-XX:+PrintTenuringDistribution 贈送銀彈: -XX:SurvivorRatio
????作用:輸出顯示在survivor空間里面有效的對象的歲數(shù)情況。
{Heap before GC invocations=0 (full 0):
par new generation total 1887488K, used 1677824K [0x00000006e0c00000, 0x0000000760c00000, 0x0000000760c00000)
eden space 1677824K, 100% used [0x00000006e0c00000, 0x0000000747280000, 0x0000000747280000)
from space 209664K, 0% used [0x0000000747280000, 0x0000000747280000, 0x0000000753f40000)
to space 209664K, 0% used [0x0000000753f40000, 0x0000000753f40000, 0x0000000760c00000)
concurrent mark-sweep generation total 2097152K, used 0K [0x0000000760c00000, 0x00000007e0c00000, 0x00000007e0c00000)
concurrent-mark-sweep perm gen total 512000K, used 22205K [0x00000007e0c00000, 0x0000000800000000, 0x0000000800000000)
2018-02-06T13:29:54.526+0800: 6.958: [GC2018-02-06T13:29:54.526+0800: 6.958: [ParNew2018-02-06T13:29:54.584+0800: 7.016: [SoftReference, 0 refs, 0.0000450 secs]2018-02-06T13:29:54.584+0800: 7.016: [WeakReference, 1074 refs, 0.0001630 secs]2018-02-06T13:29:54.584+0800: 7.017: [FinalReference, 67745 refs, 0.1348760 secs]2018-02-06T13:29:54.719+0800: 7.152: [PhantomReference, 0 refs, 0.0000180 secs]2018-02-06T13:29:54.719+0800: 7.152: [JNI Weak Reference, 0.0000090 secs]
Desired survivor size 107347968 bytes, new threshold 1 (max 30)
- age 1: 157548032 bytes, 157548032 total
: 1677824K->154017K(1887488K), 0.1942010 secs] 1677824K->154017K(3984640K), 0.1942870 secs] [Times: user=0.20 sys=0.08, real=0.19 secs]
Heap after GC invocations=1 (full 0):
par new generation total 1887488K, used 154017K [0x00000006e0c00000, 0x0000000760c00000, 0x0000000760c00000)
eden space 1677824K, 0% used [0x00000006e0c00000, 0x00000006e0c00000, 0x0000000747280000)
from space 209664K, 73% used [0x0000000753f40000, 0x000000075d5a8560, 0x0000000760c00000)
to space 209664K, 0% used [0x0000000747280000, 0x0000000747280000, 0x0000000753f40000)
concurrent mark-sweep generation total 2097152K, used 0K [0x0000000760c00000, 0x00000007e0c00000, 0x00000007e0c00000)
concurrent-mark-sweep perm gen total 512000K, used 22205K [0x00000007e0c00000, 0x0000000800000000, 0x0000000800000000)
}
其中-XX:+PrintTenuringDistribution只是豐富了gclog部分如下:
Desired survivor size 107347968 bytes, new threshold 1 (max 30)
- age 1: 157548032 bytes, 157548032 total
: 1677824K->154017K(1887488K), 0.1942010 secs] 1677824K->154017K(3984640K), 0.1942870 secs] [Times: user=0.20 sys=0.08, real=0.19 secs]
描述信息:
????Survivor對象年齡棋凳,最大值設(shè)置的是30拦坠,實際計算后的閥值是1。
????Survivor大小剩岳,Desired survivor size指的是整個Survivor的1/2 107347968byte也就是 from or to 的大小贞滨,所以例子中的Survivor大小是204mb 對象閥值是1,從這個例子中可以看出進(jìn)入survivor的對象比survivor預(yù)留空間大拍棕,所以會有對象到老年代中晓铆。這時最好要調(diào)整-XX:SurvivorRatio來設(shè)置合理的Survivor
????Survivor中存活對象157mb,切年齡是1莫湘。
贈送銀彈
????額外贈送-XX:SurvivorRatio=8 含義:eden/suvivor=8 ,其中survivor包含from尤蒿、to。
eg:yong區(qū)設(shè)定2g幅垮,-XX:NewSize=2g 腰池,那么,from = 2g/(8+2) ,也就是說yong區(qū)會被分成10分,eden區(qū)占8分,survivor占2份示弓,這也能看出比值越大survivor被稀釋的越嚴(yán)重讳侨。比值越小survivor分到的空間更大。
????以上面log為例奏属,計算出合理的-XX:SurvivorRatio 跨跨,可以確定survivor為160mb*2為合理區(qū)域,所以假設(shè)比值為x,eden=320x囱皿,yong區(qū)總共 2g=320x+320勇婴,所以比值x=(2g-320)/320 ,x近似=5。
繼續(xù)分析log中的age
截取運(yùn)行過一段時間的日志分析下:
{Heap before GC invocations=11 (full 0):
par new generation total 1887488K, used 1716581K [0x00000006e0c00000, 0x0000000760c00000, 0x0000000760c00000)
eden space 1677824K, 100% used [0x00000006e0c00000, 0x0000000747280000, 0x0000000747280000)
from space 209664K, 18% used [0x0000000753f40000, 0x00000007565196a8, 0x0000000760c00000)
to space 209664K, 0% used [0x0000000747280000, 0x0000000747280000, 0x0000000753f40000)
concurrent mark-sweep generation total 2097152K, used 23205K [0x0000000760c00000, 0x00000007e0c00000, 0x00000007e0c00000)
concurrent-mark-sweep perm gen total 512000K, used 49938K [0x00000007e0c00000, 0x0000000800000000, 0x0000000800000000)
2018-02-06T14:21:29.610+0800: 3102.042: [GC2018-02-06T14:21:29.610+0800: 3102.042: [ParNew2018-02-06T14:21:29.639+0800: 3102.072: [SoftReference, 0 refs, 0.0000400 secs]2018-02-06T14:21:29.639+0800: 3102.072: [WeakReference, 9421 refs, 0.0005540 secs]2018-02-06T14:21:29.640+0800: 3102.072: [FinalReference, 4196 refs, 0.0044150 secs]2018-02-06T14:21:29.644+0800: 3102.077: [PhantomReference, 4 refs, 0.0000080 secs]2018-02-06T14:21:29.644+0800: 3102.077: [JNI Weak Reference, 0.0000090 secs]
Desired survivor size 107347968 bytes, new threshold 16 (max 30)
- age 1: 4345400 bytes, 4345400 total
- age 2: 2436856 bytes, 6782256 total
- age 3: 676112 bytes, 7458368 total
- age 4: 2323952 bytes, 9782320 total
- age 5: 599616 bytes, 10381936 total
- age 6: 563656 bytes, 10945592 total
- age 7: 567656 bytes, 11513248 total
- age 8: 815480 bytes, 12328728 total
- age 9: 527672 bytes, 12856400 total
- age 10: 3956032 bytes, 16812432 total
- age 11: 16575184 bytes, 33387616 total
: 1716581K->49462K(1887488K), 0.0345690 secs] 1739786K->72667K(3984640K), 0.0349280 secs] [Times: user=0.12 sys=0.00, real=0.04 secs]
Heap after GC invocations=12 (full 0):
par new generation total 1887488K, used 49462K [0x00000006e0c00000, 0x0000000760c00000, 0x0000000760c00000)
eden space 1677824K, 0% used [0x00000006e0c00000, 0x00000006e0c00000, 0x0000000747280000)
from space 209664K, 23% used [0x0000000747280000, 0x000000074a2cd8a0, 0x0000000753f40000)
to space 209664K, 0% used [0x0000000753f40000, 0x0000000753f40000, 0x0000000760c00000)
concurrent mark-sweep generation total 2097152K, used 23205K [0x0000000760c00000, 0x00000007e0c00000, 0x00000007e0c00000)
concurrent-mark-sweep perm gen total 512000K, used 49938K [0x00000007e0c00000, 0x0000000800000000, 0x0000000800000000)
}
格式:- age 年齡: 處于當(dāng)前年齡段的對象大小 總大小(各個年齡段是累計的)
總結(jié)6:
????-XX:+PrintTenuringDistribution這個參數(shù)對于設(shè)置-XX:MaxTenuringThreshold有很大幫助嘱腥,閥值需要長時間觀察對象分布耕渴,設(shè)置合理即可。
????-XX:MaxTenuringThreshold設(shè)置過大問題:原本應(yīng)該晉升對象到survivor區(qū),直到survivor區(qū)溢出齿兔,一旦溢出發(fā)生橱脸,Eden+Svuvivor中對象將不再依據(jù)年齡全部提升到老年代,這樣對象老化的機(jī)制就失效了
????-XX:MaxTenuringThreshold設(shè)置過蟹治:eden區(qū)的對象會陸續(xù)送入old區(qū)添诉,對象移動本身就是開銷,cms老年代回收還會造成碎片化医寿。