Java 如何分析永久代内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2842982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:31:00  来源:igfitidea点击:

How to analyze PermGen contents?

javapermgen

提问by Daniel

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.

我想得到 PermGen 的转储,看看它为什么会被填满。有没有办法分析这个?我已经知道了像 log4j、tomcat webapp 重新加载等常见的问题,但是我的应用程序中也有一些自定义代理生成代码,我只是想深入了解一下。

Is this possible somehow?

这有可能吗?

采纳答案by Puneet

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:

PermGen 通常由字符串文字池和加载的类组成。为了回答您的部分问题,即字符串文字池,我编写了一个实用程序来打印正在运行的 JVM 的字符串文字池。它可以在这里找到:

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

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.

它基于PermStat,这是 jmap 工具用于打印 permgen 统计信息的类。

回答by Eyal Schneider

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:+PrintGCDetailsyou can also track the size of the permgen.

当它们从永久代加载/卸载时,它们会打印类的标识。如果添加,-XX:+PrintGCDetails您还可以跟踪 permgen 的大小。

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

请注意,我不确定 Sun 以外的 JVM 是否支持这些标志。

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

PermGen 内存不足错误的另一个嫌疑人是字符串实习。检查代码中实习字符串的位置。

回答by mtpettyp

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.

如果您想获得所有已加载类的列表,您可以使用jconsole. 单击类选项卡,然后单击“详细输出”。这将打印加载到的每个类stdout。我发现这对跟踪 JAXB 代理类问题非常有用。

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

您可能必须使用-Dcom.sun.management.jmxremote命令行选项启动您的应用程序jconsole才能附加到它。

回答by Dilum Ranatunga

Will jmap -permgenfit the bill?

jmap -permgen符合要求吗?

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

请参阅 Java 的故障排除指南 http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/memleaks.html#gbyuu