Where is the heap dump file created by jcmd?

9.6k Views Asked by At

I have tried to take a heap dump using jcmd (from a git bash console window):

$ /c/Program\ Files/Java/jdk1.8.0_202/bin/jcmd 25156 GC.heap_dump filename=livetest-grindtohalt.hprof
25156:
Heap dump file created

However, the file does not seem to exist:

$ find -name livetest-grindtohalt.hprof

$

Where can I find it?

3

There are 3 best solutions below

0
On BEST ANSWER

The answer by Douglas Kretzmann sets you on the correct path to practical jcmd use. To answer the question from the original post, relative paths are resolved against the current working directory of the specified java process. So after

jcmd 6232 GC.heap_dump heap.hprof

you will be able to find heap.hprof in the directory output by

lsof -p 6232 | grep cwd
3
On

I had the same problem in windows.

jcmd 6232 GC.heap_dump filename=IShp1.hprof

it ran, said file created, but a search of c drive couldn't find it. Reran and got 'file exists'.

Tried with a path specified in filename, and a different file name,

jcmd 6232 GC.heap_dump filename=c:\temp\IShp2.hprof

This also got 'file exists'.

I conclude 'filename' is not being honored. Presumably jcmd is writing some internally-specified unknown file name to some unknown location, when the 'filename' is specified.

Instead

jcmd 6232 GC.heap_dump c:\temp\isHpdmp1.hprof

works and writes the file to the specified location. So presumably for *nix something like

jcmd 6232 GC.heap_dump /opt/temp/myHd.hprof 
0
On

Literally upstream refuses to "fix" diagnostic for 4 years:

https://bugs.openjdk.java.net/browse/JDK-8177763 - Getting an hprof dump via jcmd could benefit from stronger option checking.

And official docs: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks004.html presents incorrect examples, like:

Example 3-2 Create a Heap Dump using jcmd

jcmd <process id/main class> GC.heap_dump filename=Myheapdump

Just strip filename=.

Current working directory for dump is of PID process, not of jcmd! So use full path if you don't want to search for dump )) Full workflow:

mkdir dest/
chmod a+w dest/

sudo jcmd
1234 my.evil.app

sudo -u myuser -g mygrp jcmd 1234 GC.heap_dump $PWD/dest/myapp.hprof