How to analyze PermGen contents?

隐身守侯 提交于 2019-12-27 17:00:33

问题


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?


回答1:


The PermGen normally consists of the string literal pool and loaded classes. To answer part of your problem, i.e. the string literal pool I wrote a utility to print a running JVM's string literal pool. It is available here:

https://github.com/puneetlakhina/javautils/blob/master/src/com/blogspot/sahyog/PrintStringTable.java

It is based on PermStat, which is the class used to print permgen stats by the jmap tool.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/2842982/how-to-analyze-permgen-contents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!