Home  >  Article  >  Java  >  Example analysis of memory problems in configuring eclipse.ini in java

Example analysis of memory problems in configuring eclipse.ini in java

Y2J
Y2JOriginal
2017-04-26 10:09:221494browse

This article is a detailed analysis and introduction to the problem of eclipse.ini memory settings. Friends in need can refer to it

-vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M
There are several questions here:
1. What are the meanings of each parameter?
2. Why can Eclipse start on some machines after I set both -Xmx and -XX:MaxPermSize to 512M, but cannot on some machines?
3. Why does Eclipse not perform the corresponding settings when writing the above parameters to the eclipse.ini file?
Let’s answer them one by one
1. What is the meaning of each parameter?
-vmargs in the parameters means setting JVM parameters, so the following are actually JVM parameters. We first understand the mechanism of JVM memory management, and then explain the meaning of each parameter.
Heap and non-heap memory
According to the official statement: "The Java virtual machine has a heap. The heap is the runtime data area, and the memory of all class instances and arrays is allocated from here. . The heap is created when the Java virtual machine starts. "The memory outside the heap in the JVM is called 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 Java code and is reserved for developers; the non-heap is the memory reserved for the JVM for its own use, so the memory required for method area and JVM internal processing or optimization (such as JIT compiled code cache), every class structure (such as the runtime constant pool, field and method data), and the code for methods and constructors are all in off-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. 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 to be 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 size of non-heap memory, the default is 1/64 of physical memory /4.
JVM memory limit (maximum value)
First of all, JVM memory is limited to the actual maximum physical memory (nonsense! Haha). Assuming that the physical memory is infinite, the maximum value of JVM memory has a lot to do with the operating system. To put it simply, although the controllable memory space of a 32-bit processor is 4GB, the specific operating system will set a limit. This limit is generally 2GB-3GB (generally speaking, it is 1.5G-2G under Windows systems and 1.5G-2G under Linux systems). 2G-3G), and there will be no restrictions on processors above 64bit.
2. Why can Eclipse start on some machines after I set both -Xmx and -XX:MaxPermSize to 512M, but cannot on some machines?
Through the above introduction to JVM memory management, we have learned that JVM memory includes two types: heap memory and non-heap memory. In addition, the maximum memory of JVM first depends on the actual physical memory and operating system. Therefore, setting VM parameters causes the program to fail to start mainly for the following reasons:
1) The value of -Xms in the parameter is greater than -Xmx, or the value of -XX:PermSize is greater than -XX :MaxPermSize;
2) The sum of the value of -Xmx and -XX:MaxPermSize exceeds the maximum limit of JVM memory, such as the maximum memory limit of the current operating system, or actual physical memory, etc. Speaking of actual physical memory, one thing to note here is that if your memory is 1024MB, it may not be 1024MB used in the actual system, because part of it is occupied by the hardware.
3. Why does Eclipse not perform the corresponding settings when writing the above parameters to the eclipse.ini file?
Then why are the same parameters valid in shortcuts or command lines but invalid in the eclipse.ini file? This is because we did not follow the setting rules of the eclipse.ini file:
The parameters are in the form of "item value". If there are spaces in the middle, they need to be written in a new line. If there are spaces in the value, they need to be enclosed in double quotes. For example, we use the -vm C:\Java\jre1.6.0\bin\javaw.exe parameter to set up the virtual machine. In the eclipse.ini file, it should be written like this:
-vm
C:\Java\ jre1.6.0\bin\javaw.exe
As mentioned above, the final parameters can be written like this in eclipse.ini:
-vmargs
-Xms128M
-Xmx512M
-XX:PermSize=64M
-XX:MaxPermSize=128M
The actual running results can be viewed through the "Configuration Details" button in the "Help"-"About Eclipse SDK" window in Eclipse.
In addition, it should be noted that the content of the eclipse.ini file that comes with the Eclipse compressed package is as follows:
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx256m
The meaning of –launcher.XXMaxPermSize (note that there are two connecting lines at the front) and -XX:MaxPermSize parameters are basically the same, I think the only one The difference is that the former is the parameter set when eclipse.exe is started, while the latter is the parameter in the JVM used by eclipse. In fact, just set one of the two, so here you can comment out –launcher.XXMaxPermSize and the next line with #.
3. Other startup parameters. If you have a dual-core CPU, maybe try this parameter:
-XX:+UseParallelGC
to make the GC execute faster. (Just a newly added parameter for GC in JDK 5)

The above is the detailed content of Example analysis of memory problems in configuring eclipse.ini in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn