tags:

views:

314

answers:

4

I want to get a dump of the PermGen to see why it is filling. Is there a way to analyze this? I already know about the common suspects like log4j, tomcat webapp reloading etc, but I have some custom proxy generation code in my application, too, and just want to look under the hood.

Is this possible somehow?

A: 

You can use the flags:

-XX:+TraceClassLoading -XX:+TraceClassUnloading

They print the identities of classes as they get loaded/unloaded from the permanent generation. If you add -XX:+PrintGCDetails you can also track the size of the permgen.

Note that i'm not sure the flags are supported in JVMs other than Sun's.

Another suspect of PermGen out-of-memory-errors is string interning. Check the places where you intern strings in your code.

Eyal Schneider
This does not address the actual question ... how to **dump** the permgen heap.
Stephen C
@Stephen: you are right, but I hoped it would be enough in this case :)
Eyal Schneider
accepted, because this helped me most, even if it did not completly solve my problem. I found out that 160MB pern gen really were not much enought, after writing a script that parsed my log output and counted the size of all loaded classes. (While reading my comment I see at least 2 WTFs)
Daniel
A: 

If you're looking to get a list of all classes loaded you can use jconsole. Click on the classes tab then click "Verbose Output". That will print each class that is loaded to stdout. I found this very useful tracking down a JAXB proxy class issue.

You may have to launch your application with the -Dcom.sun.management.jmxremote command line option in order for jconsole to attach to it.

mtpettyp
Sorry, my permgen is already nearly full. And I don't know with what.
Daniel
This should print out the classes that are filling your PermGen space as they are loaded. Can you restart your application and turn on this logging?
mtpettyp
Not useful and in fact the same as providing -XX:+TraceClassLoading -XX:+TraceClassUnloading from the first comment.
Daniel
A: 

Will jmap -permgen fit the bill?

See the troubleshooting guide for Java http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/memleaks.html#gbyuu

Dilum Ranatunga
No. I already knew about this, but I really need a way to have a look at whats already in there.
Daniel
A: 

I am specifying the below command in catalina.bat >

set JAVA_OPTS=-XX:+TraceClassLoading -XX:+TraceClassUnloading -XX:+PrintGCDetails

The logs are printed in console but i am not able to redirect the logs in file. Using startup.bat > logs.txt

Can anyone tell me how to save/trace the console logs??

Amit
At least I can tell you to create a new question, instead of posting a question where the aswer belongs ;). Use the "Ask Question" button at the top.
Daniel