Eclipse modifies jvm parameter optimization methods (2 types) and jvm Optimization

Source: Internet
Author: User

Eclipse modifies jvm parameter optimization methods (2 types) and jvm Optimization

This article describes how to modify jvm parameter optimization methods in eclipse (two methods). The details are as follows:

When you do not configure eclipse, you will always feel slow to start and use eclipse. In fact, you only need to configure eclipse-related parameters, there will be great improvements.

There are two methods:
1. Open the eclipse configuration file eclipse. ini and change-Xmx (the value represents the maximum memory size that jvm can use)
2. when running the java program, select run> run configuration> arguments and enter-Xms100M-Xmx800M (-Xms indicates the memory size allocated during jvm startup, -Xmx indicates the maximum amount of memory that can be allocated ).

When I tested converting a document to an image in eclipse today, 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 available to the virtual machine. So the problem is how to set the maximum jvm memory 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 modification, restart eclipse and find that it does not work at all. After reading some materials, I checked whether the minimum memory and maximum memory set here were used by JVM. This memory value contains the memory used by eclipse.

Ii. Modify jdk memory usage (this method is feasible)

Find window-> preferences-> Java-> Installed JRE in eclispe, click the Edit button on the right, and enter the following values in the "Default VM Arguments" option on the editing page.

-Xms64m -Xmx128m

3. Modify Run Configurations (this method is feasible)

Right-click the code, choose "Run As"> "Run events", and enter the following values in "VM Arguments:" In the arguments parameter.

-Xms64m -Xmx128m

The following jvm parameters are used to set the heap memory:

-Xmx512m Maximum total heap memory, generally set to 1/4 of the physical memory
-Xms512m The initial total heap memory is usually set as large as the maximum heap memory, so you do not need to adjust the heap size based on the current heap usage.
-Xmn192m Young with heap memory, sun officially recommends 3/8 of the total heap memory
Heap memory Composition Total heap memory = Young with heap memory + old with heap memory + persistent with heap memory
Young with heap memory Put the object here when it is just created
Old with heap memory Objects are placed here before they are actually recycled.
Persistent memory with heap Put the class file and metadata here.
-XX: PermSize = 128 m Initial persistent heap size
-XX: MaxPermSize = 128 m The maximum persistent heap size. The default value of eclipse is 256 MB. If you want to compile jdk, you must set it very large because it has too many classes.

4. query the current JVM Memory code

The following code queries the current JVM memory size. You can test whether the JVM memory will change after the preceding settings. After the JVM memory configuration item is added, you do not 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 current jvm memory information ** @ 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 for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.