1

我有一个 Maven 构建,它似乎偶尔会出现泄漏,导致 Java 进程耗尽 PermGen 内存(编辑),我从 VisualVM 了解到,每当构建新的时,堆和 PermGen 显着增加。现在我想找出泄漏的位置(编辑:而不仅仅是摆脱偶尔的异常)。

似乎标准的方法是让 HPROF 收集数据以进行验尸分析。但是,这对我来说失败了,并且生成的 java.hprof 文件无法被工具正确解析。

我的“mvn.bat”文件看起来像(Windows 7 上的 64 位 JVM):

set JAVA_HOME=c:\Program Files\java\jdk1.7.0_11
C:\Users\TRA\progs\apache-maven-3.0.4\bin\mvn %*

我的 MAVEN_OPTS 看起来像

MAVEN_OPTS=-agentlib:hprof=format=b

这是“mvn clean”的结果。

[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.589s
[INFO] Finished at: Fri Feb 08 12:46:26 CET 2013
[INFO] Final Memory: 8M/154M
[INFO] ------------------------------------------------------------------------
Dumping Java heap ...
HPROF LIST OF ALL FIELDS:
[1] Lsun/reflect/UnsafeFieldAccessorImpl; "field" "Ljava/lang/reflect/Field;"(ty=OBJ) val=[0x00000000,0x500007e0] or [0x00000000,0x500007e0]
[2] Lsun/reflect/UnsafeFieldAccessorImpl; "fieldOffset" "I" (primType=73(I)) val=[0x00000007,0x00000070] or [0x00000007,0x00000070]
[3] Lsun/reflect/UnsafeFieldAccessorImpl; "isFinal" "Z" (primType=90(Z)) val=[0x00000007,0x7ae16501] or [0x00000007,0x7ae16501]
[4] Lsun/reflect/UnsafeStaticFieldAccessorImpl; "base" "Ljava/lang/Object;"(ty=OBJ)
[5] Lsun/reflect/UnsafeQualifiedStaticFieldAccessorImpl; "isReadOnly" "Z" (primType=90(Z))

FOLLOW REFERENCES RETURNED:
[1]: flavor=1, refKind=2, primType=0, object_index=0x500007e0, length=-1, next=0xb0013852
[2]: flavor=2, refKind=2, primType=73, object_index=0x0, length=-1, next=0xb0013851
[3]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0xb0013850
[4]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0x0

PROBLEM WITH:
[4] Lsun/reflect/UnsafeStaticFieldAccessorImpl; "base" "Ljava/lang/Object;" (primType=0( ), got 90(Z)) val=[0x00000007,0x7ae16501] or [0x00000000,0x00000000]

HPROF ERROR: Trouble with fields and heap data [hprof_reference.c:281]

HPROF LIST OF ALL FIELDS:
[1] Lsun/reflect/UnsafeFieldAccessorImpl; "field" "Ljava/lang/reflect/Field;"(ty=OBJ) val=[0x00000000,0x500007e1] or [0x00000000,0x500007e1]
[2] Lsun/reflect/UnsafeFieldAccessorImpl; "fieldOffset" "I" (primType=73(I)) val=[0x00000007,0x00000074] or [0x00000007,0x00000074]
[3] Lsun/reflect/UnsafeFieldAccessorImpl; "isFinal" "Z" (primType=90(Z)) val=[0x00000007,0x7b2c1001] or [0x00000007,0x7b2c1001]
[4] Lsun/reflect/UnsafeStaticFieldAccessorImpl; "base" "Ljava/lang/Object;"(ty=OBJ)
[5] Lsun/reflect/UnsafeQualifiedStaticFieldAccessorImpl; "isReadOnly" "Z" (primType=90(Z))

FOLLOW REFERENCES RETURNED:
[1]: flavor=1, refKind=2, primType=0, object_index=0x500007e1, length=-1, next=0xb0013836
[2]: flavor=2, refKind=2, primType=73, object_index=0x0, length=-1, next=0xb0013835
[3]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0xb0013834
[4]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0x0

PROBLEM WITH:
[4] Lsun/reflect/UnsafeStaticFieldAccessorImpl; "base" "Ljava/lang/Object;" (primType=0( ), got 90(Z)) val=[0x00000007,0x7b2c1001] or [0x00000000,0x00000000]

HPROF ERROR: Trouble with fields and heap data [hprof_reference.c:281]

HPROF LIST OF ALL FIELDS:
[1] Lsun/reflect/UnsafeFieldAccessorImpl; "field" "Ljava/lang/reflect/Field;"(ty=OBJ) val=[0x00000000,0x5002f4a1] or [0x00000000,0x5002f4a1]
[2] Lsun/reflect/UnsafeFieldAccessorImpl; "fieldOffset" "I" (primType=73(I)) val=[0x00000007,0x00000070] or [0x00000007,0x00000070]
[3] Lsun/reflect/UnsafeFieldAccessorImpl; "isFinal" "Z" (primType=90(Z)) val=[0x00000007,0x7ae16501] or [0x00000007,0x7ae16501]
[4] Lsun/reflect/UnsafeStaticFieldAccessorImpl; "base" "Ljava/lang/Object;"(ty=OBJ)
[5] Lsun/reflect/UnsafeQualifiedStaticFieldAccessorImpl; "isReadOnly" "Z" (primType=90(Z))

FOLLOW REFERENCES RETURNED:
[1]: flavor=1, refKind=2, primType=0, object_index=0x5002f4a1, length=-1, next=0xb0013a4b
[2]: flavor=2, refKind=2, primType=73, object_index=0x0, length=-1, next=0xb0013a4a
[3]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0xb0013a49
[4]: flavor=2, refKind=2, primType=90, object_index=0x0, length=-1, next=0x0

(并且不断地不断地)。我不熟悉hprof。

从这里继续的最佳方式是什么?

4

1 回答 1

0

从 32 位 jvm 切换到 64 位 jvm 的经典问题是 PermGen 异常。

使用 64 位 JVM 时,您需要更大的 PermGen 大小。如果需要,尝试使用类似MAVEN_OPTS="-XX:MaxPermSize=256m"或更高的东西。

我个人在使用64 位 jvm 构建大型项目时使用512m甚至1g 。那些相同的项目需要 32 位 jmvs 的一半。

于 2013-02-08T19:53:17.027 回答