Skip to content

Commit 3267049

Browse files
committed
8370325: G1: Disallow GC for TLAB allocation
Backport-of: 53e7ea8
1 parent 335ca2e commit 3267049

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

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

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

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

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,14 @@ class G1CollectedHeap : public CollectedHeap {
423423
//
424424
// * If either call cannot satisfy the allocation request using the
425425
// current allocating region, they will try to get a new one. If
426-
// this fails, they will attempt to do an evacuation pause and
427-
// retry the allocation.
428-
//
429-
// * If all allocation attempts fail, even after trying to schedule
430-
// an evacuation pause, allocate_new_tlab() will return null,
431-
// whereas mem_allocate() will attempt a heap expansion and/or
432-
// schedule a Full GC.
426+
// this fails, (only) mem_allocate() will attempt to do an evacuation
427+
// pause and retry the allocation. Allocate_new_tlab() will return null,
428+
// deferring to the following mem_allocate().
433429
//
434430
// * We do not allow humongous-sized TLABs. So, allocate_new_tlab
435431
// should never be called with word_size being humongous. All
436432
// humongous allocation requests should go to mem_allocate() which
437-
// will satisfy them with a special path.
433+
// will satisfy them in a special path.
438434

439435
HeapWord* allocate_new_tlab(size_t min_size,
440436
size_t requested_size,
@@ -448,12 +444,13 @@ class G1CollectedHeap : public CollectedHeap {
448444
// should only be used for non-humongous allocations.
449445
inline HeapWord* attempt_allocation(size_t min_word_size,
450446
size_t desired_word_size,
451-
size_t* actual_word_size);
452-
447+
size_t* actual_word_size,
448+
bool allow_gc);
453449
// Second-level mutator allocation attempt: take the Heap_lock and
454450
// retry the allocation attempt, potentially scheduling a GC
455-
// pause. This should only be used for non-humongous allocations.
456-
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size);
451+
// pause if allow_gc is set. This should only be used for non-humongous
452+
// allocations.
453+
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size, bool allow_gc);
457454

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

0 commit comments

Comments
 (0)