Search code examples
javajvmheap-memoryheap-dump

How heap dump collects data


I know there are numerous ways to take heap dump of a Java Process. But I would like to know how these data are collected.

In other words, what component in the JVM provides this heap data, when dump is triggered.


Solution

  • Generally speaking, a tool like "jmap" talks to components that are not part of the Java public APIs: stuff in the sun.jvm.hotspot.* packages.

    • If "jmap" is dumping an attached JVM, it interacts with the JVM's debug agent via JVMTI.

    • In other cases, "jmap" uses various classes in sun.jvm.hotspot.* to extract the information from the JVM processes address space or a core dump.

    If you want to understand the gory details, download the OpenJDK source code (pick any version), locate the JMap.java file, and start reading.