Java Tools & Commands Java
jmap is Java standard command-line utility which comes with JDK (starting from JDK 1.6).
jmap prints memory-related statistics for a running VM or core file.
c:>jmap -help Usage: jmap -clstats <pid> to connect to running process and print class loader statistics jmap -finalizerinfo <pid> to connect to running process and print information on objects awaiting finalization jmap -histo[:[<histo-options>]] <pid> to connect to running process and print histogram of java object heap jmap -dump:<dump-options> <pid> to connect to running process and dump java heap jmap -? -h --help to print this help message
dump-options: live dump only live objects (takes precedence if both "live" and "all" are specified) all dump all objects in the heap (default if one of "live" or "all" is not specified) format=b binary format file=<file> dump heap to <file> gz=<number> If specified, the heap dump is written in gzipped format using the given compression level. 1 (recommended) is the fastest, 9 the strongest compression.
Example: jmap -dump:live,format=b,file=heap.bin <pid>
histo-options: live count only live objects (takes precedence if both "live" and "all" are specified) all count all objects in the heap (default if one of "live" or "all" is not specified) file=<file> dump data to <file> parallel=<number> Number of parallel threads to use for heap inspection: 0 (the default) means let the VM determine the number of threads to use 1 means use one thread (disable parallelism). For any other value the VM will try to use the specified number of threads, but might use fewer.
Example: jmap -histo:live,file=/tmp/histo.data <pid>
c:>java -version java version "17.0.4.1" 2022-08-18 LTS Java(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2) Java HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)
Note: Use jps to find PID of the process first. I prefer to use jps -m
Examples:
C:>jmap -heap 12556 Attaching to process ID 12556, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.65-b01
using thread-local object allocation. Parallel GC with 8 thread(s)
Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 4273995776 (4076.0MB) NewSize = 89128960 (85.0MB) MaxNewSize = 1424490496 (1358.5MB) OldSize = 179306496 (171.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB)
Heap Usage: PS Young Generation Eden Space: capacity = 134217728 (128.0MB) used = 55828240 (53.24195861816406MB) free = 78389488 (74.75804138183594MB) 41.595280170440674% used From Space: capacity = 11010048 (10.5MB) used = 10981040 (10.472335815429688MB) free = 29008 (0.0276641845703125MB) 99.73653157552083% used To Space: capacity = 11010048 (10.5MB) used = 0 (0.0MB) free = 11010048 (10.5MB) 0.0% used PS Old Generation capacity = 179306496 (171.0MB) used = 58267192 (55.56792449951172MB) free = 121039304 (115.43207550048828MB) 32.49586228041621% used
6709 interned Strings occupying 472728 bytes.
C:>jmap -histo 12556
num #instances #bytes class name ---------------------------------------------- 1: 9126 51035440 [C 2: 1441598 34598352 com.inet.jortho.DictionaryFactory$Node 3: 1052560 26171432 [Ljava.lang.Object; 4: 7836 11406744 [I 5: 503 254400 [B 6: 2205 252360 java.lang.Class 7: 8935 214440 java.lang.String 8: 2956 118240 java.security.AccessControlContext 9: 3606 115392 java.util.HashMap$Node 10: 2011 64352 java.util.ArrayList$Itr 11: 505 44440 java.lang.reflect.Method 12: 1208 38656 java.util.Hashtable$Entry 13: 453 32616 java.lang.reflect.Field 14: 155 32160 [Ljava.util.HashMap$Node; 15: 856 27392 java.lang.ref.WeakReference 16: 839 26848 java.util.concurrent.ConcurrentHashMap$Node 17: 118 25488 sun.java2d.SunGraphics2D 18: 892 21408 sun.awt.EventQueueItem 19: 260 20800 java.awt.event.MouseEvent 20: 693 18208 [Ljava.lang.Class; 21: 597 14328 java.awt.Point 22: 35 13384 [Ljava.util.Hashtable$Entry; 23: 417 13344 java.awt.Rectangle 24: 824 13184 java.lang.Integer 25: 233 13048 java.lang.invoke.MemberName 26: 323 12920 java.lang.ref.SoftReference 27: 183 11712 java.awt.event.InvocationEvent 28: 465 11160 java.awt.EventQueue$3 29: 153 11016 java.awt.geom.AffineTransform 30: 326 10432 java.util.concurrent.locks.AbstractQueuedSynchronizer$Node 31: 624 9984 java.lang.Object 32: 208 9888 [Ljava.lang.String; 33: 199 9552 sun.java2d.loops.Blit 34: 149 9536 java.net.URL 35: 198 9504 java.util.HashMap 36: 20 9440 javax.swing.JMenuItem 37: 36 8800 [Ljava.util.concurrent.ConcurrentHashMap$Node; 38: 163 7824 sun.java2d.loops.ScaledBlit 39: 226 7232 java.lang.invoke.LambdaForm$Name 40: 88 7040 java.lang.reflect.Constructor 41: 123 6888 java.lang.Class$ReflectionData 42: 280 6720 java.awt.EventQueue$4 43: 258 6192 java.lang.Long 44: 190 6080 java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry 45: 16 6016 java.lang.Thread 46: 245 5880 java.util.LinkedList$Node 47: 147 5880 sun.java2d.pipe.Region 48: 143 5720 java.lang.invoke.MethodType 49: 94 5640 [Ljava.lang.ref.SoftReference; 50: 19 4648 [F 51: 137 4384 java.util.LinkedList 52: 56 4240 [Ljava.util.WeakHashMap$Entry; 53: 88 4224 sun.java2d.loops.MaskBlit 54: 256 4096 java.lang.Byte 55: 256 4096 java.lang.Short 56: 53 4056 [S 57: 71 3976 java.util.zip.ZipFile$ZipFileInputStream 58: 8 3904 javax.swing.plaf.metal.MetalScrollButton 59: 94 3760 java.util.LinkedHashMap$Entry 60: 92 3680 java.lang.ref.Finalizer 61: 114 3648 java.awt.event.ComponentEvent 62: 76 3648 java.lang.invoke.LambdaForm 63: 57 3648 java.util.concurrent.ConcurrentHashMap 64: 81 3600 [Ljava.lang.invoke.LambdaForm$Name; 65: 60 3360 java.util.zip.ZipFile$ZipFileInflaterInputStream ........................................................
C:>jmap -clstats 12556 Attaching to process ID 12556, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.65-b01 finding class loader instances ..done. computing per loader stat ..done. please wait.. computing liveness...liveness analysis may be inaccurate ... class_loader classes bytes parent_loader alive? type
<bootstrap> 1850 3548677 null live <internal> 0x0000000773c02620 192 565248 0x0000000773c02680 live sun/misc/Launcher$AppClassLoader@0x00000007c000f688 0x0000000773c02680 0 0 null live sun/misc/Launcher$ExtClassLoader@0x00000007c000fa30 0x0000000774143280 1 889 0x0000000774142898 dead sun/reflect/DelegatingClassLoader@0x00000007c0009df8 0x00000006c1400068 0 0 0x0000000773c02620 dead java/util/ResourceBundle$RBClassLoader@0x00000007c006c018 0x0000000774142898 12 37194 0x0000000773c02620 dead sun/reflect/misc/MethodUtil@0x00000007c00d3918 0x00000007741431b8 1 878 null dead sun/reflect/DelegatingClassLoader@0x00000007c0009df8 0x0000000774143348 1 1471 null dead sun/reflect/DelegatingClassLoader@0x00000007c0009df8
total = 8 2057 4154357 N/A alive=3, dead=5 N/A
|