JAVA-XMS-XMX set the memory size of the Java application to run, Xms xmx permsize maxpermsize Difference

Source: Internet
Author: User
Tags garbage collection xms

-xms and-xmx are an option for Java commands to set the available memory size for your application startup and the amount of memory available at run time.

XMX is an option in Java to set the maximum amount of memory your application can use (see, just your app, not the entire JVM), and if your program takes a lot of memory, you need to modify the default settings, such as configuring Tomcat, If the flow of AH program AH is very large need to increase this value, but there is one thing to remember, do not larger than your machine memory, so your machine will not be able to stand, then the dead.

XMS is another parameter that sets the memory, which is used to set the size of the memory stack when the program is initialized, and the startup performance of your program will be improved if you add this value. But there are also the previous restrictions, as well as the xmx restrictions.
The implementations of different virtual machines vary, but their operating modes are the same, but the performance is different.
The virtual machine is just a software implementation, it is a machine in memory, and our machine is the JRE, is to generate this JVM. Typically, a JVM is generated each time you run a application, but you can also have multiple programs in the same JVM.

Eclipse crashes, Error tip:
MyEclipse has detected that less than 5% of the 64MB of Perm
Gen (non-heap memory) space remains. It is strongly recommended
That's you exit and restart MyEclipse with new virtual machine memory
Paramters to increase this memory. Failure to Can
Data loss. The recommended Eclipse memory parameters are:
eclipse.exe-vmargs-xms128m-xmx512m-xx:permsize=64m-xx:maxpermsize=128m

1. The meaning of the parameter
-vmargs-xms128m-xmx512m-xx:permsize=64m-xx:maxpermsize=128m
The-vmargs description is followed by the parameters of the VM, so the following are actually parameters of the JVM
-xms128m JVM Initial allocation of heap memory
-xmx512m JVM Maximum allowable allocation of heap memory, on demand
-xx:permsize=64m JVM Initial allocation of non-heap memory
-xx:maxpermsize=128m JVM Maximum allowable allocation of non heap memory, on demand

Let's first look at the mechanism of JVM memory management and then explain what each parameter represents.


1) heap (HEAP) and non-heap (non-heap) memory


According to the official statement: "Java virtual machines have a heap, the heap is the Run-time data region, all class instances and arrays of memory are allocated from here." The heap was created when the Java virtual machine was started. "" Memory outside the heap in the JVM is called Non heap memory (non-heap memory).
You can see that the JVM mainly manages two types of memory: the heap and the non heap. Simply put, the heap is Java code-accessible memory that is reserved for developers, and not heaps are for the JVM to use,
Therefore, the code for the method area, the JVM internal processing or optimization (such as JIT-compiled code caching), each class structure (such as running a constant pool, field and method data), and the methods and construction methods are in non heap memory.


Heap memory allocation


The JVM's initial allocation of heap memory is specified by-XMS, and the default is physical memory 1/64;JVM the maximum allocated heap memory is specified by-XMX, which defaults to 1/4 of physical memory. When the default free heap memory is less than 40%, the JVM increases the maximum limit of the heap until-xmx;
When the free heap memory is greater than 70%, the JVM reduces the minimum limit of the heap until-xms. Therefore, the server generally sets-xms and-xmx equal to avoid resizing the heap after each GC.
Note: If-XMX is not specified or is specified to be small, the application may cause a java.lang.OutOfMemory error, which is from the JVM, not throwable, and cannot be captured with Try...catch.


Non-heap memory allocation


