jhat
Analyze Java heap dumps
TLDR
Analyze a heap dump (from jmap), view via HTTP on port 7000
Analyze a heap dump, specifying an alternate port for the HTTP server
Analyze a dump letting jhat use up to 8 GB RAM (2-4x dump size recommended)
SYNOPSIS
jhat [ options ] <heap-dump-file>
PARAMETERS
-port
Specifies the port for the HTTP server. The default port is 7000.
-exclude
Specifies a file containing a list of data members to exclude from the reachable objects query.
-stack false|true
Turns off or on the tracking of object allocation call stacks. Default is true. Setting to false can save memory.
-refs false|true
Turns off or on tracking of references to objects. Default is true. Setting to false can save memory.
-debug
Sets the debug level for jhat. Higher levels provide more verbose output.
-force
Forces parsing of the heap dump even if errors are encountered during the process.
-J
Passes
DESCRIPTION
jhat (Java Heap Analysis Tool) is a command-line utility bundled with older Java Development Kit (JDK) versions. It parses a Java heap dump file and launches a web server, allowing users to browse and query the objects within the heap dump using a web browser. It's particularly useful for diagnosing memory leaks and understanding memory consumption patterns in Java applications. After a heap dump is generated (often using jmap -dump), jhat can be pointed to this file to provide an interactive view of objects, their references, and paths to Garbage Collection (GC) roots. While powerful for basic analysis, jhat can be memory-intensive for large heap dumps and has been superseded by more advanced and efficient tools in newer JDK versions.
CAVEATS
jhat can consume significant amounts of memory, potentially more than the heap dump itself, especially for large heap files. Its performance can be slow, and the interactive web interface might become sluggish with extensive data.
A critical limitation is its deprecation and subsequent removal starting from JDK 9. For modern Java development, more robust and efficient tools like Eclipse Memory Analyzer (MAT), YourKit Java Profiler, or the jcmd utility (which can perform heap analysis via jcmd
<I>WEB INTERFACE NAVIGATION</I>
After jhat successfully parses a heap dump and starts its HTTP server, you can access the analysis through a web browser (e.g., http://localhost:7000/). The interface typically offers:
- All Classes: A list of all loaded classes.
- Show heap histogram: A summary of object counts and sizes.
- Show instance counts for all classes (excluding platform): Similar to histogram but excluding system classes.
- Show roots: Displays Garbage Collection roots.
- OQL Query: Allows execution of Object Query Language (OQL) queries to find specific objects or object patterns.
<I>TYPICAL USAGE WORKFLOW</I>
1. Generate Heap Dump: Use jmap to create a heap dump.
Example: jmap -dump:format=b,file=/tmp/heapdump.hprof
2. Analyze with jhat: Run jhat against the generated dump file.
Example: jhat -port 8000 /tmp/heapdump.hprof
3. Browse: Open a web browser to http://localhost:8000/ to explore the heap contents.
4. Query: Use the OQL interface to run specific queries for objects, references, and paths to GC roots.
HISTORY
jhat was introduced as part of the Java Development Kit (JDK) 6 to provide a built-in tool for heap dump analysis. Its primary goal was to offer a convenient, accessible way to explore memory issues without requiring complex external tools. However, due to its significant memory footprint, performance limitations, and the emergence of more sophisticated profiling and analysis tools, jhat was deprecated in JDK 8 and completely removed from the JDK distribution starting with JDK 9. The functionality is now typically covered by jcmd for dump generation and external tools for analysis.