How to make your heap dump more informative

By default, a heap dump contains almost no “JVM-internal” information. However, this information, such as the maximum heap size, GC type, GC tuning parameters, etc. can be very helpful in the JXRay analysis.

Why is it useful? Here are some examples:
1. If a heap dump is generated after an OutOfMemoryError is thrown, it is very helpful to know what the maximum heap size is. If total used heap, calculated by heap dump analysis, is much smaller than the maximum heap size, the situation is special and requires expert analysis. JXRay can do it – if maximum heap size is available.
2. G1 and Shenandoah GCs manage the heap by dividing it into regions. The number of regions is determined at app startup and does not change. It is typically around 2000. Humongous objects (objects exceeding 50% of a single heap region size) waste memory primarily through internal fragmentation (unused space inside allocated regions) and premature tenure (trapping short-lived objects in the slow-to-collect Old Generation). See this article for more information. JXRay can analyze Humongous objects and offer tips on how to fix the above problems – if heap region size is available.
3. Sometimes an app may run on misconfigured JVM, that reduce its performance. JXRay can detect some such situations, and developers themselves may be able to detect more.

The information that we need is contained in the JVM command line arguments used for the app that generated the given heap dump. To make these arguments available to JXRay, you can use either of the following methods:

  1. Save the arguments into a text file, and then pass them to JXRay using the -jvm_flags_file <file> flag
  2. Add the following code to your app, and make sure it gets executed before the dump is generated:
    import java.lang.management.ManagementFactory;

    List<String> jvmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
    System.getProperties().put("java.vm.inputarguments", String.join(" ", jvmArgs));

    JXRay recognizes the above custom system property stored in the heap dump as the list of JVM arguments.

Leave a Reply

Your email address will not be published. Required fields are marked *