Java jmap 命令出现堆转储错误:过早的 EOF

Java heap dump error with jmap command : Premature EOF

我在执行以下命令时遇到以下异常

jmap -dump:format=b,file=heap_dump.bin <process_id>

输出:

Dumping heap to <file_name>
Exception in thread "main" java.io.IOException: Premature EOF
            at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:248)
            at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:199)
            at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:217)
            at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:180)
            at sun.tools.jmap.JMap.dump(JMap.java:242)
            at sun.tools.jmap.JMap.main(JMap.java:140)

JDK 版本:1.7.0_45

VM_OPTs :

-Xms2g -Xmx4g  -XX:+UseG1GC -XX:MaxGCPauseMillis=1500 
-XX:G1HeapRegionSize=2 -XX:+PrintFlagsFinal -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2 

硬件:RHEL 5.x,4 核 CPU Linux 机器 6 GB RAM

根据 oracle 错误报告数据库 (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6882554),此问题已得到修复,但我仍在使用构建 no:45

获得 jdk 1.7 版本

除了升级到 Jdk 1.8 之外,您能否提出任何解决方案,由于其他依赖项,这在我的情况下是不可能的?

编辑:

我已尝试使用以下命令,但此命令也不起作用(生成了部分转储文件)并显示相同的过早 EOF。

jmap -J-d64 -dump:format=b,file=<filename> <pid>

我已经与启动进程的用户触发了命令。该用户对该目录具有写权限。文件已生成,但不完整。

9 MB 文件是为 2 GB 堆编写的,无法用于分析。

Brian 的评论有助于解决问题。

如果您在 64 位机器上使用 G1GC 算法:

以下命令不起作用(不包括 live 选项)

jmap -J-d64 -dump:format=b,file=<heap_dump_filename> <pid>

您必须使用以下选项来获取堆转储

jmap -J-d64 -dump:live,format=b,file=<heap_dump_filename> <PID>

有一些建议使用 -F 选项来强制堆转储,但根据 oracle technotes:

-F Force. Use with jmap -dump or jmap -histo option if the pid does not respond. The live suboption is not supported in this mode.

由于 G1GC 选项需要堆转储,因此无法使用上述选项。