Wednesday, February 22, 2012

Checking Java Heap and Thread Dumps in Unix / Solaris

Heap Dump

JAVA_HOME/bin/jmap -heap:format=b ******

where ****** is process id
Attaching to process ID *****, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 1.5.0_12-b04
Free chunk in heap, size=131072
Free chunk in heap, size=792741552
Free chunk in heap, size=148364752
Unknown oop at 0x00002aaafab6b6a8
Oop's klass is 0x00002aab06801de8
Finding object size using Printezis bits and skipping over...
heap written to heap.bin
It generates file “heap.bin”


Thread Dump
kill -QUIT ******


Thread dump appends info to already existing stdout logs usually in tomcat server

 Heap Dump : Another way

/usr/java/jdk1.5.0_12/bin/jmap -dump:format=b,file=heap.bin <pid>

The –heap option below prints a heap summary.  Not sure we want that in combination with the format=b.  When I ran the command below locally on my eclipse instance, it took about 5 mins to generate the heap.  When I used the command above it only took about 5 seconds.  Both heap dumps created seem valid, but according to the Usage guide –heap doesn’t have options with it, so not sure what the command is doing and the fact that it is taking a long time may be why you saw it puke.

Anyone else have some feedback on the command?

Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -permstat            to print permanent generation statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system
 

No comments:

Post a Comment