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:
The histogram gives a very good summary of heap objects used in my GarbageCollection.java program:
Most of the objects were String objects. There were 73925 of them. This matches well with what I allocated
in the program: one array of 64*64 string objects for each 1-MB object. If 16 1-MB objects were allocated, there should
be 65536 string objects.
"[Ljava.lang.String;" is a special class name representing a java.lang.String[] array.
"[I" is a special class name representing a int[] array.