@@ -386,22 +386,26 @@ HeapWord* G1CollectedHeap::allocate_new_tlab(size_t min_size,
386386 assert_heap_not_locked_and_not_at_safepoint ();
387387 assert (!is_humongous (requested_size), " we do not allow humongous TLABs" );
388388
389- return attempt_allocation (min_size, requested_size, actual_size);
389+ // Do not allow a GC because we are allocating a new TLAB to avoid an issue
390+ // with UseGCOverheadLimit: although this GC would return null if the overhead
391+ // limit would be exceeded, but it would likely free at least some space.
392+ // So the subsequent outside-TLAB allocation could be successful anyway and
393+ // the indication that the overhead limit had been exceeded swallowed.
394+ return attempt_allocation (min_size, requested_size, actual_size, false /* allow_gc */ );
390395}
391396
392- HeapWord*
393- G1CollectedHeap::mem_allocate (size_t word_size,
394- bool * gc_overhead_limit_was_exceeded) {
397+ HeapWord* G1CollectedHeap::mem_allocate (size_t word_size,
398+ bool * gc_overhead_limit_was_exceeded) {
395399 assert_heap_not_locked_and_not_at_safepoint ();
396400
397401 if (is_humongous (word_size)) {
398402 return attempt_allocation_humongous (word_size);
399403 }
400404 size_t dummy = 0 ;
401- return attempt_allocation (word_size, word_size, &dummy);
405+ return attempt_allocation (word_size, word_size, &dummy, true /* allow_gc */ );
402406}
403407
404- HeapWord* G1CollectedHeap::attempt_allocation_slow (uint node_index, size_t word_size) {
408+ HeapWord* G1CollectedHeap::attempt_allocation_slow (uint node_index, size_t word_size, bool allow_gc ) {
405409 ResourceMark rm; // For retrieving the thread names in log messages.
406410
407411 // Make sure you read the note in attempt_allocation_humongous().
@@ -430,6 +434,8 @@ HeapWord* G1CollectedHeap::attempt_allocation_slow(uint node_index, size_t word_
430434 result = _allocator->attempt_allocation_locked (node_index, word_size);
431435 if (result != nullptr ) {
432436 return result;
437+ } else if (!allow_gc) {
438+ return nullptr ;
433439 }
434440
435441 // If the GCLocker is active and we are bound for a GC, try expanding young gen.
@@ -631,7 +637,8 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion range) {
631637
632638inline HeapWord* G1CollectedHeap::attempt_allocation (size_t min_word_size,
633639 size_t desired_word_size,
634- size_t * actual_word_size) {
640+ size_t * actual_word_size,
641+ bool allow_gc) {
635642 assert_heap_not_locked_and_not_at_safepoint ();
636643 assert (!is_humongous (desired_word_size), " attempt_allocation() should not "
637644 " be called for humongous allocation requests" );
@@ -643,7 +650,7 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
643650
644651 if (result == nullptr ) {
645652 *actual_word_size = desired_word_size;
646- result = attempt_allocation_slow (node_index, desired_word_size);
653+ result = attempt_allocation_slow (node_index, desired_word_size, allow_gc );
647654 }
648655
649656 assert_heap_not_locked ();
0 commit comments