JVM default memory size

Heap and non-heap memory

  According to the official statement: "The Java virtual machine has a heap. The heap is the runtime data area. The memory of all class instances and arrays is allocated from here. The heap is created when the Java virtual machine starts." "Heap in the JVM External memory is called non-heap memory (Non-heap memory)". It can be seen that JVM mainly manages two types of memory: heap and non-heap. Simply put, the heap is the memory accessible by the Java code, which is reserved for developers to use; the non-heap is reserved for their own use by the JVM, so the method area, the internal processing of the JVM or the memory required for optimization (such as JIT compiled code Cache), each class structure (such as runtime constant pool, field and method data), and method and construction method code are all in non-heap memory.

Heap memory allocation

  The initial memory allocated by the JVM is specified by -Xms, and the default is 1/64 of the physical memory; the maximum memory allocated by the JVM is specified by -Xmx, and the default is 1/4 of the physical memory. When the default 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 heap size after each GC.

Non-heap memory allocation

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

JVM maximum memory

  First of all, the JVM memory is limited to the actual maximum physical memory (nonsense! Haha), assuming that the physical memory is infinite, the maximum JVM memory has a great relationship with the operating system. Simply put, although the controllable memory space of a 32-bit processor has 4GB, the specific operating system will give a limit. This limit is generally 2GB-3GB (generally 1.5G-2G under Windows system, and 1.5G-2G under Linux system. 2G-3G), and there will be no restrictions on processors above 64bit.

View the maximum JVM size of the machine

  java -XshowSettings:vm

View the maximum metaspace of this machine

  java -XX:+PrintFlagsInitial | findstr MetaspaceSize

 

Original: https://www.cnblogs.com/guanghe/p/13558412.html

 

Guess you like

Origin blog.csdn.net/cherry_vicent/article/details/108810683