详细用法可以oracle官方查看(https://docs.oracle.com/javase/8/docs/technotes/tools/index.html)

GC情况是否正常排查

通过top查看任务的负载.抓到负载高的pid

jstat -gcutil pid 时间 打印多少次

(base) [root@rhel076 ~]# jstat -gcutil 3008 2000 100
Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN
Warning: Unresolved Symbol: sun.gc.generation.2.space.0.used substituted NaN
Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN
S0 S1 E O P YGC YGCT FGC FGCT GCT     
82.87 0.00 44.24 45.10 ? 3500 461.005 270 24.911 485.916
82.87 0.00 45.59 45.10 ? 3500 461.005 270 24.911 485.916
0.00 100.00 0.00 50.03 ? 3501 461.243 270 24.911 486.154
100.00 0.00 4.37 52.55 ? 3502 461.366 270 24.911 486.277
0.00 100.00 8.29 55.90 ? 3503 461.490 270 24.911 486.401
0.00 100.00 65.75 55.90 ? 3503 461.490 270 24.911 486.401
99.75 0.00 3.86 62.90 ? 3504 461.797 270 24.911 486.708
99.75 0.00 46.60 62.90 ? 3504 461.797 270 24.911 486.708
99.75 0.00 90.63 62.90 ? 3504 461.797 270 24.911 486.708

 

watch jstat -gcutil 3008

观察JVM的变化

 

./jmap -heap 3008  目标PIDJVM各个代的内存分配情况,I.7JDK版本貌似不支持。1.8下执行成功

(base) [root@rhel076 bin]# ./jmap -heap 3008
Attaching to process ID 3008, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.31-b07

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 17179869184 (16384.0MB)
NewSize = 1570308096 (1497.5625MB)
MaxNewSize = 1570308096 (1497.5625MB)
OldSize = 15609561088 (14886.4375MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 1413283840 (1347.8125MB)
used = 869234880 (828.9669799804688MB)
free = 544048960 (518.8455200195312MB)
61.504621746754% used
Eden Space:
capacity = 1256259584 (1198.0625MB)
used = 714894320 (681.7763519287109MB)
free = 541365264 (516.2861480712891MB)
56.906576403878006% used
From Space:
capacity = 157024256 (149.75MB)
used = 154340560 (147.1906280517578MB)
free = 2683696 (2.5593719482421875MB)
98.29090354040588% used
To Space:
capacity = 157024256 (149.75MB)
used = 0 (0.0MB)
free = 157024256 (149.75MB)
0.0% used
concurrent mark-sweep generation:
capacity = 15609561088 (14886.4375MB)
used = 6770147272609334384 (6.456515572175345E12MB)
free = 11135670487127 MB
4.337179780034911E10% used

35315 interned Strings occupying 4338848 bytes.

jinfo -flags [ 可选参数 eg:MaxHeapSize] PID