How to take heap dump of a java process

To take heap dump in java we can use jmap.exe avaialble in JAVA_HOME/bin/ directory

jmap.exe -dump:format=b,file=D://filename.hprof 2860

Here 2860 is the Process Id of my java application.to find process id of your application we can use jcmd.exe

jcmd.exe -l 

output:

6132 sun.tools.jcmd.JCmd -l
2860 quartz.QuartzSchedularExample

once the heap dump file is created, use jvisualvm.exe tool present in java bin directory,in jvisualvm GUI select load and browse your dump file.

Note:If you want a heapdump on out-of-memory, you can start Java with the option

-XX:-HeapDumpOnOutOfMemoryError

the above option will take a heap dump when OutOfMemoryError thrown by JVM

Example:

java -jar -XX:-HeapDumpOnOutOfMemoryError myApp.jar
Advertisements
This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s