PermGen space, permgenspace

Source: Internet
Author: User

PermGen space, permgenspace

[To] http://blog.csdn.net/xiaojianpitt/article/details/3276790

PermGen space

PermGen space stands for Permanent Generation space, which refers to the Permanent storage area of the memory OutOfMemoryError: PermGen space is actually out of memory, and the solution must be to increase the memory. This part is used to store Class and Meta information. When the Class is loaded, it is placed in the PermGen space area, which is different from the Heap area where the Instance is stored, GC (Garbage Collection) does not clean up the PermGen space during the main program running period. Therefore, if your APP loads many classes, the PermGen space error may occur. This error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files and the size exceeds the default jvm size (4 MB), this error message is generated.
Solution: manually set the MaxPermSize
Correction Method:-Xms256m-Xmx256m-XX: MaxNewSize = 256 m-XX: MaxPermSize = 256 m

 

Modify TOMCAT_HOME/bin/catalina. sh
JAVA_OPTS = "-server-XX: PermSize = 64M-XX: MaxPermSize = 128 m
Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

SunThis document explains the following:

Java. lang. OutOfMemoryError: PermGen space

The detail messagePermGen spaceIndicates thatthePermanent generationIs full. the permanent generation is the area of the heap where class and method objectsare stored. if an application loads a very large number of classes, then thesize of the permanent generation might need to be increased using-XX: MaxPermSizeOption.

InternedJava. lang. StringObjects are also storedin the permanent generation.Java. lang. StringClass maintains apool of strings. WhenInternMethod is invoked, the method checksthe pool to see if an equal string is already in the pool. If there is, thentheInternMethod returns it; otherwise it adds the string to thepool. In more precise terms,Java. lang. String. internMethod isused to obtain the canonical representation of the string; the result is areference to the same class instance that wocould be returned if that stringappeared as a literal. if an application interns a huge number of strings, thepermanent generation might need to be increased from its default setting.

When this kind of error occurs, the textString. internOrClassLoader. defineClassMight appear near the top of the stacktrace that is printed.

TheJmap-permgenCommand prints statistics forthe objects in the permanent generation, including information aboutinternalized String instances. See 2.6.4Getting Information on the Permanent Generation.

The following are some of your problems:

When sun jdk + Tomcat 5.5.20 encounters a problem when running the service, the server crashes after several days and reports java. lang. OutOfMemoryError: PermGen space exception.

Many people found that the problem was caused by spring, hibernate, and tomcat. They dynamically generated classes, resulting in permanentheap overflow in JVM. There are different solutions. Some people say that upgrading tomcat to the latest version does not even require tomcat. Some people suspect that the issue of spring is very intense in the spring Forum, because the use of CBLIB in spring in AOP will dynamically generate many classes.

But the question is, why is the open source of these trump cards having the same problem? Is it a more basic reason? Tomcat answered this in A vague manner in Q &. (Why does the memory usage increase when I redeploya web application?Because the Classloader (and the Class objects it loaded) cannot be recycled. they are stored in thepermanent heap generation by the JVM, and when you redepoy a new class loaderis created, which loads another copy of all these classes. this can causeOufOfMemoryErrorsEventually .)

So someone checked the more basic JVM and found the key to the problem. In the past, SUN's JVM divided the memory into different zones, one of which is the permanent zone used to store a lot of classes and class descriptions. Originally SUN thought that this region was fixed during JVM startup, but he did not expect that the current dynamics would be so widely used. In addition, this region has a special garbage collection mechanism. The problem now is that gc cannot be recycled after classes are dynamically loaded to this region!

The most thorough solution to this bug is to use SUN's JDK instead of BEA's JRokit.

 

An outofmemory error occurs during redeploy in tomcat.

There are several possible reasons:

1. Use proxool because proxool contains an earlier version of cglib.

2, log4j, it is best not to use, only use common-logging

3. Update cglib of the old version to the latest version.

4. Update to the latest hibernate3.2.
3. Take the tomcat environment as an example. Other WEB servers, such as jboss and weblogic, share the same principle.

 

Ii. java. lang. OutOfMemoryError: Java heap space
Heap size settings
The JVM Heap setting refers to the setting of the memory space that JVM can allocate during the java program running. The JVM automatically sets the Heap size value at startup,
The initial space (-Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. You can use options such as-Xmn-Xms-Xmx provided by JVM.
. The Heap size is the sum of YoungGeneration and TenuredGeneraion.
Tip: if 98% is used for GC and the available Heap size is less than 2% in JVM, this exception is thrown.
Tip: the Heap Size should not exceed 80% of the available physical memory. Generally, you must set the-Xms and-Xmx options to the same, and-Xmn to the-Xmx value of 1/4.
Solution: manually set Heapsize
Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m"

Iii. Example:

JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: PermSize = 64 M-XX: MaxNewSize = 256m-XX: MaxPermSize = 128m-Djava.awt.headless = true"


For Tomcat, if there are multiple applications under Tomcat, try to put the jar files shared under lib under Tomcat lib, And the release speed and running speed are also improved.

 

Digress: users often complain about tomcat's poor performance ..., unstable. In fact, based on my several years of experience, from the "interconnected Star" to the current real estate portal network, we all use tomcat as a WEB server, with millions of visits each day, and tomcat is still running well. If you have any questions, we suggest you start with your own program and take a look at the java DOC documentation.

Reference: http://blogs.sun.com/jonthecollector/entry/presenting_the_permanent_generation

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.