Archive

Posts Tagged ‘java_opts’

tomcat – java.lang.OutOfMemoryError: PermGen space

December 17, 2009 Leave a comment

This error occurs when the JVM runs out of space in the permanent generation heap, a heap that holds objects such as classes and methods.

Since the defaults for the JVM are quite low, the first step should be to increase the default using -XX:MaxPermSize.

A lot of Java developers have seen OutOfMemory error one time or other.

However these errors come in different forms and shapes. The more common is: “Exception in thread “main”

java.lang.OutOfMemoryError: Java heap space” and indicates that the Heap utilization has exceeded the value set by -Xmx.

One more interesting flavor of the same error message is: “java.lang.OutOfMemoryError: PermGen space”.

Most of the memory profiler tools are unable to detect this problem.

For optimized, more efficient garbage-collecting Java Heap is managed in generations – memory segments holding objects of different ages.

Garbage collection algorithms in each generation are different. Each generation contains variables of different length of life and different

GC policies are applied to them.

There is one generation – Permanent Generation. The permanent generation is special because it holds meta-data describing user classes

classes that are not part of the Java language). Examples of such meta-data are objects describing classes and methods and they are stored

in the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause

java.lang.OutOfMemoryError: PermGen no matter how high your -Xmx and how much memory you have on the machine.

To set a new initial size on Sun JVM use the -XX:PermSize=64m option when starting the virtual machine.

To set the maximum permanent generation size use -XX:MaxPermSize=128m option.

A Sample JAVA_OPTS in Tomcat Catalina.sh file:

JAVA_OPTS=”-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m

-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m

-XX:MaxPermSize=256m -XX:+DisableExplicitGC”

Note: Change Xms and PermSize base on your server capability.