// 根据内存使用是否满足回收的条件进行判定 if (_cmsGen->should_concurrent_collect()) { if (Verbose && PrintGCDetails) { gclog_or_tty->print_cr("CMS old gen initiated"); } return true; }
// 根据CMS是否存在回收失败的风险进行判定 GenCollectedHeap *gch = GenCollectedHeap::heap(); assert(gch->collector_policy()->is_two_generation_policy(), "You may want to check the correctness of the following"); if (gch->incremental_collection_will_fail(true /* consult_young */)) { if (Verbose && PrintGCDetails) { gclog_or_tty->print("CMSCollector: collect because incremental collection will fail "); } return true; }
// 根据元空间剩余空间大小判定 if (MetaspaceGC::should_concurrent_collect()) { if (Verbose && PrintGCDetails) { gclog_or_tty->print("CMSCollector: collect for metadata allocation "); } return true; }
// 根据 CMS 触发的周期判定: // a. 如果配置为0则返回为 true // b. 如果自cms触发到现在为止的时间大于触发周期,返回 true if (CMSTriggerInterval >= 0) { if (CMSTriggerInterval == 0) { // Trigger always return true; }
if (stats().cms_time_since_begin() >= (CMSTriggerInterval / ((double) MILLIUNITS))) { if (Verbose && PrintGCDetails) { if (stats().valid()) { gclog_or_tty->print_cr( "CMSCollector: collect because of trigger interval (time since last begin %3.7f secs)", stats().cms_time_since_begin()); } else { gclog_or_tty->print_cr("CMSCollector: collect because of trigger interval (first collection)"); } } return true; } }
// Support for concurrent collection policy decisions. bool CompactibleFreeListSpace::should_concurrent_collect() const { // In the future we might want to add in frgamentation stats -- // including erosion of the "mountain" into this decision as well. return !adaptive_freelists() && linearAllocationWouldFail(); }