This is the fourth day of my participation in Gwen Challenge
Common JVM parameter configuration machine meaning
-vmargs -xMS128m -XMx512m -xx :PermSize=64M -xx :MaxPermSize=128M -vmargs -xms128m Specifies the maximum heap memory that the JVM can allocate. -xmx512m Specifies the maximum heap memory that the JVM can allocate. On-demand allocation -xx :PermSize=64M Non-heap memory initially allocated by the JVM -xx :MaxPermSize=128M Maximum non-heap memory that the JVM can allocate on demandCopy the code
Let’s first look at the mechanics of JVM memory management and then explain what each parameter represents.
Heap and non-heap memory
In official terms: “The Java VIRTUAL machine has a heap, which is a run-time data area where memory for all class instances and arrays is allocated. The heap is created when the Java Virtual machine starts.” The memory outside of the heap in the JVM is called non-heap memory. You can see that the JVM manages two main types of memory: heap and non-heap. Simply put, the heap is the memory that is accessible to Java code and is reserved for developers. Non-heap is what the JVM keeps for itself, so the method area, the memory needed for processing or optimization within the JVM (such as jIT-compiled code caches), the code for each class structure (such as runtime pool, field, and method data), and the method and constructor code are all in non-heap memory.
Heap allocation
The JVM’s initial allocation of heap memory is specified by -xms, which defaults to 1/64 of physical memory. The maximum heap memory allocated by the JVM is specified by -xmx, which defaults to 1/4 of the physical memory. When the default free heap is less than 40%, the JVM increases the heap to the maximum limit of -xmx; When free heap memory is greater than 70%, the JVM reduces the heap to the minimum limit of -xMS. So servers typically set -xms, -xmx equal to avoid resizing the heap after each GC. Note: If -xmx is not specified or specified too small, the application may cause a java.lang.OutOfMemory error. This error is from the JVM and is not Throwable. Catch catch.
Non-heap memory allocation
The JVM uses -xx :PermSize to set the initial value of non-heap memory, which defaults to 1/64 of physical memory. The maximum non-heap memory size is set by XX:MaxPermSize. The default is 1/4 of the physical memory. MaxPermSize the default value of MaxPermSize is related to the -server-client option. The default value of MaxPermSize is 64 MB under -server and 32 MB under -client. I didn’t experiment with that.) The full name of the PermGen space in the preceding error message is Permanent Generation space, which refers to the Permanent memory storage area. It’s not clear whether PermGen space is non-heap memory or just non-heap memory, but at least it is. XX: MaxPermSize set starts to lead to Java. Lang. OutOfMemoryError: PermGen space is profit out of memory. Tell us why memory gains occur:
- This portion of memory is used to store Class and Meta information. When classes are loaded, they are placed in the PermGen space, which is different from the Heap where Instance is stored.
- Garbage Collection (GC) does not clean up PermGen space during the main application runtime, so if your APP loads a lot of classes, you are likely to get a PermGen space error.
This error is common when the Web server pre-compile JSPS.
JVM memory limits (maximum)
First, the JVM memory is limited to the actual maximum physical memory, which is highly dependent on the operating system, assuming that physical memory is infinite. To put it simply, although the 32-bit processor can control the memory space of 4GB, the specific operating system will give a limit, the limit is generally 2GB-3GB (generally speaking, the Windows system is 1.5G-2G, the Linux system is 2G-3G), and the 64-bit processor will not have the limit.
Why does Eclipse start on some machines when I set -xmx and -xx :MaxPermSize to 512MB, but not on some machines? From the previous introduction to JVM memory management we learned that THERE are two types of JVM memory: heap and non-heap memory, and that the maximum JVM memory depends first on the actual physical memory and operating system. Therefore, there are several reasons why the program cannot start due to setting VM parameters:
- The value of -xms is greater than -xmx, or the value of -xx :PermSize is greater than -xx :MaxPermSize.
- The sum of the -xmx value and -xx :MaxPermSize exceeds the maximum JVM memory limit, such as the current operating system maximum memory limit, or actual physical memory, etc. One thing to note about physical memory is that if you have 1024MB of memory, you’re not going to be using 1024MB on the actual system because some of it is being used by the hardware.
If you have a dual-core CPU, you might want to try this parameter:
-XX:+UseParallelGC
Make GC faster to execute. (just a new parameter for GC in JDK 5)