Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
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 to JDK 12.
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.
Table of Contents
javac - The Java Program Compiler
java - The Java Program Launcher
jpackage - Binary Package Builder
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
JVM Troubleshooting Tools in JDK
jinfo - VM Option Value Checker
jinfo - Changing HotSpot VM Option
jstack - Stack Tracer to Generate Thread Dump
Java Thread Deadlock Demo Program
jstack - Detecting Java Thread Deadlocks
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
Searching for Instances with OQL Statements
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
jrunscript - Script Code Shell
native2ascii - Native-to-ASCII Encoding Converter