詳解如下參數(shù):
-XX:+PrintHeapAtGC
-verbose:gc
-XX:+PrintTenuringDistribution
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+PrintReferenceGC
-XX:+PrintGCTimeStamps
-XX:+PrintGC
-XX:+PrintGCApplicationStoppedTime
1、-XX:+PrintHeapAtGC
作用:每次gc(yonggc,fullgc) 都會(huì)輸出gc前后堆詳情(Eden區(qū)域、from區(qū)、to區(qū)、old區(qū)、Metaspace區(qū) 、Class space等) 個(gè)人認(rèn)為這個(gè)輸出的gclog是目前最細(xì)的力度(極力推薦查找gc問題配置上這個(gè)參數(shù))。
ParallelGC中l(wèi)og:
{Heap before GC invocations=5 (full 0):
PSYoungGen total 45056K, used 38644K [0x00000007bce00000, 0x00000007c0000000, 0x00000007c0000000)
eden space 38912K, 99% used [0x00000007bce00000,0x00000007bf3bd328,0x00000007bf400000)
from space 6144K, 0% used [0x00000007bfa00000,0x00000007bfa00000,0x00000007c0000000)
to space 6144K, 0% used [0x00000007bf400000,0x00000007bf400000,0x00000007bfa00000)
ParOldGen total 153600K, used 1509K [0x00000007b3800000, 0x00000007bce00000, 0x00000007bce00000)
object space 153600K, 0% used [0x00000007b3800000,0x00000007b39797c8,0x00000007bce00000)
Metaspace used 3290K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 362K, capacity 388K, committed 512K, reserved 1048576K
2018-08-03T17:50:29.631-0800: [GC (Allocation Failure)
Desired survivor size 3670016 bytes, new threshold 2 (max 3)
[PSYoungGen: 38644K->3072K(45056K)] 40154K->4581K(198656K), 0.0037607 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
Heap after GC invocations=5 (full 0):
PSYoungGen total 45056K, used 3072K [0x00000007bce00000, 0x00000007c0000000, 0x00000007c0000000)
eden space 38912K, 0% used [0x00000007bce00000,0x00000007bce00000,0x00000007bf400000)
from space 6144K, 50% used [0x00000007bf400000,0x00000007bf700030,0x00000007bfa00000)
to space 3584K, 0% used [0x00000007bfc80000,0x00000007bfc80000,0x00000007c0000000)
ParOldGen total 153600K, used 1509K [0x00000007b3800000, 0x00000007bce00000, 0x00000007bce00000)
object space 153600K, 0% used [0x00000007b3800000,0x00000007b39797c8,0x00000007bce00000)
Metaspace used 3290K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 362K, capacity 388K, committed 512K, reserved 1048576K
}
CMS中 log:
{Heap before GC invocations=1 (full 0):
par new generation total 46080K, used 42256K [0x00000007b3800000, 0x00000007b6a00000, 0x00000007b6a00000)
eden space 40960K, 99% used [0x00000007b3800000, 0x00000007b5fc6ae0, 0x00000007b6000000)
from space 5120K, 29% used [0x00000007b6500000, 0x00000007b667d750, 0x00000007b6a00000)
to space 5120K, 0% used [0x00000007b6000000, 0x00000007b6000000, 0x00000007b6500000)
concurrent mark-sweep generation total 153600K, used 0K [0x00000007b6a00000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 3288K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 362K, capacity 388K, committed 512K, reserved 1048576K
2018-08-03T17:40:09.703-0800: [GC (Allocation Failure) 2018-08-03T17:40:09.703-0800: [ParNew
Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age 2: 1492936 bytes, 1492936 total
: 42256K->1686K(46080K), 0.0013712 secs] 42256K->1686K(199680K), 0.0014078 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap after GC invocations=2 (full 0):
par new generation total 46080K, used 1686K [0x00000007b3800000, 0x00000007b6a00000, 0x00000007b6a00000)
eden space 40960K, 0% used [0x00000007b3800000, 0x00000007b3800000, 0x00000007b6000000)
from space 5120K, 32% used [0x00000007b6000000, 0x00000007b61a5b18, 0x00000007b6500000)
to space 5120K, 0% used [0x00000007b6500000, 0x00000007b6500000, 0x00000007b6a00000)
concurrent mark-sweep generation total 153600K, used 0K [0x00000007b6a00000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 3288K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 362K, capacity 388K, committed 512K, reserved 1048576K
}
2、-verbose:gc
作用:每次gc(yonggc,fullgc) 輸出前后結(jié)果信息
** CMS&ParallelGC中l(wèi)og:**
[GC (Allocation Failure) 37929K->1720K(198656K), 0.0015626 secs]
[GC (Allocation Failure) 40362K->1576K(198656K), 0.0018508 secs]
3、-XX:+PrintTenuringDistribution
作用:每次新生代 young GC時(shí),輸出幸存區(qū)中對(duì)象的年齡分布
ParallelGC中l(wèi)og:
Desired survivor size 6291456 bytes, new threshold 3 (max 3)
Desired survivor size 6291456 bytes, new threshold 3 (max 3)
Desired survivor size 6291456 bytes, new threshold 3 (max 3)
CMS中l(wèi)og:
Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age 1: 1528520 bytes, 1528520 total
Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age 2: 1493000 bytes, 1493000 total
4、-XX:+PrintGCDateStamps
作用:輸出GC的時(shí)間戳(以日期的形式,如 2019-11-30T17:54:12.986-0800)
ParallelGC中l(wèi)og:
無
CMS中l(wèi)og:
{Heap before GC invocations=0 (full 0):
par new generation total 9216K, used 8191K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 99% used [0x00000007bce00000, 0x00000007bd5ffc38, 0x00000007bd600000)
from space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
to space 1024K, 0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
2019-11-30T17:54:12.986-0800: 0.126: [GC (Allocation Failure) 2019-11-30T17:54:12.986-0800: 0.126: [ParNew2019-11-30T17:54:12.995-0800: 0.134: [SoftReference, 0 refs, 0.0000312 secs]2019-11-30T17:54:12.995-0800: 0.134: [WeakReference, 10 refs, 0.0000163 secs]2019-11-30T17:54:12.995-0800: 0.134: [FinalReference, 0 refs, 0.0000166 secs]2019-11-30T17:54:12.995-0800: 0.134: [PhantomReference, 0 refs, 0 refs, 0.0000149 secs]2019-11-30T17:54:12.995-0800: 0.134: [JNI Weak Reference, 0.0000138 secs]: 8191K->1024K(9216K), 0.0083958 secs] 8191K->7628K(50176K), 0.0084375 secs] [Times: user=0.01 sys=0.01, real=0.01 secs]
Heap after GC invocations=1 (full 0):
par new generation total 9216K, used 1024K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
from space 1024K, 100% used [0x00000007bd700000, 0x00000007bd800000, 0x00000007bd800000)
to space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
concurrent mark-sweep generation total 40960K, used 6604K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
}
5、-XX:+PrintGCDetails
作用:輸出GC的詳細(xì)日志,相比-XX:+PrintHeapAtGC力度粗了很多,重點(diǎn)放在了回收??耗時(shí)上級(jí),只分YongGeneration與OldGeneration。
ParallelGC中l(wèi)og:
[GC (Allocation Failure) [PSYoungGen: 37929K->1616K(45056K)] 37929K->1624K(198656K), 0.0022814 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 40258K->1664K(45056K)] 40266K->1672K(198656K), 0.0019262 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 40062K->1584K(45056K)] 40070K->1592K(198656K), 0.0010587 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 40225K->0K(45056K)] 40233K->1501K(198656K), 0.0018711 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
CMS中l(wèi)og:
[GC (Allocation Failure) [ParNew: 40141K->1529K(46080K), 0.0016821 secs] 40141K->1529K(199680K), 0.0017271 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 42260K->1618K(46080K), 0.0015961 secs] 42260K->1618K(199680K), 0.0016258 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 42145K->1637K(46080K), 0.0013662 secs] 42145K->1637K(199680K), 0.0014078 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 42366K->0K(46080K), 0.0049625 secs] 42366K->1502K(199680K), 0.0049983 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
6、 -XX:+PrintReferenceGC
作用:輸出GC回收的四種應(yīng)用類型詳情。
{Heap before GC invocations=0 (full 0):
par new generation total 9216K, used 8189K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 99% used [0x00000007bce00000, 0x00000007bd5ff4b8, 0x00000007bd600000)
from space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
to space 1024K, 0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
0.106: [GC (Allocation Failure) 0.106: [ParNew0.113: [SoftReference, 0 refs, 0.0000162 secs]0.113: [WeakReference, 10 refs, 0.0000077 secs]0.113: [FinalReference, 0 refs, 0.0000057 secs]0.113: [PhantomReference, 0 refs, 0 refs, 0.0000076 secs]0.113: [JNI Weak Reference, 0.0000074 secs]: 8189K->1024K(9216K), 0.0074205 secs] 8189K->7621K(50176K), 0.0074596 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]
Heap after GC invocations=1 (full 0):
par new generation total 9216K, used 1024K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
from space 1024K, 100% used [0x00000007bd700000, 0x00000007bd800000, 0x00000007bd800000)
to space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
concurrent mark-sweep generation total 40960K, used 6597K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
}
CMS-YongGC-log中截取 -XX:+PrintReferenceGC 作用:
[GC (Allocation Failure)
0.106: [ParNew
0.113:[SoftReference, 0 refs, 0.0000162 secs]
0.113:[WeakReference, 10 refs, 0.0000077 secs]
0.113:[FinalReference, 0 refs, 0.0000057 secs]
0.113:[PhantomReference, 0 refs, 0 refs, 0.0000076 secs]
0.113:[JNI Weak Reference, 0.0000074 secs]
:8189K->1024K(9216K), 0.0074205 secs]
8189K->7621K(50176K), 0.0074596 secs]
[Times: user=0.01 sys=0.01, real=0.00 secs]
將以此回收??中涉及到的四種引用信息詳情輸出到log中。(如上log中WeakReference清理了10個(gè)引用)
7、-XX:+PrintGCTimeStamps
作用:輸出GC的時(shí)間戳(以基準(zhǔn)時(shí)間的形式)。

