我正在尝试解决 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:
- (class_loader) The address of the class loader object – at the snapshot when the utility was run.
- (classes) The number of classes loaded (defined by this loader with the method(java.lang.ClassLoader.defineClass).
- (bytes) The approximate number of bytes consumed by meta-data for all classes loaded by this class loader.
- (parent_loader) The address of the parent class loader (if any).
- (alive?) A “live” or “dead” indication – indicates whether the loader object will be garbage collected in the future.
- (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/