@@ -403,21 +403,25 @@ HeapWord* G1CollectedHeap::allocate_new_tlab(size_t min_size,
403403  assert_heap_not_locked_and_not_at_safepoint ();
404404  assert (!is_humongous (requested_size), " we do not allow humongous TLABs" 
405405
406-   return  attempt_allocation (min_size, requested_size, actual_size);
406+   //  Do not allow a GC because we are allocating a new TLAB to avoid an issue
407+   //  with UseGCOverheadLimit: although this GC would return null if the overhead
408+   //  limit would be exceeded, but it would likely free at least some space.
409+   //  So the subsequent outside-TLAB allocation could be successful anyway and
410+   //  the indication that the overhead limit had been exceeded swallowed.
411+   return  attempt_allocation (min_size, requested_size, actual_size, false  /*  allow_gc */ 
407412}
408413
409- HeapWord*
410- G1CollectedHeap::mem_allocate (size_t  word_size) {
414+ HeapWord* G1CollectedHeap::mem_allocate (size_t  word_size) {
411415  assert_heap_not_locked_and_not_at_safepoint ();
412416
413417  if  (is_humongous (word_size)) {
414418    return  attempt_allocation_humongous (word_size);
415419  }
416420  size_t  dummy = 0 ;
417-   return  attempt_allocation (word_size, word_size, &dummy);
421+   return  attempt_allocation (word_size, word_size, &dummy,  true   /*  allow_gc  */ 
418422}
419423
420- HeapWord* G1CollectedHeap::attempt_allocation_slow (uint node_index, size_t  word_size) {
424+ HeapWord* G1CollectedHeap::attempt_allocation_slow (uint node_index, size_t  word_size,  bool  allow_gc ) {
421425  ResourceMark rm; //  For retrieving the thread names in log messages.
422426
423427  //  Make sure you read the note in attempt_allocation_humongous().
@@ -444,6 +448,8 @@ HeapWord* G1CollectedHeap::attempt_allocation_slow(uint node_index, size_t word_
444448      result = _allocator->attempt_allocation_locked (node_index, word_size);
445449      if  (result != nullptr ) {
446450        return  result;
451+       } else  if  (!allow_gc) {
452+         return  nullptr ;
447453      }
448454
449455      //  Read the GC count while still holding the Heap_lock.
@@ -612,7 +618,8 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion range) {
612618
613619inline  HeapWord* G1CollectedHeap::attempt_allocation (size_t  min_word_size,
614620                                                     size_t  desired_word_size,
615-                                                      size_t * actual_word_size) {
621+                                                      size_t * actual_word_size,
622+                                                      bool  allow_gc) {
616623  assert_heap_not_locked_and_not_at_safepoint ();
617624  assert (!is_humongous (desired_word_size), " attempt_allocation() should not " 
618625         " be called for humongous allocation requests" 
@@ -624,7 +631,7 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
624631
625632  if  (result == nullptr ) {
626633    *actual_word_size = desired_word_size;
627-     result = attempt_allocation_slow (node_index, desired_word_size);
634+     result = attempt_allocation_slow (node_index, desired_word_size, allow_gc );
628635  }
629636
630637  assert_heap_not_locked ();
0 commit comments