I'm trying to take a java heap dump to help investigate a memory leak. Whenever I use this:
jmap -J-d64 -dump:format=b,file=myheapdump -F 29498
The heap dump file gets to about 16,048 kb and stops growing, jmap will run forever and not stop unless I kill it. Alternatively I tried using this:
jcmd 29498 -F GC.heap_dump heapdump.hprof
But since I am executing it from root, and the process is being run from another user, I get this:
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)
So I guess my question is what am I doing wrong and what is the best way to move forward in trying to get this heap dump?
To get around the error when using jcmd, you can try adding the jvm argument mentioned in this answer: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
Another possibility if you're using Linux is to use the gdb tool as outlined here: https://www.atlassian.com/blog/archives/so-you-want-your-jvms-heap