JVM: Heap and Non-heap memory

Heap (Heap) and non-heap (Non-heap) memory:

The heap is the runtime data area from which memory for all class instances and arrays is allocated. The heap is created when the Java virtual machine starts. "The memory outside the heap in the JVM is called non-heap memory (Non-heap memory)". It can be seen that the JVM mainly manages two types of memory: heap and non-heap.
Simply put, the heap is the memory accessible to the Java code, which is reserved for developers; the
non-heap is reserved for the JVM for its own use, all method areas, memory required for internal processing or optimization of the JVM (such as JIT-compiled code cache), per-class structures (such as runtime constant pools, field and method data), and code for methods and constructors are in non-heap memory.

Heap memory allocation:
-Xms 256m
-Xmx 256m
The initial memory allocated by the JVM is specified by -Xms, which is 1/64 of the physical memory by default;
the maximum memory allocated by the JVM is specified by -Xmx, which is 1/4 of the physical memory by default. By default, when the free heap memory is less than 40%, the JVM will increase the heap until the maximum limit of -Xmx; when the free heap memory is greater than 70%, the JVM will reduce the heap until the minimum limit of -Xms. Therefore, the server generally sets -Xms and -Xmx equal to avoid adjusting the size of the heap after each GC.

Non-heap memory allocation:
-XX:PermSize 256m
-XX:MaxPermSize 256m
JVM uses -XX:PermSize to set the initial value of non-heap memory, the default is 1/64 of physical memory; the
maximum non-heap memory size is set by -XX:MaxPermSize, The default is 1/4 of physical memory.

overflow:

In general, the following exceptions can be located directly:
Heap overflow:
java.lang.OutOfMemoryError: Java heap spcace
Stack overflow:
java.lang.StackOverflowError
Method area overflow:
java.lang.OutOfMemoryError: PermGen space

Guess you like

Origin blog.csdn.net/blueheartstone/article/details/128792685