Browsing Object Instance Values

This section provides a tutorial example on how to search for an object instance and browse its values and references in a Java heap dump file through the 'jhat' Web server.

Warning: "jhat" has been discontinued since JDK 9. But if you still have JDK 1.8 installed, you can continue to use it to browser heap dump files generated by JDK 9 to JDK 10.

After looking object instance counts, I want to find some object instances created by my program and browse their values. My program, GarbageCollection.java, used the following code to create many java.lang.Object[] instances:

   private static Object getOneMega() {
      Object[] lst = new Object[10];
      lst[0] = new long[256*128];
      lst[1] = new int[256*256];
      lst[2] = new double[256*128];
      lst[3] = new float[64*256];
      lst[4] = new byte[64*1024];
      String[] l = new String[64*64];
      for (int i=0; i<64*64; i++)
         l[i] = new String("12345678"); // 16B
      lst[5] = l;
      lst[6] = new char[64*512];
      return lst;
   }

I want to find one of these Object[] instances and review its elements.

1. Run a Web browser with http://localhost:7000. The heap dump first page shows up.

2. Click the link of "Show instance counts for all classes (including platform)". The instance count page shows up.

3. Click the link of "instances" in the line of "330 instances of class [Ljava.lang.Object;". Remember that "[Ljava.lang.Object;" is the class name for Object[] arrays. A list of all 330 instances is displayed with their addresses.

3. Click on the first instance of "[Ljava.lang.Object;@0x25a9e6d0 (48 bytes)". The contents of this instance show up:

Object at 0x25a9e6d0

Array of 10 objects

Class:
class [Ljava.lang.Object;

Values
0 : [J@0x25aaea00 (262152 bytes)
1 : [I@0x25aeea10 (262152 bytes)
2 : [D@0x25b2ea20 (262152 bytes)
3 : [F@0x25b6ea30 (65544 bytes)
4 : [B@0x25b7ea40 (65544 bytes)
5 : [Ljava.lang.String;@0x25b8ea50 (16392 bytes)
6 : [C@0x25baa7b0 (65544 bytes)
7 : null
8 : null
9 : null

References to this object:
[Ljava.lang.Object;@0x2536e920 (72 bytes)
   : Element 8 of [Ljava.lang.Object;@0x2536e920

Excellent! I am lucky that the first instance of Object[] is created by my code. "jhat" does a good job showing me everything about this instance. I can continue clicking its values or references to get information.

Conclusion: "jhat" is much easier to use than many Java debugger for browser heap objects.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 java - The Java Program Launcher

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 javadoc - The Java Document Generator

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

JVM Troubleshooting Tools

 JVM Troubleshooting Tools in JDK

 jinfo - VM Option Value Checker

 jinfo - Changing HotSpot VM Option

 jstack - Stack Tracer to Generate Thread Dump

 What Is a Thread Dump?

 Java Thread Deadlock Demo Program

 jstack - Detecting Java Thread Deadlocks

 jmap - JVM Heap Dump Tool

 Printing Histogram of Java Object Heap

 jmap - Generating Heap Dump File

 jhat - Java Heap Analysis Tool

 jhat - Starting Web Server on a Heap Dump File

 Listing Instance Counts of All Classes

Browsing Object Instance Values

 Object Query Language (OQL)

 Searching for Instances with OQL Statements

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

 Miscellaneous Tools

 native2ascii - Native-to-ASCII Encoding Converter

 JAB (Java Access Bridge) for Windows

 Archived Tutorials

 References

 Full Version in PDF/EPUB