Friday, October 14, 2016

Acquire Heap Dump of Java Process

When it comes to production troubleshooting with Java Servers, It is a main fact that we need to analyze the memory consumption.  Normally if we have configured following properties , It will automatically create the heap dump when there is an OutOfMemory exception.

 -XX:+HeapDumpOnOutOfMemoryError  
 -XX:HeapDumpPath=<path>  

There are some OOM exceptions which is not creating heap dump since it is not related to memory. You can understand on various OutOfMemory Exceptions in the article [1].


But, If you need to get a heap dump at a time which server is consuming memory but not yet throwing OOM Exception, You can use following command to do that.

Assuming that you have set JAVA_HOME and PID is the Process ID.

In a Linux based system.
 jmap -dump:format=b,file=./heap.hprof <PID>  

In a windows based system

 <JAVA_HOME>/bin/jmap -dump:format=b,file=c:\temp\heap.hprof <PID>  



Once you obtain the heap dump, You can analyze it using tools like MAT, VisualVM.



[1] https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html

No comments:

Post a Comment