Tuesday, September 8, 2009

Understanding PermGen and Java Memory Management

These are two command-line parameters that you must use to define the size of the permgen area: -XX:PermSize -XX:MaxPermSize. See the example bellow:

java -Xms64m -Xmx128m -XX:PermSize=64m -XX:MaxPermSize=256m MainClass

In this example, we are instructing the Java Virtual Machine to create an initial object heap size of 64 megabytes (-Xms) and maximum size of 128 megabytes (-Xmx). And we are defining a PermGen heap area of initially 64 megabytes (-XX:PermSize) and maximum size of 256 megabytes (-XX:MaxPermSize). Remember that the initial size of the heap area in this example, is the sum of the initial object heap area and the initial permgen heap area, that is, 64+64=128 megabytes. And the same for the maximum size of the heap area: 128+256=384 megabytes.

As a practical example, let's see how to increase permgen area size in Jboss. Locate the jboss.bat (in Windows) or jboss.conf (in Unix). Look for a linke containing a redefinition of the shell script variable JAVA_OPTS. You see bellow how the default configuration in Windows:

Uncomment thes line to set PermGen area size:

Now that we have learned how to monitor and fix permgen errors, I advice you not to blindly increase the permgen size everytime there is a permgen error. Monitor how the size of the permgen area is growing. The Permgen area shouldn't be constantly growing over a long period. The Java language features dynamic class loading, so classes will be loaded on demand and the permgen heap size will grow as well. But, if in the long term, your permgen area is still steadly growing, you are probably using some kind of bytecode generation framework which is misbehaving or you are using it incorrectly. Analyse that and rethink what you are doing.

Java Memory Management

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

A White Paper on Java Memory Management


No comments:

Post a Comment

Happy Reading!

Ganex Improves .. Headline Animator