Create Java heapdumps with the help of core dumps

转载自:http://devops-abyss.blogspot.com/2010/03/create-java-heapdumps-with-help-of-core.html

 

Hi,

for some time I had the problem, that taking Java heap dumps with jmap took too long. When one of my tomcats crashed by an OutOfMemoryException, I had no time to do a heap dump because it took some hours and the server had to be back online.

Now I found a sollution to my problem. The initial idea came from this post. It had a solution for Solaris, but with some googling and try and error I found a solution for linux too.

  1. create a core dump of your java process with gdb
    gdb --pid=[java pid]
    gcore [file name]
    detach
    quit
  2. restart the tomcat or do whatever you like with the java process
  3. attach jmap to the core dump and create a Java heap dump
    jmap -heap:format=b [java binary] [core dump file]
  4. analyze your Java heap dump with your prefered tool

 When you get the following error in step three:

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

This might help:
In my case the error apeared because I used the wrong java binary in the jmap call. When you are not sure about your java binary, open the core dump with gdb:

gdb --core=[core dump file]

You will get an output similar to this one:

GNU gdb 6.6 Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB.  Type "show warranty" for details. This GDB was configured as "i586-suse-linux"... (no debugging symbols found) Using host libthread_db library "/lib/libthread_db.so.1".
warning: core file may not match specified executable file. (no debugging symbols found) Failed to read a valid object file image from memory. Core was generated by `/opt/tomcat/bin/jsvc'. #0  0xffffe410 in _start ()

 What you are looking for is in this line:

Core was generated by `/opt/tomcat/bin/jsvc'.

 Call jmap with this binary and you will get a heapdump.

你可能感兴趣的:(java,tomcat,linux,Solaris,SuSE)