JVM Startup parameters and Java.lang.OutOfMemoryError

Source: Internet
Author: User
Tags xms
Preface
Java.lang.OutOfMemoryError, this is mainly due to the JVM parameters are not well matched. OutOfMemoryError is divided into two types: Java.lang.OutOfMemoryError:Java heap space and java.lang.OutOfMemoryError:PermGen space. The former is a memory overflow of heap memory, which can be resolved by configuring-XMS and-xmx parameters. The latter is a memory overflow of non heap memory that can be set by configuring-xx:permsize and-xx:maxpermsize.
the meaning of the parameter
-XMS:JVM Initial allocation of heap memory -XMX:JVM maximum allowable allocation of heap memory, on demand -XX:PERMSIZE:JVM Initial allocation of non-heap memory -XX:MAXPERMSIZE:JVM Maximum allowable allocation of non heap memory, on demandSet in the Tomcat container in IntelliJ idea, as shown in the following illustration:


heap memory and non-heap memory Heap Memory: the memory that the JVM leaves to developers. General storage objects and arrays. 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 free heap memory is less than 40%, the JVM increases the heap memory to the maximum limit of-xmx, and when the free heap memory is greater than 70%, the JVM reduces heap memory until the minimum limit of-XMS. Therefore, the server generally sets-XMS,-xmx equality to avoid resizing heap memory after each GC. 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: the memory that the JVM left for itself. Method areas, JVM internal processes, or optimizations required for memory (such as JIT-compiled code caching), each class structure (such as running a constant pool, field and method data), and the Code for methods and construction methods are in non heap memory. The JVM's initial allocation of non heap memory is specified by-xx:permsize, which defaults to the 1/64;JVM of the maximum allocated heap memory of physical memory by-xx:maxpermsize, which defaults to 1/4 of physical memory. (also one said: MaxPermSize defaults and-server-client options related to the-server option under the default maxpermsize for the 64m,-client option under the default MaxPermSize 32m) -xx:maxpermsize set too small can cause java.lang.OutOfMemoryError:PermGen space, for the following reasons: PermGen space is used to store class and meta information, GC does not deal with permgen space, so if the load a lot of class, it will appear above error. This error is more common when the Web server is pre compile the JSP. When you load the model with spark, you encounter a Java.lang.OutOfMemoryError:PermGen Space This error, the main cause of this error is the load of the model has a large number of metadata information, which is all in the heap of memory, not heap memory after setting, Do not report this error again.

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.