jmap -dump导出jvm堆内存信息时报错

JDK-6882554 : Heap dump request crashs MServer

当前java版本

shell
1
2
3
4
5
6
# java -version
java version "1.8.0_112"

Java(TM) SE Runtime Environment (build 1.8.0_112-b15)

Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

问题描述

导出jvm堆内存信息时,出现如下报错,并且对应pid进程停止

shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# jmap -dump:format=b,file=/home/outfile1106_1 $(ps -ef | grep -v grep | grep tomcat-software | awk '{print $2}')

Dumping heap to /home/outfile1106_1 ...

Exception in thread "main" java.io.IOException: Premature EOF

at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:292)

at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:199)

at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)

at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:224)

at sun.tools.jmap.JMap.dump(JMap.java:247)

at sun.tools.jmap.JMap.main(JMap.java:142)

解决方法

格式:

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

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

shell
1
2
3
4
5
# jmap -J-d64 -dump:format=b,file=/home/outfile1106 $(ps -ef | grep -v grep | grep tomcat-software | awk '{print $2}')

Dumping heap to /home/outfile1106 ...

Heap dump file created

对比导出后文件大小

shell
1
2
3
# ls -lh /home/outfile1106*
-rw------- 1 root root 308M Nov 6 09:24 /home/outfile1106
-rw------- 1 root root 8.0M Nov 6 09:34 /home/outfile1106_1

参考文章:

评论

:D 一言句子获取中...

加载中,最新评论有1分钟缓存...