This article introduces the method (2 types) of eclipse to modify jvm parameter tuning, and shares it with you, as follows:
Generally, when you do not set the relevant settings for eclipse, you will always feel that the startup is slow and it is good to use. In fact, as long as you configure the relevant parameters of eclipse, it will be greatly improved.
There are two ways:
1. Open the eclipse configuration file eclipse.ini and change -Xmx (its value represents the maximum memory that jvm can use)
2. When running the java program, select run->run configuration->arguments and enter -Xms100M -Xmx800M (-Xms represents the memory size allocated when jvm starts, and -Xmx represents the maximum amount of memory that can be allocated).
Today, when I was testing the document to a picture in eclipse, the following error was reported:
java.lang.OutOfMemoryError: Java heap space
From the exception information above, we can see that the memory required by the JVM has exceeded the maximum memory that we allocated to the virtual machine. So the problem turns into how to set the maximum memory of jvm in eclipse.
1. Try to modify the Eclipse.ini file (this method does not work)
Find the eclipse.ini file in the eclipse directory and modify the following content:
-Xms40m-Xmx512m
After modifying it, restarting eclipse, it found that it did not work at all. After checking some information later, it turned out that the minimum and maximum memory set here were for use by the JVM. This memory value contains the memory used by eclipse itself.
2. Modify jdk to use memory (this method is feasible)
Find window->preferences->Java->Installed JRE in eclispe, click the Edit button on the right, and fill in the following values in the "Default VM Arguments" option in the editing interface.
-Xms64m -Xmx128m
3. Modify Run Configurations (this method is feasible)
Right-click on the code, click "Run As" -> "Run Configurations" in the order, and fill in the following values in "VM arguments:" in the Arguments parameter.
-Xms64m -Xmx128m
The heap memory is mainly set through the following jvm parameters:
| -Xmx512m | Maximum total heap memory, generally set to 1/4 of physical memory |
| -Xms512m | The initial total heap memory is usually set as large as the maximum heap memory, so there is no need to adjust the heap size according to the current heap usage. |
| -Xmn192m | Young with heap memory, sun officially recommends 3/8 of the entire heap |
| Composition of heap memory | Total heap memory = young with heap memory + old with heap memory + persistent with heap memory |
| Young with heap of memory | The object was put here when it was created |
| Older with pile of memory | The object will be placed here before it is actually recycled |
| Persistent with heap memory | class files, metadata, etc. are placed here |
| -XX:PermSize=128m | The initial size of the persistent belt heap |
| -XX:MaxPermSize=128m | The maximum size of the persistent band heap, the default eclipse is 256m. If you want to compile jdk, you must set this to be very large because there are too many classes. |
4. Query the current JVM memory code
The following is the code to query the current JVM memory size. You can test whether the JVM memory will change after the above settings. After increasing the configuration items for JVM memory, there is no need to restart eclipse. The specific code is as follows:
public class TestMemory { /** * @param args */ public static void main(String[] args) { System. out .println( " Memory Information:" + toMemoryInfo()); } /** * Get the memory information of the current jvm* * @return */ public static String toMemoryInfo() { Runtime currRuntime = Runtime.getRuntime (); int nFreeMemory = ( int ) (currRuntime.freeMemory() / 1024 / 1024); int nTotalMemory = ( int ) (currRuntime.totalMemory() / 1024 / 1024); return nFreeMemory + "M/" + nTotalMemory +"M(free/total)" ; }}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.