1543 }
1544 }
1545 }
1546
1547 // Otherwise, we start a collection cycle if
1548 // old gen want a collection cycle started. Each may use
1549 // an appropriate criterion for making this decision.
1550 // XXX We need to make sure that the gen expansion
1551 // criterion dovetails well with this. XXX NEED TO FIX THIS
1552 if (_cmsGen->should_concurrent_collect()) {
1553 if (Verbose && PrintGCDetails) {
1554 gclog_or_tty->print_cr("CMS old gen initiated");
1555 }
1556 return true;
1557 }
1558
1559 // We start a collection if we believe an incremental collection may fail;
1560 // this is not likely to be productive in practice because it's probably too
1561 // late anyway.
1562 GenCollectedHeap* gch = GenCollectedHeap::heap();
1563 assert(gch->collector_policy()->is_two_generation_policy(),
1564 "You may want to check the correctness of the following");
1565 if (gch->incremental_collection_will_fail(true /* consult_young */)) {
1566 if (Verbose && PrintGCDetails) {
1567 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail ");
1568 }
1569 return true;
1570 }
1571
1572 if (MetaspaceGC::should_concurrent_collect()) {
1573 if (Verbose && PrintGCDetails) {
1574 gclog_or_tty->print("CMSCollector: collect for metadata allocation ");
1575 }
1576 return true;
1577 }
1578
1579 // CMSTriggerInterval starts a CMS cycle if enough time has passed.
1580 if (CMSTriggerInterval >= 0) {
1581 if (CMSTriggerInterval == 0) {
1582 // Trigger always
1583 return true;
1947 FreelistLocker z(this);
1948 MetaspaceGC::compute_new_size();
1949 _cmsGen->compute_new_size_free_list();
1950 }
1951
1952 // A work method used by foreground collection to determine
1953 // what type of collection (compacting or not, continuing or fresh)
1954 // it should do.
1955 // NOTE: the intent is to make UseCMSCompactAtFullCollection
1956 // and CMSCompactWhenClearAllSoftRefs the default in the future
1957 // and do away with the flags after a suitable period.
1958 void CMSCollector::decide_foreground_collection_type(
1959 bool clear_all_soft_refs, bool* should_compact,
1960 bool* should_start_over) {
1961 // Normally, we'll compact only if the UseCMSCompactAtFullCollection
1962 // flag is set, and we have either requested a System.gc() or
1963 // the number of full gc's since the last concurrent cycle
1964 // has exceeded the threshold set by CMSFullGCsBeforeCompaction,
1965 // or if an incremental collection has failed
1966 GenCollectedHeap* gch = GenCollectedHeap::heap();
1967 assert(gch->collector_policy()->is_two_generation_policy(),
1968 "You may want to check the correctness of the following");
1969 // Inform cms gen if this was due to partial collection failing.
1970 // The CMS gen may use this fact to determine its expansion policy.
1971 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) {
1972 assert(!_cmsGen->incremental_collection_failed(),
1973 "Should have been noticed, reacted to and cleared");
1974 _cmsGen->set_incremental_collection_failed();
1975 }
1976 *should_compact =
1977 UseCMSCompactAtFullCollection &&
1978 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) ||
1979 GCCause::is_user_requested_gc(gch->gc_cause()) ||
1980 gch->incremental_collection_will_fail(true /* consult_young */));
1981 *should_start_over = false;
1982 if (clear_all_soft_refs && !*should_compact) {
1983 // We are about to do a last ditch collection attempt
1984 // so it would normally make sense to do a compaction
1985 // to reclaim as much space as possible.
1986 if (CMSCompactWhenClearAllSoftRefs) {
1987 // Default: The rationale is that in this case either
|
1543 }
1544 }
1545 }
1546
1547 // Otherwise, we start a collection cycle if
1548 // old gen want a collection cycle started. Each may use
1549 // an appropriate criterion for making this decision.
1550 // XXX We need to make sure that the gen expansion
1551 // criterion dovetails well with this. XXX NEED TO FIX THIS
1552 if (_cmsGen->should_concurrent_collect()) {
1553 if (Verbose && PrintGCDetails) {
1554 gclog_or_tty->print_cr("CMS old gen initiated");
1555 }
1556 return true;
1557 }
1558
1559 // We start a collection if we believe an incremental collection may fail;
1560 // this is not likely to be productive in practice because it's probably too
1561 // late anyway.
1562 GenCollectedHeap* gch = GenCollectedHeap::heap();
1563 assert(gch->collector_policy()->is_generation_policy(),
1564 "You may want to check the correctness of the following");
1565 if (gch->incremental_collection_will_fail(true /* consult_young */)) {
1566 if (Verbose && PrintGCDetails) {
1567 gclog_or_tty->print("CMSCollector: collect because incremental collection will fail ");
1568 }
1569 return true;
1570 }
1571
1572 if (MetaspaceGC::should_concurrent_collect()) {
1573 if (Verbose && PrintGCDetails) {
1574 gclog_or_tty->print("CMSCollector: collect for metadata allocation ");
1575 }
1576 return true;
1577 }
1578
1579 // CMSTriggerInterval starts a CMS cycle if enough time has passed.
1580 if (CMSTriggerInterval >= 0) {
1581 if (CMSTriggerInterval == 0) {
1582 // Trigger always
1583 return true;
1947 FreelistLocker z(this);
1948 MetaspaceGC::compute_new_size();
1949 _cmsGen->compute_new_size_free_list();
1950 }
1951
1952 // A work method used by foreground collection to determine
1953 // what type of collection (compacting or not, continuing or fresh)
1954 // it should do.
1955 // NOTE: the intent is to make UseCMSCompactAtFullCollection
1956 // and CMSCompactWhenClearAllSoftRefs the default in the future
1957 // and do away with the flags after a suitable period.
1958 void CMSCollector::decide_foreground_collection_type(
1959 bool clear_all_soft_refs, bool* should_compact,
1960 bool* should_start_over) {
1961 // Normally, we'll compact only if the UseCMSCompactAtFullCollection
1962 // flag is set, and we have either requested a System.gc() or
1963 // the number of full gc's since the last concurrent cycle
1964 // has exceeded the threshold set by CMSFullGCsBeforeCompaction,
1965 // or if an incremental collection has failed
1966 GenCollectedHeap* gch = GenCollectedHeap::heap();
1967 assert(gch->collector_policy()->is_generation_policy(),
1968 "You may want to check the correctness of the following");
1969 // Inform cms gen if this was due to partial collection failing.
1970 // The CMS gen may use this fact to determine its expansion policy.
1971 if (gch->incremental_collection_will_fail(false /* don't consult_young */)) {
1972 assert(!_cmsGen->incremental_collection_failed(),
1973 "Should have been noticed, reacted to and cleared");
1974 _cmsGen->set_incremental_collection_failed();
1975 }
1976 *should_compact =
1977 UseCMSCompactAtFullCollection &&
1978 ((_full_gcs_since_conc_gc >= CMSFullGCsBeforeCompaction) ||
1979 GCCause::is_user_requested_gc(gch->gc_cause()) ||
1980 gch->incremental_collection_will_fail(true /* consult_young */));
1981 *should_start_over = false;
1982 if (clear_all_soft_refs && !*should_compact) {
1983 // We are about to do a last ditch collection attempt
1984 // so it would normally make sense to do a compaction
1985 // to reclaim as much space as possible.
1986 if (CMSCompactWhenClearAllSoftRefs) {
1987 // Default: The rationale is that in this case either
|