java - 如何解释 "jmap -permstat"的输出?

标签 java permgen jmap

我正在尝试解决 permgen 泄漏问题,并想就如何解释 jmap -permstat 的输出征求大家的意见。

假设我有一个 jmap -permstat 报告,如下所示:

class_loader        classes  bytes     parent_loader       alive?  type

<bootstrap>            4791  25941568                null   live  <internal>
0x00000007203ed508        0         0  0x00000007203ed228   dead  com/example/object/SomeObjectType$FirstClassLoader@0x0000000something1
0x000000071dc17620        1      3056  0x0000000705e692a8   dead  sun/reflect/DelegatingClassLoader@0x0000000something4
0x000000071f26a898        0       100                null   dead  com/example/object/SomeClassLoader@0x0000000something3
0x0000000721c6dba0        0       100                null   dead  com/example/object/SomeClassLoader@0x0000000something3
0x000000071e36df20        0       100                null   dead  com/example/object/SomeClassLoader@0x0000000something3
0x000000072157c1b8      339   2069112  0x000000072157b8d8   dead  com/example/object/SomeObjectType$SecondClassLoader@0x0000000something2
0x00000007128b7830        1      1912  0x0000000700056db8   dead  sun/reflect/DelegatingClassLoader@0x0000000something4
0x0000000707634360        1      3088  0x0000000700056db8   dead  sun/reflect/DelegatingClassLoader@0x0000000something4

以下是我对上述输出的解释——请更正我在这样做时所犯的任何错误。

“类型”列中的值不是唯一的。我们看到一些物体出现了三次。但是,class_loader 值在所有三个中都是唯一的;因此,它们中的每一个都是一个独特的对象,占据永久空间。本例中,每一个占100字节;因此,SomeClassLoader 类型的对象占用了 300 字节的 permgen 空间。

如果 classes 值不为零,那么这个对象一定是某种类加载器,this 指的是它引用的类的数量。 (注意:在实际文件中,这三个对象在 bytes 列中有零;我已经为这个例子添加了值。在实际实践中,我猜测如果 classes 列中有一个 0,则不可能字节值不能为零。)

如果 alive 值为“dead”,则表示该对象已准备好进行垃圾回收,但 JVM 并未这样做。关于为什么会出现这种情况的原因,需要单独讨论。

如果 parent_loader 列中有一个值,那么这是一个被另一个类加载器引用的对象,并且在该对象被垃圾回收之前不能被垃圾回收。

最后: 1) 如果我在报告中看到 500 行都列出了相同的类型, 2) 但他们列出了不同的 class_loader 值, 3)然后我可以将字节列中的值相加 4) 这将准确地表示该类型的对象占用了多少 permgen 空间。

这是正确的吗?谢谢!

最佳答案

从这里blog entry :

For each class loader object, the following details are printed:

  1. (class_loader) The address of the class loader object – at the snapshot when the utility was run.
  2. (classes) The number of classes loaded (defined by this loader with the method(java.lang.ClassLoader.defineClass).
  3. (bytes) The approximate number of bytes consumed by meta-data for all classes loaded by this class loader.
  4. (parent_loader) The address of the parent class loader (if any).
  5. (alive?) A “live” or “dead” indication – indicates whether the loader object will be garbage collected in the future.
  6. (type) The class name of this class loader.

永久生成不包含普通对象,而是类元数据(参见 What does PermGen actually stand for? )。所以,重写你的陈述:

Finally: 1) If I see 500 lines on the report that all list the same type, 2) but they list different class_loader values, 3) then I can add up the values in the bytes column 4) and this will accurately represent how much permgen space is being occupied by meta-data for all classes loaded by class loader objects of the same (SomeClassLoader) class.

Eclipse Memory Analyzer 工具显示的“Retained Heap”是指对象消耗的堆内存(新旧内存)。

永久代在堆之外(参见 https://stackoverflow.com/a/12058171/33622)并处理类元数据

关于java - 如何解释 "jmap -permstat"的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13365961/

相关文章:

java - Maven 构建在执行测试期间抛出 java.lang.ClassNotFoundException

java - 如何在每次运行我的应用程序时生成一个唯一的随机数?

java - 设置 XX :MaxMetaspaceSize to the same old XX:MaxPermSize value 后垃圾收集器停止运行

java - nmap 的默认堆转储格式是什么?

java - 使用 jmap(1.5) 从 java 核心转储中提取信息

java - 无法从 JSP 访问 WEB-INF 下定义的 CSS 文件

java - 由于 : java. lang.OutOfMemoryError: PermGen 空间,Tomcat6 经常挂起

java - 为什么 PermGen Commit 增量这么小?

java - org.hibernate.hql.internal.ast.tree.Node 在 jmap 堆转储中意味着什么

java - Hiber 缓存 : Cache all fixed data permanently