The JVM uses-xx:permsize to set a non heap memory initial value, which defaults to 1/64 of physical memory, and the maximum amount of non heap memory is set by Xx:maxpermsize, which defaults to 1/4 of physical memory. (and one says: MaxPermSize defaults are related to the-server-client option,
The default MaxPermSize under the-server option is 32m for the default maxpermsize under 64m,-client option. I didn't experiment with that. )
The full name of the PermGen space in the error message above is permanent Generation spaces, which are the permanent areas of memory storage. Haven't figured out whether the PermGen space belongs to a heap of memory, or is not a heap of memory, but at least it belongs.
Xx:maxpermsize set too small will cause java.lang.OutOfMemoryError:PermGen space is memory benefits.
Talk about why memory benefits out:
(1) This portion of memory is used to store class and meta information, class is placed in the PermGen space area when it is load, and it is different from the heap area where the instance is stored.
(2) GC (garbage Collection) does not clean up the PermGen space during the runtime of the main program, so if your app will load a lot of classes, it is likely that PermGen space error will occur.
This error is common when the Web server is pre compile the JSP.


2 JVM Memory limit (maximum)


First, JVM memory is limited to the actual maximum physical memory, and the maximum value of JVM memory is significantly related to the operating system, assuming that the physical memory is infinitely large. To put it simply, the 32-bit processor, while the controllable memory space has 4GB, will give a limit to the specific operating system
This limitation is generally 2GB-3GB (generally the Windows system under the 1.5g-2g,linux system is 2g-3g), and more than 64bit of processors will not be limited.

2. Why do some machines I have-xmx and-xx:maxpermsize set to 512M after eclipse can start, and some machines will not start.
  Through the above introduction to JVM memory management we have learned that JVM memory consists of two kinds: heap memory and non heap memory, and the JVM's maximum memory depends first on the actual physical memory and operating system. So setting the VM parameters causes the program not to start for several reasons: the value of the-XMS in the
1) parameter is greater than-XMX, or the value of-xx:permsize is greater than the value of-xx:maxpermsize
2-xmx and-xx: The sum of the maxpermsize exceeds the maximum JVM memory limit, such as the current operating system maximum memory limit, or actual physical memory, and so on. When it comes to actual physical memory, the point is that
  if your memory is 1024MB, it is not possible to use 1024MB in the actual system because a portion of it is consumed by the hardware.

3. Why write the above parameter to the Eclipse.ini file eclipse does not perform the corresponding setting.
  Why is the same parameter valid on the shortcut or command line and is not valid in the Eclipse.ini file? This is because we are not complying with the set rules for the Eclipse.ini file:
The form of a parameter such as "Item Value", where there is a space in the middle of the need for line-wrapping, if the value has spaces in the need to be included in double quotes. For example, we use the-VM c:/java/jre1.6.0/bin/javaw.exe parameter to set up the virtual machine, which is written in the
Eclipse.ini file:
-vm 
c:/java/jre1.6.0/bin/ JAVAW.EXE&NBSP
-vmargs 
-xms128m 
-xmx512m 
-xx:permsize=64m 
-xx: MAXPERMSIZE=128M&NBSP
The results of the actual operation can be viewed through the Configuration Details button in the "Help"-"About Eclipse SDK" window in Eclipse.
In addition, the contents of the Eclipse.ini file included with the Eclipse package are as follows:
-showsplash 
org.eclipse.platform 
-- Launcher. XXMAXPERMSIZE&NBSP
256m 
-vmargs 
-xms40m 
-xmx256m 
–launcher. Xxmaxpermsize (Note that the first two connectors) and-xx:maxpermsize parameters are basically the same meaning, I think the only difference is that the former is the Eclipse.exe when the start of the parameters set,
The latter is the parameter in the JVM used by Eclipse. In fact, the two set a can, so here can put –launcher. Xxmaxpermsize and the next line use # comments.

4. Other startup parameters. If you have a dual-core CPU, you may be able to try this parameter:
-xx:+useparallelgc
Allow the GC to execute faster. (only the newly added parameters to the GC in JDK 5)

Add:
If your web app uses a large number of third-party jars that exceed the default size of the server JVM, there is a memory benefit problem.
WORKAROUND: Set MaxPermSize size
You can add server-initiated JVM parameter settings by selecting the appropriate server in the Myelipse, such as TOMCAT5, and expanding the JDK subkey page inside:
-xms128m
-xmx256m
-xx:permsize=128m
-xx:maxnewsize=256m
-xx:maxpermsize=256m
or manually set the MaxPermSize size, such as Tomcat,
Modify Tomcat_home/bin/catalina.bat and add the following line to the echo "Using catalina_base: $CATALINA _base":
Java_opts= "-server-xx:permsize=64m-xx:maxpermsize=128m

Recommendation: Move the same third-party jar files to the Tomcat/shared/lib directory, which will reduce the memory consumption of the jar document

Related Article

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.