- the heap dump may crash the java process before completing
- the heap dump may hang indefinitely
- there may not be enough disk space to accomodate the dump
- the dump may be so large that analysis tools are unable to process it
One solution to this scenario is to use the jmap utility to obtain a heap dump histogram from the running process. This appears to be very lightweight, completing quickly on very large heaps and generating a very small summary analysis file that can be used for troubleshooting.
The syntax for doing this is the following, where <pid> is the process id of the java process.
jmap -histo <pid>
The output is a very nice summary showing, for each class in the heap, the class name, the number of instances, and the size in bytes, for example as follows:
num #instances #bytes class name
----------------------------------------------
1: 70052 11118624 <constMethodKlass>
2: 70052 8422160 <methodKlass>
3: 6320 8258472 <constantPoolKlass>
4: 6320 6117216 <instanceKlassKlass>
5: 116656 5732520 <symbolKlass>
6: 17467 5729824 [I
7: 5682 5050352 <constantPoolCacheKlass>
8: 57275 4818512 [C
9: 24818 2660384 [B
10: 59327 1898464 java.lang.String
11: 2847 1766720 [J
12: 2978 1542008 <methodDataKlass>
13: 11687 797256 [S
14: 13307 706440 [Ljava.lang.Object;
15: 6777 704808 java.lang.Class
16: 18904 604928 java.util.HashMap$Entry
17: 10088 522512 [[I
18: 5736 499408 [Ljava.util.HashMap$Entry;
19: 12838 410816 java.util.Hashtable$Entry
20: 5580 267840 java.util.HashMap
21: 428 249952 <objArrayKlassKlass>
22: 5888 235520 java.util.concurrent.ConcurrentHashMap$Segment
23: 6243 199776 java.util.concurrent.locks.ReentrantLock$NonfairSync
24: 5888 146544 [Ljava.util.concurrent.ConcurrentHashMap$HashEntry;
...
3029: 1 16 sun.awt.X11.XToolkit$4
3030: 1 16 java.util.Collections$EmptyIterator
3031: 1 16 com.sun.tools.visualvm.core.explorer.ExplorerContextMenuFactory
3032: 1 16 sun.reflect.generics.tree.TypeVariableSignature
3033: 1 16 sun.awt.X11.XKeyboardFocusManagerPeer$1
3034: 1 16 org.openide.xml.EntityCatalog$Forwarder
Total 714547 74730032