jhat for heap dump analysis

All

I thought I had already had written this blog post long ago. I might be mistaken, maybe when I wrote about the fact there is no more Jhat after OpenJDK 9, or talking about jVisualVM.

Well, I will miss it.

Jhat

‘jhat’ is a heap analysis tool that parses a Java heap dump and enables web-browsing a parsed heap dump, and even write Object Query Language interface [1]

Pretty straight forward, the help is below only with the options I actually use:

Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>

-J<flag> Pass <flag> directly to the runtime system. For
example, -J-mx512m to use a maximum heap size of 512MB

-port <port>: Set the port for the HTTP server. Defaults to 7000

-baseline <file>: Specify a baseline object dump. Objects in
both heap dumps with the same ID and same class will
be marked as not being “new”.

-debug <int>: Set debug level.

0: No debug output
1: Debug hprof file parsing
2: Debug hprof file parsing, no server
-version Report version number

-h|-help Print this help and exit
<file> The file to read

  1. Get the hprof file – aka heap dump
  2. Execute jhat to analyze:

$JDK/bin/jhat -J-Xmx3g -port 7001 example.hprofReading from java_pid30212.hprof…
Dump file created Thu Feb 27 05:32:01 EST 2020
Snapshot read, resolving…
Resolving 15958718 objects…
Chasing references, expect 3191 dots…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..
Eliminating duplicate references…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..
Snapshot resolved.
Started HTTP server on port 7001
Server is ready.

This tells the jhat will use 3g will affect the effect of the heap size of JVM. In this case, I do not use the parameter file, but rather, pass the file directly at the end.

-f= file.hprof

3. Open the browser with port 7001 on this case, specified with -port 7001.

http://localhost:7001/

4. Do the OQL queries, example ~ to investigate native memory leak:

    SELECT k, k.capacity FROM java.nio.DirectByteBuffer k

Example with MAT for Query:

mat_example

All Classes (excluding platform)

Package <Arrays>

(…)

(…)

5. See ~ which is quite useful to count objects:

Execute Object Query Language (OQL) query

Select * from org.hornetq.core.client.impl.ServerLocatorImpl o WHERE o.initialConnectors != null

You can use this OQL or the class would be on jhat console directly.

http://localhost:7001/allClassesWithPlatform/

Reference

[1] https://www.infoq.com/news/2015/12/OpenJDK-9-removal-of-HPROF-jhat/

[2] This book covers a little bit of the tool and has several OQL queries for guidance.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s