JVM

Java Heap Dumps 

  1.  jmap 

jmap prints heap dumps into a specified file location. This tool is packaged within JDK. It can be found in \bin folder. 

  jmap -dump:format=b,file=/opt/tmp/heapdump.bin 37320 
 

Note: It’s quite important to pass “live” option. If this option is passed, then only live objects in the memory are written into the heap dump file. If this option is not passed, all the objects, even the ones which are ready to be garbage collected are printed in the heap dump file. 

  1. HeapDumpOnOutOfMemoryError 

When an application experiences java.lang.OutOfMemoryError, it’s ideal to capture heap dump right at that point to diagnose the problem because you want to know what objects were sitting in memory and what percentage of memory they were occupying when java.lang.OutOfMemoryError occurred. 

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/tmp/heapdump.bin 

  1. jcmd 

jcmd tool is used to send diagnostic command requests to the JVM. It’s packaged as part of JDK. It can be found in \bin folder. 

jcmd 37320 GC.heap_dump /opt/tmp/heapdump.bin 

https://dzone.com/articles/how-to-capture-java-heap-dumps-7-options

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment