LinuxCommandLibrary

jhat

Analyze Java heap dumps

TLDR

Analyze a heap dump (from jmap), view via HTTP on port 7000

$ jhat [dump_file.bin]
copy

Analyze a heap dump, specifying an alternate port for the HTTP server
$ jhat [[-p|-port]] [port] [dump_file.bin]
copy

Analyze a dump letting jhat use up to 8 GB RAM (2-4x dump size recommended)
$ jhat -J-mx8G [dump_file.bin]
copy

SYNOPSIS

jhat [ options ] heap-dump-file

PARAMETERS

heap-dump-file
    The path to the heap dump file to analyze.

-stack false | true
    Turns off tracking of object allocation call stack. Defaults to true.

-refs false | true
    Turns off tracking of references to objects. Defaults to true.

-port port-number
    Sets the port for the HTTP server. Defaults to 7000.

-exclude file
    Specifies a file containing a list of data members that should be excluded from the object graph. Useful for simplifying the view.

-baseline file
    Specifies a baseline heap dump file to compare against. Used to find objects that are only in the current heap dump.

-debug int
    Sets debug level.

-version
    Prints the version of jhat

-help
    Prints the help message

DESCRIPTION

The jhat command is a command-line tool used to analyze Java heap dumps. It parses a Java heap dump file (typically created using jmap or jcmd) and starts an HTTP server, allowing you to browse the object graph of the heap using a web browser. This helps identify memory leaks, understand object relationships, and analyze memory usage patterns in a Java application.

jhat provides a user-friendly interface to explore the heap, query object properties, and follow object references. It is particularly useful for post-mortem debugging when a Java application has encountered an OutOfMemoryError or exhibits unexpected memory consumption. Analyzing heap dumps helps pinpoint the root cause of memory-related issues in your Java applications.

CAVEATS

jhat can be resource-intensive, especially for large heap dumps. Processing a very large heap dump can take a significant amount of time and consume a lot of memory. Also, due to security concerns, avoid using jhat in production environments without proper precautions. The HTTP server it starts is very basic and is not designed for high security or performance.

<B>SECURITY CONSIDERATIONS</B>

The HTTP server started by jhat is not designed for production environments and lacks security features. It's highly recommended to restrict access to the jhat server to authorized users and avoid exposing it to the public internet.

<B>ALTERNATIVES</B>

Modern IDEs like Eclipse and IntelliJ IDEA offer heap analysis tools that often provide more advanced features and a more user-friendly interface than jhat. Tools like VisualVM, MAT (Memory Analyzer Tool), and YourKit also provide more advanced analysis capabilities.

HISTORY

jhat was originally part of the JDK and provided as a standalone tool for heap analysis. Over time, its usage has decreased as more sophisticated memory analysis tools have become available. However, it remains a useful tool for quick heap dump analysis, especially in environments where other tools are not readily accessible. It is a historical tool that introduced the concept of interactive heap analysis via a web browser. It has been part of the JDK since Java 6.

SEE ALSO

jmap(1), jcmd(1)

Copied to clipboard