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.

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.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

JVM Troubleshooting Tools

 JVM Troubleshooting Tools in JDK 1.5

 'jinfo' - VM Option Value Checker

 Changing HotSpot VM Option using 'jinfo'

 'jstack' - Stack Tracer to Generate Thread Dump

 What Is a Thread Dump?

 Java Thread Deadlock Demo Program

 Detecting Java Thread Deadlocks with 'jstack'

 'jmap' - JVM Heap Dump Tool

 Printing Histogram of Java Object Heap

 Generating Heap Dump File with 'jmap'

 'jhat' - Java Heap Analysis Tool

 Starting 'jhat' 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

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version