2

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?

JRG
  • 4,037
  • 3
  • 23
  • 34
jymbo
  • 1,335
  • 1
  • 15
  • 26
  • What about running `jmap` (without -F) from the same user account as used to run JVM? – apangin Jul 30 '17 at 10:40
  • I get an error stating that the user does not have permission – jymbo Jul 30 '17 at 15:10
  • What permission? To create a dump file? Try a different directory which the user has permission to write to. – apangin Jul 30 '17 at 18:40
  • Attempting to use jcmd as the process owner, and writing to a directory that is owned by the same user I get this: Permission denied – jymbo Jul 31 '17 at 16:51

1 Answers1

0

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

kingdc
  • 135
  • 8
  • 1
    Adding that argument gives another error: jcmd 17272 -XX:+StartAttachListener GC.heap_dump heapdump.hprof 17272: java.lang.IllegalArgumentException: Unknown diagnostic command – jymbo Aug 01 '17 at 16:02
  • 1
    @jymbo From that error message looks like you may have added the argument to the jcmd command itself? The arg would need to be added to the java command of the process which you are trying to get the dump of, when you start up that process – kingdc Aug 01 '17 at 21:51