Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize memory Management in JAVA

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to achieve memory management in JAVA, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Memory partition

Set JAVA_OPTS=-server-Xms1024m-Xmx1024m-XX:PermSize=512M-XX:MaxPermSize=512m-XX:MaxNewSize=512M virtual machine stack and local method stack overflow: StackOverflowError-Xoss: set local method stack size java heap overflow: OutOfMemoryError java heap space-Xmx: set maximum value of virtual machine heap parameters-Xms: set minimum value of virtual machine heap parameters run constant pool overflow: OutOfMemoryError PermGen space-XX:PermSize,-XX:MaxPermSize: limit the size of the method area

1. Program counter

The line number indicator of the bytecode executed by the current thread. This memory area is "thread private" memory. This memory area is the only one that does not specify any OutOfMemoryError conditions in the Java virtual machine specification.

2.Java virtual machine stack

This type of memory area is "thread private" memory whose life cycle is the same as that of threads. Virtual machine stack describes the memory model of Java method execution: when each method is executed, a Stack Frame ① is created at the same time to store local variables, operation stack, dynamic link, method exit and other information. Each method is called until the completion of execution, corresponding to a stack frame in the virtual machine stack from the stack to the stack process.

3. Local method stack

The role of the local method stack (NativeMethodStacks) is very similar to that of the virtual machine stack, except that the virtual machine stack performs Java methods (that is, bytecode) services for the virtual machines, while the local method stacks serve the Native methods used by the virtual machines. Like the virtual machine stack, the local method stack area throws StackOverflowError and OutOfMemoryError exceptions

4. Heap

The main area of garbage collection is the largest piece of memory managed by the virtual machine and is created when the virtual machine starts. The only purpose of this memory area is to store object instances, almost all object instances allocate memory here, but with the development of JIT compiler and the gradual maturity of escape analysis technology, the optimization technology of stack allocation and scalar substitution will lead to some subtle changes, and it will become less absolute when all objects are allocated on the heap.

5. Method area

The method area is used to store data such as class information, constants, static variables, code compiled by just-in-time compiler, which have been loaded by the virtual machine. The runtime pool is part of the method area and is used to store various literals and symbolic references generated by the compiler.

Label removal algorithm

Mark dead and surviving classes, and then clear them. Fragmentation may be serious.

Replication algorithm

The memory is divided into two parts, the surviving one moves to one side, then the other side clears it and eats the memory.

Marking and finishing

The surviving ones move to one side, and the other part cleans up.

Generation recovery algorithm

Is it helpful for you to read the above content after using the new generation to use the replication algorithm for senile substitute tag removal and tag finishing algorithm? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report