--- old/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2019-02-27 10:23:31.100404212 +0100 +++ new/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2019-02-27 10:23:30.825395850 +0100 @@ -2113,15 +2113,21 @@ } void G1CollectedHeap::collect(GCCause::Cause cause) { + attempt_collect(cause, true); +} + +bool G1CollectedHeap::attempt_collect(GCCause::Cause cause, bool retry_on_vmop_failure) { assert_heap_not_locked(); - uint gc_count_before; - uint old_marking_count_before; - uint full_gc_count_before; - bool retry_gc; + bool vmop_succeeded; + bool should_retry_vmop; do { - retry_gc = false; + should_retry_vmop = false; + + uint gc_count_before; + uint old_marking_count_before; + uint full_gc_count_before; { MutexLocker ml(Heap_lock); @@ -2142,19 +2148,18 @@ true, /* should_initiate_conc_mark */ g1_policy()->max_pause_time_ms()); VMThread::execute(&op); - if (!op.pause_succeeded()) { + vmop_succeeded = op.pause_succeeded(); + if (!vmop_succeeded && retry_on_vmop_failure) { if (old_marking_count_before == _old_marking_cycles_started) { - retry_gc = op.should_retry_gc(); + should_retry_vmop = op.should_retry_gc(); } else { // A Full GC happened while we were trying to schedule the - // initial-mark GC. No point in starting a new cycle given + // concurrent cycle. No point in starting a new cycle given // that the whole heap was collected anyway. } - if (retry_gc) { - if (GCLocker::is_active_and_needs_gc()) { - GCLocker::stall_until_clear(); - } + if (should_retry_vmop && GCLocker::is_active_and_needs_gc()) { + GCLocker::stall_until_clear(); } } } else { @@ -2169,13 +2174,16 @@ false, /* should_initiate_conc_mark */ g1_policy()->max_pause_time_ms()); VMThread::execute(&op); + vmop_succeeded = op.pause_succeeded(); } else { // Schedule a Full GC. VM_G1CollectFull op(gc_count_before, full_gc_count_before, cause); VMThread::execute(&op); + vmop_succeeded = op.pause_succeeded(); } } - } while (retry_gc); + } while (should_retry_vmop); + return vmop_succeeded; } bool G1CollectedHeap::is_in(const void* p) const {