Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

This is a nice trick I learned over the past week while doing JVM heap analysis. You can use JConsole to take a heap dump of your JVM. Open the MBeans tab and navigate to com.sun.management, then HotSpotDiagnosticMXBean. This will display all the methods that can be invoked on this bean. We're interested in the dumpHeap method.

The JDK documentation describes this method as:
 Method Signature
void dumpHeap(String outputFile, boolean live) throws IOException

HotSpotDiagnosticMXBean.png


So the first parameter is the file name to write the heap dump to and the second controls whether all objects or just the live objects are to be dumped. If you specify false, it will include all objects that are not reachable and are waiting to be garbage collected, otherwise it will only include just the reachable objects.



-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.