使用例子:
-XX:CMSInitiatingOccupancyFraction=70
CMS垃圾收集器,當(dāng)老年代達(dá)到70%時(shí),觸發(fā)CMS垃圾回收琳骡。
查看CMSInitiatingOccupancyFraction的初始值為-1
intx CMSInitiatingOccupancyFraction = -1 {product}
那么-1代表著什么呢弯淘?
查看jvm源碼可知
product(intx, CMSInitiatingOccupancyFraction, -1, \
"Percentage CMS generation occupancy to start a CMS collection " \
"cycle. A negative value means that CMSTriggerRatio is used")
注釋里也說了颜武,如果CMSInitiatingOccupancyFraction是個(gè)負(fù)值您觉,那么CMSTriggerRatio將被用到
那么具體是如何用到的呢拙寡?
_cmsGen ->init_initiating_occupancy(CMSInitiatingOccupancyFraction, CMSTriggerRatio);
void ConcurrentMarkSweepGeneration::init_initiating_occupancy(intx io, uintx tr) {
assert(io <= 100 && tr <= 100, "Check the arguments");
if (io >= 0) {
_initiating_occupancy = (double)io / 100.0;
} else {
_initiating_occupancy = ((100 - MinHeapFreeRatio) +
(double)(tr * MinHeapFreeRatio) / 100.0)
/ 100.0;
}
}
如果CMSInitiatingOccupancyFraction在0~100之間,那么由CMSInitiatingOccupancyFraction決定顾犹。
否則由按 ((100 - MinHeapFreeRatio) + (double)( CMSTriggerRatio * MinHeapFreeRatio) / 100.0) / 100.0 決定倒庵。
那么MinHeapFreeRatio,CMSTriggerRatio的初始值是多少炫刷?
uintx MinHeapFreeRatio = 40 {manageable}
uintx CMSTriggerRatio = 80 {product}
即最終當(dāng)老年代達(dá)到 ((100 - 40) + (double) 80 * 40 / 100 ) / 100 = 92 %時(shí),會(huì)觸發(fā)CMS回收郁妈。