I have to create heapdumps, which works nice with jmap. My problem is, that jmap takes very long to create the heapdump file. Especially when the heap is getting bigger (> 1GB) it is taking too long.
One situation as example:
When the server gets into trouble with the heapspace, I want to restart it automatically and create a heapdump before the restart. This works, but takes too long to write the heapdump. This way the server is down for too long. The heapdump creation takes longer than one hour.
I know about -XX:+HeapDumpOnOutOfMemoryError
, but most of the time I can find the memory problem before the exception is thrown by the jvm.
Is there an alternative to jmap which writes the heapdumps faster?
A special solution for the example above would also be appreciated.
This question is a mix between programming and system-administration, but I think I'm at the right place here.
i found an answer to my question. this answer to an other question on serverfault gave me the idea.
gdb --pid=<your java pid>
gcore <file name>
detach
quit
jmap -heap:format=b <path to java binary> <core dump file>
In step 4 it's vital you specify the right java binary, otherwise jmap can not attach to the core dump. if you are not sure which binary was used for the java process, open the core dump with gdb:
gdb --core=<core dump file>
There will be a line like this one, telling you the complete path:
Core was generated by '/opt/tomcat/bin/jsvc'.
creating the core dump is much faster, than creating the heapdump directly via jmap. this way you can create a heapdump of a java process without too long downtimes.
EDIT:
when you get the following error message, it might be you have specified the wrong java binary:
to get the right java binary for the jmap call, open the core dump with gdb:
there will be a line like this, telling you the correct binary: