@@ -360,22 +360,26 @@ HeapWord* G1CollectedHeap::allocate_new_tlab(size_t min_size,
360360 assert_heap_not_locked_and_not_at_safepoint ();
361361 assert (!is_humongous (requested_size), " we do not allow humongous TLABs" );
362362
363- return attempt_allocation (min_size, requested_size, actual_size);
363+ // Do not allow a GC because we are allocating a new TLAB to avoid an issue
364+ // with UseGCOverheadLimit: although this GC would return null if the overhead
365+ // limit would be exceeded, but it would likely free at least some space.
366+ // So the subsequent outside-TLAB allocation could be successful anyway and
367+ // the indication that the overhead limit had been exceeded swallowed.
368+ return attempt_allocation (min_size, requested_size, actual_size, false /* allow_gc */ );
364369}
365370
366- HeapWord*
367- G1CollectedHeap::mem_allocate (size_t word_size,
368- bool * gc_overhead_limit_was_exceeded) {
371+ HeapWord* G1CollectedHeap::mem_allocate (size_t word_size,
372+ bool * gc_overhead_limit_was_exceeded) {
369373 assert_heap_not_locked_and_not_at_safepoint ();
370374
371375 if (is_humongous (word_size)) {
372376 return attempt_allocation_humongous (word_size);
373377 }
374378 size_t dummy = 0 ;
375- return attempt_allocation (word_size, word_size, &dummy);
379+ return attempt_allocation (word_size, word_size, &dummy, true /* allow_gc */ );
376380}
377381
378- HeapWord* G1CollectedHeap::attempt_allocation_slow (size_t word_size) {
382+ HeapWord* G1CollectedHeap::attempt_allocation_slow (size_t word_size, bool allow_gc ) {
379383 ResourceMark rm; // For retrieving the thread names in log messages.
380384
381385 // Make sure you read the note in attempt_allocation_humongous().
@@ -448,6 +452,8 @@ HeapWord* G1CollectedHeap::attempt_allocation_slow(size_t word_size) {
448452 log_trace (gc, alloc)(" %s: Successfully scheduled collection returning " PTR_FORMAT,
449453 Thread::current ()->name (), p2i (result));
450454 return result;
455+ } else if (!allow_gc) {
456+ return nullptr ;
451457 }
452458
453459 if (succeeded) {
@@ -706,7 +712,8 @@ void G1CollectedHeap::fill_archive_regions(MemRegion* ranges, size_t count) {
706712
707713inline HeapWord* G1CollectedHeap::attempt_allocation (size_t min_word_size,
708714 size_t desired_word_size,
709- size_t * actual_word_size) {
715+ size_t * actual_word_size,
716+ bool allow_gc) {
710717 assert_heap_not_locked_and_not_at_safepoint ();
711718 assert (!is_humongous (desired_word_size), " attempt_allocation() should not "
712719 " be called for humongous allocation requests" );
@@ -715,7 +722,7 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
715722
716723 if (result == NULL ) {
717724 *actual_word_size = desired_word_size;
718- result = attempt_allocation_slow (desired_word_size);
725+ result = attempt_allocation_slow (desired_word_size, allow_gc );
719726 }
720727
721728 assert_heap_not_locked ();
0 commit comments