不仔細(xì)對(duì)比真的無法發(fā)現(xiàn)加了這個(gè)參數(shù)gclog有什么變化。
8、-XX:+PrintGC
CMS中l(wèi)og:
7.774: [GC (Allocation Failure) 32768K->17253K(200704K), 0.0833318 secs]
23.877: [GC (Allocation Failure) 50021K->52439K(200704K), 0.0543904 secs]
40.501: [GC (Allocation Failure) 85207K->84427K(200704K), 0.0473820 secs]
56.633: [GC (Allocation Failure) 117195K->116277K(200704K), 0.0425909 secs]
73.247: [GC (Allocation Failure) 149045K->148270K(200704K), 0.0435195 secs]
73.291: [GC (CMS Initial Mark) 148386K(200704K), 0.0011136 secs]
73.396: [GC (CMS Final Remark) 148767K(200704K), 0.0028249 secs]
75.464: [GC (CMS Initial Mark) 153371K(200704K), 0.0033355 secs]
80.679: [GC (CMS Final Remark) 163165K(200704K), 0.0045811 secs]
82.747: [GC (CMS Initial Mark) 167081K(200704K), 0.0065648 secs]
82.858: [GC (CMS Final Remark) 168061K(200704K), 0.0061034 secs]
84.933: [GC (CMS Initial Mark) 171915K(200704K), 0.0108552 secs]
85.047: [GC (CMS Final Remark) 171915K(200704K), 0.0085279 secs]
87.120: [GC (CMS Initial Mark) 175833K(200704K), 0.0084935 secs]
8、-XX:+PrintGCApplicationStoppedTime
作用:打印GC造成應(yīng)用暫停的時(shí)間。 tips:web頁(yè)面有卡頓可以參考這個(gè)值來進(jìn)行排查問題。
{Heap before GC invocations=0 (full 0):
par new generation total 9216K, used 8191K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 99% used [0x00000007bce00000, 0x00000007bd5ffc38, 0x00000007bd600000)
from space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
to space 1024K, 0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
2019-11-30T18:23:40.613-0800: [GC (Allocation Failure) 2019-11-30T18:23:40.613-0800: [ParNew: 8191K->1023K(9216K), 0.0076207 secs] 8191K->7626K(50176K), 0.0076643 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Heap after GC invocations=1 (full 0):
par new generation total 9216K, used 1023K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K, 0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
from space 1024K, 99% used [0x00000007bd700000, 0x00000007bd7ffff8, 0x00000007bd800000)
to space 1024K, 0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
concurrent mark-sweep generation total 40960K, used 6602K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K
}
2019-11-30T18:23:40.620-0800: Total time for which application threads were stopped: 0.0078554 seconds, Stopping threads took: 0.0000152 seconds
2019-11-30T18:23:44.632-0800: Total time for which application threads were stopped: 0.0001055 seconds, Stopping threads took: 0.0000237 seconds
如上log中最后兩行就是jvm回收??造成的應(yīng)用服務(wù)器停頓時(shí)間!
看看你需要那種?
是的組合在一起??,才是真愛~
我一般這么組合:
-XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime
-XX:+PrintReferenceGC -XX:+PrintTenuringDistribution
-Xloggc:/export/Logs/xxxxxxx/tomcat7-cms-gc.log