Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

i found an answer to my question. this answer to an other question on serverfault gave me the idea.

  1. connect with gdb to your java process
    gdb --pid=<your java pid>
  2. create core dump from gdb
    gcore <file name>
    detach
    quit
  3. restart the java process or do what ever you like
  4. create a heap dump from the core dump, by connecting jmap to the core dump
    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:

Error attaching to core file: Can't attach to the core file

to get the right java binary for the jmap call, open the core dump with gdb:

gdb --core=[path tp core file]

there will be a line like this, telling you the correct binary:

Core was generated by `/opt/tomcat/bin/jsvc'.
share|improve this answer
    
my JSK doesnt include "gdb". is this something that comes with another variety of Java? –  djangofan Mar 17 '11 at 23:24
    
gdb is not part of the JDK. gdb is the GNU debugger, which is part of any Linux distribution I'm aware off. –  Christian Mar 18 '11 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.