--- old/src/share/vm/gc/g1/g1CollectedHeap.cpp 2015-08-24 16:54:12.169210351 -0400 +++ new/src/share/vm/gc/g1/g1CollectedHeap.cpp 2015-08-24 16:54:11.497171803 -0400 @@ -1728,21 +1728,20 @@ } } - -HeapWord* -G1CollectedHeap::satisfy_failed_allocation(size_t word_size, - AllocationContext_t context, - bool* succeeded) { - assert_at_safepoint(true /* should_be_vm_thread */); - - *succeeded = true; +HeapWord* G1CollectedHeap::satisfy_failed_allocation_helper(size_t word_size, + AllocationContext_t context, + bool do_gc, + bool clear_all_soft_refs, + bool expect_null_mutator_alloc_region, + bool* gc_succeeded) { + *gc_succeeded = true; // Let's attempt the allocation first. HeapWord* result = attempt_allocation_at_safepoint(word_size, context, - false /* expect_null_mutator_alloc_region */); + expect_null_mutator_alloc_region); if (result != NULL) { - assert(*succeeded, "sanity"); + assert(*gc_succeeded, "sanity"); return result; } @@ -1752,49 +1751,65 @@ // do something smarter than full collection to satisfy a failed alloc.) result = expand_and_allocate(word_size, context); if (result != NULL) { - assert(*succeeded, "sanity"); + assert(*gc_succeeded, "sanity"); return result; } - // Expansion didn't work, we'll try to do a Full GC. - bool gc_succeeded = do_collection(false, /* explicit_gc */ - false, /* clear_all_soft_refs */ - word_size); - if (!gc_succeeded) { - *succeeded = false; - return NULL; - } + if (do_gc) { + // Expansion didn't work, we'll try to do a Full GC. + *gc_succeeded = do_collection(false, /* explicit_gc */ + clear_all_soft_refs, + word_size); + + assert(!collector_policy()->should_clear_all_soft_refs(), + "Flag should have been handled and cleared prior to this point"); + } - // Retry the allocation - result = attempt_allocation_at_safepoint(word_size, - context, - true /* expect_null_mutator_alloc_region */); - if (result != NULL) { - assert(*succeeded, "sanity"); + return NULL; +} + +HeapWord* G1CollectedHeap::satisfy_failed_allocation(size_t word_size, + AllocationContext_t context, + bool* succeeded) { + assert_at_safepoint(true /* should_be_vm_thread */); + + // Attempts to allocate followed by Full GC. + HeapWord* result = + satisfy_failed_allocation_helper(word_size, + context, + true, /* do_gc */ + false, /* clear_all_soft_refs */ + false, /* expect_null_mutator_alloc_region */ + succeeded); + + if (result != NULL || !*succeeded) { return result; } - // Then, try a Full GC that will collect all soft references. - gc_succeeded = do_collection(false, /* explicit_gc */ - true, /* clear_all_soft_refs */ - word_size); - if (!gc_succeeded) { - *succeeded = false; - return NULL; + // Attempts to allocate followed by Full GC that will collect all soft references. + result = satisfy_failed_allocation_helper(word_size, + context, + true, /* do_gc */ + true, /* clear_all_soft_refs */ + true, /* expect_null_mutator_alloc_region */ + succeeded); + + if (result != NULL || !*succeeded) { + return result; } - // Retry the allocation once more - result = attempt_allocation_at_safepoint(word_size, - context, - true /* expect_null_mutator_alloc_region */); + // Attempts to allocate, no GC + result = satisfy_failed_allocation_helper(word_size, + context, + false, /* do_gc */ + false, /* clear_all_soft_refs */ + true, /* expect_null_mutator_alloc_region */ + succeeded); + if (result != NULL) { - assert(*succeeded, "sanity"); return result; } - assert(!collector_policy()->should_clear_all_soft_refs(), - "Flag should have been handled and cleared prior to this point"); - // What else? We might try synchronous finalization later. If the total // space available is large enough for the allocation, then a more // complete compaction phase than we've tried so far might be