Issue Taking Java Heap Dump
我正在尝试进行Java堆转储以帮助调查内存泄漏。每当我使用此命令时:
1 | jmap -J-d64 -dump:format=b,file=myheapdump -F 29498 |
堆转储文件达到约16,048 kb并停止增长,除非我杀死它,否则jmap将永远运行并且不会停止。或者,我尝试使用此:
1 | jcmd 29498 -F GC.heap_dump heapdump.hprof |
但是由于我是从root用户执行的,并且该进程正在由另一个用户运行,所以我得到了这个信息:
1 2 3 4 5 6 | com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106) at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63) at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208) at sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:147) at sun.tools.jcmd.JCmd.main(JCmd.java:131) |
所以我想我的问题是我在做错什么,而尝试获得此堆转储的最佳方法是什么?
要解决使用jcmd时的错误,可以尝试添加此答案中提到的jvm参数:
com.sun.tools.attach.AttachNotSupportedException:无法打开套接字文件:目标进程未响应或未加载HotSpot VM
如果您使用的是Linux,则另一种可能性是使用此处概述的gdb工具:
https://www.atlassian.com/blog/archives/so-you-want-your-jvms-heap