The Ultimate JHat Dictionary: Java Heap Analysis Terms

Written by

in

jhat (Java Heap Analysis Tool) is a legacy command-line utility used to browse and parse binary Java heap dumps via a localized web server. Though removed from modern JDKs starting with JDK 9, it serves as the foundational conceptual dictionary for how modern profiles explore reference chains and root paths.

A memory leak in Java occurs when semantically useless objects remain directly or indirectly referenced by a Garbage Collection (GC) Root, preventing the JVM from reclaiming space. 📚 The JHat Dictionary: Key Terms & Concepts

To debug memory leaks effectively, you must understand the terminology built into jhat and inherited by modern analyzers:

GC Root: The starting point of object retention. These are objects accessible from outside the heap, such as active thread local variables, system classes, or JNI global references.

Reachable Objects: Any object that still has an active pointer chain linking it back to a GC Root.

Incoming References: The list of other objects pointing to your target object. If an object won’t disappear, look here to find out what is holding onto it.

Outgoing References: The list of objects your target object points to. Useful for seeing what data an oversized collection or cache is pulling into memory.

OQL (Object Query Language): An SQL-like syntax used to query the heap dump. You can filter objects by custom criteria, such as select s from java.lang.String s where s.value.length > 100. 🛠️ The 3-Step Debugging Workflow 1. Generate the Heap Dump (.hprof)

Before you can analyze memory, you must capture a snapshot of the JVM heap. You can capture it automatically on failure or on-demand using JDK commands:

# Capture manually from a running Java process ID (PID) jmap -dump:format=b,file=heapdump.hprof Use code with caution.

Tip: Always add -XX:+HeapDumpOnOutOfMemoryError to your production JVM arguments so a dump drops automatically when a crash occurs. 2. Spin Up the Analysis Server

Pass the generated file into jhat to parse the snapshot and launch a local browser interface: jhat -J-Xmx4g heapdump.hprof Use code with caution.

Note: Set the -J-Xmx flag to give jhat enough RAM to parse the dump file, which is usually larger than the heap itself. 3. Inspect via the Web Interface

Open your web browser and navigate to http://localhost:7000. Use the following views to isolate the culprit:

All Classes (excluding platform): Scroll to the bottom of the main page to skip java.* packages. Look for your custom classes and inspect their instance counts.

Instance Counts: Identify classes with an unusually high or growing number of instances.

Path to GC Root: Click on a suspected leaking instance and choose “Exclude weak/soft refs” to see the hard pointer chain keeping it alive. 🔍 Standard Leak Culprits to Look For

If you are hunting down a leak, check for these common programming anti-patterns: Solving Java Memory Leaks

Comments

Leave a Reply

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