如何分析PermGen内容?
我想获取 PermGen 的转储,看看它为何被填满。有没有办法分析这个?我已经了解常见的嫌疑人,如 log4j、tomcat webapp 重新加载等,但我的应用程序中也有一些自定义代理生成代码,只想了解一下幕后情况。
这有可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PermGen 通常由字符串文字池和加载的类组成。为了回答您的部分问题,即字符串文字池,我编写了一个实用程序来打印正在运行的 JVM 的字符串文字池。它可以在这里找到:
https://github.com/puneetlakhina/javautils /blob/master/src/com/blogspot/sahyog/PrintStringTable.java
它基于 PermStat,这是jmap工具用来打印permgen统计信息的类。
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.
您可以使用这些标志:
它们在从永久代加载/卸载时打印类的标识。如果添加
-XX:+PrintGCDetails
,您还可以跟踪永久代的大小。请注意,我不确定除 Sun 之外的 JVM 是否支持这些标志。
PermGen 内存不足错误的另一个嫌疑人是 字符串实习。检查代码中实习字符串的位置。
You can use the flags:
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.
如果您希望获取所有已加载类的列表,可以使用
jconsole
。单击类选项卡,然后单击“详细输出”。这将打印加载到 stdout 的每个类。我发现这对于跟踪 JAXB 代理类问题非常有用。您可能必须使用
-Dcom.sun.management.jmxremote
命令行选项启动应用程序,以便jconsole
附加到它。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 tostdout
. 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 forjconsole
to attach to it.jmap -permgen
符合要求吗?请参阅 Java 故障排除指南
http://java.sun. com/javase/6/webnotes/trouble/TSG-VM/html/memleaks.html#gbyuu
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