Java Tools Tutorials - Herong's Tutorial Examples - v6.23, by Herong Yang
Printing Histogram of Java Object Heap
This section provides a tutorial example on how to print the histogram of Java object heap, a list of different types of objects and their counts and total sizes.
The first function of the "jmap" tool is to print histogram of object heap of a given JVM process. Now I am going to use a sample Java program, GarbageCollection.java, I wrote in another tutorial example in this book.
The first test is to print the heap histogram of a JVM process that runs GarbageCollection.java with the "jmap -histo pid" command:
herong> javac GarbageCollection.java herong> java GarbageCollection Free/total memory: 23725256 25034752 22710400 25034752 21618728 25034752 20523584 25034752 ... (Start another command window.) herong> jps -l -m 2288 jdk.jcmd/sun.tools.jps.Jps -l -m 10012 GarbageCollection herong> jmap -histo 10012 num #instances #bytes class name (module) -------------------------------------------------- 1: 2928 27043688 [I (java.base@10.0.1) 2: 80 19663104 [J (java.base@10.0.1) 3: 75 19399856 [D (java.base@10.0.1) 4: 302762 7266288 java.lang.String (java.base@10.0.1) 5: 3319 4951872 [B (java.base@10.0.1) 6: 74 4785312 [F (java.base@10.0.1) 7: 86 4631088 [C (java.base@10.0.1) 8: 88 1165048 [Ljava.lang.String; (java.base@10.0.1) 9: 1478 97528 [Ljava.lang.Object; (java.base@10.0.1) 10: 702 85984 java.lang.Class (java.base@10.0.1) 11: 2398 76736 java.util.HashMap$Node (java.base@10.0.1) 12: 1679 53728 java.util.concurrent.ConcurrentHashMap$N... 13: 451 45376 [Ljava.util.HashMap$Node; (java.base@10.... 14: 477 22896 java.util.HashMap (java.base@10.0.1) 15: 24 15616 [Ljava.util.concurrent.ConcurrentHashMap... 16: 554 13296 java.lang.module.ModuleDescriptor$Export... 17: 391 12512 java.lang.invoke.LambdaForm$Name (java.b... 18: 227 10896 java.lang.invoke.MemberName (java.base@1... 19: 146 9344 [Ljava.lang.ref.SoftReference; (java.bas... 20: 242 7744 java.lang.module.ModuleDescriptor$Requir... 21: 220 7040 java.lang.invoke.MethodType$ConcurrentWe... 22: 173 6920 java.lang.invoke.MethodType (java.base@1... 23: 80 6400 java.net.URI (java.base@10.0.1) 24: 265 6360 java.util.ImmutableCollections$SetN (jav... 25: 174 6144 [Ljava.lang.Class; (java.base@10.0.1) ... Total 323237 89521384
The histogram gives a very good summary of heap objects used in my GarbageCollection.java program:
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