Documentation Contents
Java Platform, Standard Edition Troubleshooting Guide
Contents    Previous    Next

2.12 The jhat Utility

The jhat tool provides a convenient means to browse the object topology in a heap snapshot. This tool replaces the Heap Analysis Tool (HAT).

For more details on the jhat utility, see the jhat command man page.

The tool parses a heap dump in binary format (for example, a heap dump produced by jmap -dump).

This utility can help debug unintentional object retention. This term is used to describe an object that is no longer needed but is kept alive due to references through some path from the rootset. This can happen, for example, if an unintentional static reference to an object remains after the object is no longer needed, if an Observer or Listener fails to unregister itself from its subject when it is no longer needed, or if a Thread that refers to an object does not terminate when it should. Unintentional object retention is the Java language equivalent of a memory leak.

The following sections describe troubleshooting techniques for jhat utility.

2.12.1 Troubleshoot with jhat Utility

The tool provides a number of standard queries. For example, the Roots query displays all reference paths from the rootset to a specified object and is particularly useful for finding unnecessary object retention.

In addition to the standard queries, you can develop your own custom queries with the Object Query Language (OQL) interface.

When you issue the jhat command, the utility starts an HTTP server on a specified TCP port. You can then use any browser to connect to the server and execute queries on the specified heap dump.

Example 2-17 shows how to execute jhat to analyze a heap dump file named snapshot.hprof:

At this point, jhat has started an HTTP server on port 7000. Point your browser to http://localhost:7000 to connect to the jhat server.

When you are connected to the server, you can execute a standard query, see Standard Queries or create an OQL query, see Custom Queries. The All Classes query is displayed by default.

2.12.2 Standard Queries

When you have connected to the jhat server, you can execute the following standard queries:

2.12.3 Custom Queries

You can develop your own custom queries with the built-in Object Query Language (OQL) interface. Click the Execute OQL Query button on the first page to display the OQL query page, where you can create and execute your custom queries. The OQL Help facility describes the built-in functions, as shown in Example 2-18.

The syntax of the select statement is as follows:

2.12.4 Heap Analysis Hints

To get useful information from jhat often requires some knowledge of the application and the libraries and APIs that it uses. You can use jhat to answer two important questions:

Contents    Previous    Next

Oracle and/or its affiliates Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved.
Contact Us