Skip to content

Commit 84889b4

Browse files
committed
backport 53e7ea891d8c3d91340bf1967aa94104f54b467c
1 parent 555fb0c commit 84889b4

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

707713
inline 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();

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,14 @@ class G1CollectedHeap : public CollectedHeap {
439439
//
440440
// * If either call cannot satisfy the allocation request using the
441441
// current allocating region, they will try to get a new one. If
442-
// this fails, they will attempt to do an evacuation pause and
443-
// retry the allocation.
444-
//
445-
// * If all allocation attempts fail, even after trying to schedule
446-
// an evacuation pause, allocate_new_tlab() will return NULL,
447-
// whereas mem_allocate() will attempt a heap expansion and/or
448-
// schedule a Full GC.
442+
// this fails, (only) mem_allocate() will attempt to do an evacuation
443+
// pause and retry the allocation. Allocate_new_tlab() will return null,
444+
// deferring to the following mem_allocate().
449445
//
450446
// * We do not allow humongous-sized TLABs. So, allocate_new_tlab
451447
// should never be called with word_size being humongous. All
452448
// humongous allocation requests should go to mem_allocate() which
453-
// will satisfy them with a special path.
449+
// will satisfy them in a special path.
454450

455451
virtual HeapWord* allocate_new_tlab(size_t min_size,
456452
size_t requested_size,
@@ -464,12 +460,14 @@ class G1CollectedHeap : public CollectedHeap {
464460
// should only be used for non-humongous allocations.
465461
inline HeapWord* attempt_allocation(size_t min_word_size,
466462
size_t desired_word_size,
467-
size_t* actual_word_size);
463+
size_t* actual_word_size,
464+
bool allow_gc);
468465

469466
// Second-level mutator allocation attempt: take the Heap_lock and
470467
// retry the allocation attempt, potentially scheduling a GC
471-
// pause. This should only be used for non-humongous allocations.
472-
HeapWord* attempt_allocation_slow(size_t word_size);
468+
// pause if allow_gc is set. This should only be used for non-humongous
469+
// allocations.
470+
HeapWord* attempt_allocation_slow(size_t word_size, bool allow_gc);
473471

474472
// Takes the Heap_lock and attempts a humongous allocation. It can
475473
// potentially schedule a GC pause.

0 commit comments

Comments
 (0)