美文网首页
-XX:CMSInitiatingOccupancyFracti

-XX:CMSInitiatingOccupancyFracti

作者: 阿阿阿阿嘞 | 来源:发表于2017-08-01 11:17 被阅读0次

    使用例子:
    -XX:CMSInitiatingOccupancyFraction=70
    CMS垃圾收集器,当老年代达到70%时,触发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是个负值,那么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}
    

    即最终当老年代达到 ((100 - 40) + (double) 80 * 40 / 100 ) / 100 = 92 %时,会触发CMS回收。

    相关文章

      网友评论

          本文标题:-XX:CMSInitiatingOccupancyFracti

          本文链接:https://www.haomeiwen.com/subject/zxcjlxtx.html