Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
1 2 3
$ jstat -gccause 19 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC 0.00 0.83 2.23 22.60 89.67 84.02 33919 563.393 6 0.128 563.521 Allocation Failure No GC
参数
备注
样例
LGCC
Cause of last garbage collection
Allocation Failure
GCC
Cause of current garbage collection
No GC
jmap
Prints shared object memory maps or heap memory details for a process, core file, or remote debug server.
Prints class loader wise statistics of Java heap. For each class loader, its name, how active it is, address, parent class loader, and the number and size of classes it has loaded are printed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ jmap -clstats 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 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> 2508 4508619 null live <internal> 0x000000009388bb88 1 1473 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8 0x0000000090bcccb8 1 1472 0x0000000090024a50 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8 ... total = 634 12693 20378456 N/A alive=1, dead=633 N/A
finalizerinfo
Prints information about objects that are awaiting finalization.
1 2 3 4 5 6
$ jmap -finalizerinfo 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 Number of objects pending for finalization: 0
heap
Prints a heap summary of the garbage collection used, the head configuration, and generation-wise heap usage. In addition, the number and size of interned Strings are printed.
Heap Usage: New Generation (Eden + 1 Survivor Space): capacity = 89522176 (85.375MB) used = 32297224 (30.80103302001953MB) free = 57224952 (54.57396697998047MB) 36.07734467937866% used Eden Space: capacity = 44826624 (42.75MB) used = 31529392 (30.068771362304688MB) free = 13297232 (12.681228637695312MB) 70.33630728024488% used From Space: capacity = 44695552 (42.625MB) used = 767832 (0.7322616577148438MB) free = 43927720 (41.892738342285156MB) 1.7179159125274928% used To Space: capacity = 44695552 (42.625MB) used = 0 (0.0MB) free = 44695552 (42.625MB) 0.0% used concurrent mark-sweep generation: capacity = 1879048192 (1792.0MB) used = 33776136 (32.21143341064453MB) free = 1845272056 (1759.7885665893555MB) 1.7975130251475744% used
21703 interned Strings occupying 2142592 bytes.
histo[:live]
Prints a histogram of the heap. For each Java class, the number of objects, memory size in bytes, and the fully qualified class names are printed. The JVM internal class names are printed with an asterisk (*) prefix. If the live suboption is specified, then only active objects are counted.
1 2 3 4 5 6 7 8 9
$ jmap -histo:live 19 num #instances #bytes class name ---------------------------------------------- 1: 72102 6440744 [C 2: 5996 4159456 [B 3: 19079 1783760 [Ljava.lang.Object; 4: 71213 1709112 java.lang.String ... Total 529634 28005336
dump:[live,] format=b, file=filename
Dumps the Java heap in hprof binary format to filename. The live suboption is optional, but when specified, only the active objects in the heap are dumped. 相关的JVM参数:-XX:+HeapDumpAfterFullGC,-XX:+HeapDumpOnOutOfMemoryError
1 2 3
$ jmap -dump:live,format=b,file=/tmp/cover.hprof 19 Dumping heap to /tmp/cover.hprof ... Heap dump file created
jinfo
Generates configuration information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ jinfo 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 25.131-b11 ... conf.key = lz_live_cover ... VM Flags: Non-default VM flags: -XX:CICompilerCount=2 -XX:+CMSClassUnloadingEnabled .... Command line: -Dconf.key=lz_live_cover -Dconf.env=pre
sysprops
Prints Java system properties as name-value pairs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ jinfo -sysprops 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 25.131-b11 ... java.vm.vendor = Oracle Corporation conf.key = lz_live_cover ... java.vm.name = Java HotSpot(TM) 64-Bit Server VM sun.java.launcher = SUN_STANDARD ...
flags
1 2 3 4 5 6 7 8 9
$ jinfo -flags 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.131-b11 Non-default VM flags: -XX:CICompilerCount=2 -XX:+CMSClassUnloadingEnabled ... Command line: -Dconf.key=lz_live_cover -Dconf.env=pre ...
$ jstack 19120 2019-01-10 09:53:21 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):
...
"t3" #12 prio=5 os_prio=31 tid=0x00007faa948b4800 nid=0xf07 waiting for monitor entry [0x00007000043c8000] java.lang.Thread.State: BLOCKED (on object monitor) at me.zhongmingmao.advanced.command.SyncThread.run(ThreadDeadlock.java:39) - waiting to lock <0x0000000795700530> (a java.lang.Object) - locked <0x0000000795700550> (a java.lang.Object) at java.lang.Thread.run(Thread.java:748)
"t2" #11 prio=5 os_prio=31 tid=0x00007faa948b4000 nid=0x3c03 waiting for monitor entry [0x0000700005581000] java.lang.Thread.State: BLOCKED (on object monitor) at me.zhongmingmao.advanced.command.SyncThread.run(ThreadDeadlock.java:39) - waiting to lock <0x0000000795700550> (a java.lang.Object) - locked <0x0000000795700540> (a java.lang.Object) at java.lang.Thread.run(Thread.java:748)
"t1" #10 prio=5 os_prio=31 tid=0x00007faa948b3000 nid=0x4203 waiting for monitor entry [0x000070000547e000] java.lang.Thread.State: BLOCKED (on object monitor) at me.zhongmingmao.advanced.command.SyncThread.run(ThreadDeadlock.java:39) - waiting to lock <0x0000000795700540> (a java.lang.Object) - locked <0x0000000795700530> (a java.lang.Object) at java.lang.Thread.run(Thread.java:748)
...
Found one Java-level deadlock: ============================= "t3": waiting to lock monitor 0x00007faa94811b58 (object 0x0000000795700530, a java.lang.Object), which is held by "t1" "t1": waiting to lock monitor 0x00007faa9480da08 (object 0x0000000795700540, a java.lang.Object), which is held by "t2" "t2": waiting to lock monitor 0x00007faa94811aa8 (object 0x0000000795700550, a java.lang.Object), which is held by "t3"
...
Found 1 deadlock.
jcmd
Sends diagnostic command requests to a running Java Virtual Machine (JVM). jcmd可以替代上面除了jstat之外的所有命令,并没有保留jstat的输出格式
$ jcmd 3721 Thread.print Found one Java-level deadlock: ============================= "t3": waiting to lock monitor 0x00007fd53105ff58 (object 0x0000000795700530, a java.lang.Object), which is held by "t1" "t1": waiting to lock monitor 0x00007fd53105be08 (object 0x0000000795700540, a java.lang.Object), which is held by "t2" "t2": waiting to lock monitor 0x00007fd53105fea8 (object 0x0000000795700550, a java.lang.Object), which is held by "t3"
JFR
1 2 3 4 5 6 7 8 9 10 11 12 13
$ jcmd 3721 JFR.check 3721: Java Flight Recorder not enabled. Use VM.unlock_commercial_features to enable.
$ jcmd 3721 VM.unlock_commercial_features 3721: Commercial Features now unlocked.
$ jcmd 3721 JFR.check 3721: No available recordings. Use JFR.start to start a recording.
1 2 3 4 5 6 7 8
$ jcmd 3721 JFR.start name=abc,duration=120s 3721: Started recording 1. No limit (duration/maxsize/maxage) in use. Use JFR.dump name=abc,duration=120s filename=FILEPATH to copy recording data to file.