8370325: G1: Disallow GC for TLAB allocation

Reviewed-by: iwalulya, ayang
This commit is contained in:
Thomas Schatzl 2025-10-23 07:05:08 +00:00
parent ffcb1585ed
commit 027aea9d2e
2 changed files with 23 additions and 19 deletions

View File

@ -403,21 +403,25 @@ HeapWord* G1CollectedHeap::allocate_new_tlab(size_t min_size,
assert_heap_not_locked_and_not_at_safepoint();
assert(!is_humongous(requested_size), "we do not allow humongous TLABs");
return attempt_allocation(min_size, requested_size, actual_size);
// Do not allow a GC because we are allocating a new TLAB to avoid an issue
// with UseGCOverheadLimit: although this GC would return null if the overhead
// limit would be exceeded, but it would likely free at least some space.
// So the subsequent outside-TLAB allocation could be successful anyway and
// the indication that the overhead limit had been exceeded swallowed.
return attempt_allocation(min_size, requested_size, actual_size, false /* allow_gc */);
}
HeapWord*
G1CollectedHeap::mem_allocate(size_t word_size) {
HeapWord* G1CollectedHeap::mem_allocate(size_t word_size) {
assert_heap_not_locked_and_not_at_safepoint();
if (is_humongous(word_size)) {
return attempt_allocation_humongous(word_size);
}
size_t dummy = 0;
return attempt_allocation(word_size, word_size, &dummy);
return attempt_allocation(word_size, word_size, &dummy, true /* allow_gc */);
}
HeapWord* G1CollectedHeap::attempt_allocation_slow(uint node_index, size_t word_size) {
HeapWord* G1CollectedHeap::attempt_allocation_slow(uint node_index, size_t word_size, bool allow_gc) {
ResourceMark rm; // For retrieving the thread names in log messages.
// 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_
result = _allocator->attempt_allocation_locked(node_index, word_size);
if (result != nullptr) {
return result;
} else if (!allow_gc) {
return nullptr;
}
// Read the GC count while still holding the Heap_lock.
@ -612,7 +618,8 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion range) {
inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
size_t desired_word_size,
size_t* actual_word_size) {
size_t* actual_word_size,
bool allow_gc) {
assert_heap_not_locked_and_not_at_safepoint();
assert(!is_humongous(desired_word_size), "attempt_allocation() should not "
"be called for humongous allocation requests");
@ -624,7 +631,7 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
if (result == nullptr) {
*actual_word_size = desired_word_size;
result = attempt_allocation_slow(node_index, desired_word_size);
result = attempt_allocation_slow(node_index, desired_word_size, allow_gc);
}
assert_heap_not_locked();

View File

@ -439,18 +439,14 @@ private:
//
// * If either call cannot satisfy the allocation request using the
// current allocating region, they will try to get a new one. If
// this fails, they will attempt to do an evacuation pause and
// retry the allocation.
//
// * If all allocation attempts fail, even after trying to schedule
// an evacuation pause, allocate_new_tlab() will return null,
// whereas mem_allocate() will attempt a heap expansion and/or
// schedule a Full GC.
// this fails, (only) mem_allocate() will attempt to do an evacuation
// pause and retry the allocation. Allocate_new_tlab() will return null,
// deferring to the following mem_allocate().
//
// * We do not allow humongous-sized TLABs. So, allocate_new_tlab
// should never be called with word_size being humongous. All
// humongous allocation requests should go to mem_allocate() which
// will satisfy them with a special path.
// will satisfy them in a special path.
HeapWord* allocate_new_tlab(size_t min_size,
size_t requested_size,
@ -463,12 +459,13 @@ private:
// should only be used for non-humongous allocations.
inline HeapWord* attempt_allocation(size_t min_word_size,
size_t desired_word_size,
size_t* actual_word_size);
size_t* actual_word_size,
bool allow_gc);
// Second-level mutator allocation attempt: take the Heap_lock and
// retry the allocation attempt, potentially scheduling a GC
// pause. This should only be used for non-humongous allocations.
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size);
// pause if allow_gc is set. This should only be used for non-humongous
// allocations.
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size, bool allow_gc);
// Takes the Heap_lock and attempts a humongous allocation. It can
// potentially schedule a GC pause.