CMSInitiatingOccupancyFraction=N

触发CMS老年代占比阈值,比如:

1-XX:CMSInitiatingOccupancyFraction=80

表示当老年代的空间占比达到80%时触发CMS收集器。这个参数的默认值:

1intx CMSInitiatingOccupancyFraction    = -1               {product}

当CMSInitiatingOccupancyFraction > 0,直接取设定的值。 当 CMSInitiatingOccupancyFraction < 0时,它的默认值是由下面的计算公式得到的:

1CMSInitiatingOccupancyFraction = (100 - MinHeapFreeRatio) + (CMSTriggerRatio * MinHeapFreeRatio / 100)

而MinHeapFreeRatio和CMSTriggerRatio的默认值:

1uintx MinHeapFreeRatio                = 0                  {manageable}
2uintx CMSTriggerRatio                 = 80                 {product}

从而计算得到CMSInitiatingOccupancyFraction = 100

UseCMSInitiatingOccupancyOnly

这个参数的默认值是false,也就是不开启。

开启

1-XX:+UseCMSInitiatingOccupancyOnly

关闭

1-XX:-UseCMSInitiatingOccupancyOnly

默认情况下老年代触发CMS的空间占比阈值,第一次取的是CMSInitiatingOccupancyFraction设定的值,后续由JVM根据历史运行数据自动调整。如果UseCMSInitiatingOccupancyOnly设置为true,那么导致触发CMS的老年代空间占比阈值就一直固定取自CMSInitiatingOccupancyFraction参数设置的值。

UseCMSCompactAtFullCollection

默认值是true,执行Full GC时对老年代进行压缩。与CMSFullGCsBeforeCompaction搭配使用。

开启

1-XX:+UseCMSCompactAtFullCollection

关闭

1-XX:-UseCMSCompactAtFullCollection

CMSFullGCsBeforeCompaction

默认值是0。含义是"Number of CMS full collection done before compaction if > 0"(CMS扛不住了,进而执行Full GC,当执行了CMSFullGCsBeforeCompaction设定的次数Full GC之后,才进行老年代空间压缩)

用法:

1-XX:CMSFullGCsBeforeCompaction=0
1*should_compact =
2    UseCMSCompactAtFullCollection &&
3    ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) ||
4     GCCause::is_user_requested_gc(gch->gc_cause()) ||
5     gch->incremental_collection_will_fail(true /* consult_young */));

CMX老年代如果Full GC时压缩需要满足以下条件之一:

  • UseCMSCompactAtFullCollection == true,自上一次CMS后执行了的Full GC次数 >= CMSFullGCsBeforeCompaction
  • 程序代码中调用了System.gc()
  • young gen报告接下来如果做增量收集会失败;简单来说也就是young gen预计old gen没有足够空间来容纳下次young GC晋升的对象