views:

2806

answers:

3

I keep getting a "PermGen" error on my Tomcat 6 server.

I know what application is causing the problem, but I am not sure why it is doing so. The application is using MySQL 5 and running on JDK 6.

Are there any tools/suggestions to diagnosis or analyze the underlying issue(s) with the specific application?

Thanks

+6  A: 

The PermGen is used to store class definitions and the interned string pool.

Your code could be filling it (if it calls intern needlessly), but more likely is that the default is undersized for your application.

To set the permgen size, use "-XX:MaxPermSize=SIZE"

The following links may be helpful: tuning GC (this is the 1.5 edition), GC FAQ (1.4.2 edition), Hotspot VM options (I believe this is 1.6)

kdgregory
Thanks for the response, I will look into the all of your suggestions.
Berek Bryan
Since this got touched today (thanks, to whoever upvoted), here's another link on diagnosing OOM (written by me): http://www.kdgregory.com/index.php?page=java.outOfMemory
kdgregory
A: 

I think you might have many JSPs in your application. There is a known issue in tomcat where restarting a deployed application with many JSPs causes PermGen issues because tomcat recompiles and reloads all these classes again. Increasing the size as mentioned in the previous post should help.

+1  A: 

Try the following JVM switches:

-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled

Upping the permgen space with -XX:MaxPermSize just delays the problem.

Please see this comment: http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error/88262#88262

That indirectly pointed me to these two posts:

Problem: http://blogs.sun.com/fkieviet/entry/classloader%5Fleaks%5Fthe%5Fdreaded%5Fjava Solution: http://blogs.sun.com/fkieviet/entry/how%5Fto%5Ffix%5Fthe%5Fdreaded

opyate
It delays the problem if you maintain accidental classloader links. And, to be sure, there are a lot of cases where this can happen, and it can be next to impossible to find them unless you know your libraries inside and out (java.beans.Introspector, for example, maintains a cache of class data).
kdgregory
However, often the problem is simply that the web-app is too large to use the default. Particularly in a development environment, where you have a 64Mb permgen, and may be redeploying constantly. It takes time for all existing references to go out of scope (for example, a pooled thread hanging onto the last servlet that it ran).
kdgregory