Listing Instance Counts of All Classes

This section provides a tutorial example on how to list object instance counts of all loaded classes 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 and JDK 10.

Running "jhat" Web server on a heap dump file offers us a very good debugging tool. You can get statistical counts of loaded classes and objects. You can review object contents and references. You can also run object queries to search for any specific information.

First, let's see how to get instance counts for all loaded classes.

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:

65733 instances of class java.lang.String 
362 instances of class java.lang.Class 
330 instances of class [Ljava.lang.Object; 
206 instances of class [C 
66 instances of class [Ljava.lang.String; 
58 instances of class java.util.Hashtable$Entry 
50 instances of class [I 
26 instances of class [B 
19 instances of class java.util.Locale 
19 instances of class java.util.concurrent.ConcurrentHashMap$HashEntry 
17 instances of class [J 
16 instances of class java.util.HashMap$Entry 
16 instances of class java.util.concurrent.ConcurrentHashMap$Segment 
16 instances of class java.util.concurrent.locks.ReentrantLock$NonfairSync 
16 instances of class [D 
16 instances of class [F 
16 instances of class [Ljava.util.HashMap$Entry; 
16 instances of class [Ljava.util.concurrent.ConcurrentHashMap$HashEntry; 
14 instances of class java.lang.Object 
14 instances of class java.util.HashMap 
14 instances of class java.util.LinkedHashMap$Entry 
12 instances of class java.io.ExpiringCache$Entry 
11 instances of class java.net.URL 
10 instances of class java.io.ObjectStreamField 
....

The output shows that the highest count is the number of java.lang.String instances. This is expected, because I created String arrays with 64*64 Strings in each array.

Last update: 2018.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 java - The Java Program Launcher

 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

 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

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB