我有一個Maven構建似乎偶爾會使Java過程耗盡PermGen內存(EDIT),我從VisualVM瞭解到,堆和PermGen增加顯着每當一個新的建立。現在我想找出泄漏的位置(編輯:而不是隻是擺脫偶爾的例外)。當試圖找到Maven構建內存泄漏HPROF抱怨
看來標準的方法是讓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。
從這裏繼續下去的最好方法是什麼?
你能顯示導致問題的pom文件嗎?你正在運行單元測試還是集成測試? – khmarbaise 2013-02-08 12:51:46
不幸的是我不能顯示有問題的poms。有幾個測試,但沒有重量。我不相信_this_問題是直接與maven相關的,但也許是Guice,或者我只是試圖做一些不受支持的事情。 – 2013-02-08 13:38:59
嘗試將'-XX:-HeapDumpOnOutOfMemoryError'添加到'MAVEN_OPTS'。這應該告訴JVM生成內存轉儲,然後可以通過分析器(如YourKit或VisualVM)進行分析。 – 2013-02-08 16:12:22