Skip to content

Commit 027aea9

Browse files
author
Thomas Schatzl
committed
8370325: G1: Disallow GC for TLAB allocation
Reviewed-by: iwalulya, ayang
1 parent ffcb158 commit 027aea9

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

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

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

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

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

Lines changed: 9 additions & 12 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
HeapWord* allocate_new_tlab(size_t min_size,
456452
size_t requested_size,
@@ -463,12 +459,13 @@ class G1CollectedHeap : public CollectedHeap {
463459
// should only be used for non-humongous allocations.
464460
inline HeapWord* attempt_allocation(size_t min_word_size,
465461
size_t desired_word_size,
466-
size_t* actual_word_size);
467-
462+
size_t* actual_word_size,
463+
bool allow_gc);
468464
// Second-level mutator allocation attempt: take the Heap_lock and
469465
// retry the allocation attempt, potentially scheduling a GC
470-
// pause. This should only be used for non-humongous allocations.
471-
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size);
466+
// pause if allow_gc is set. This should only be used for non-humongous
467+
// allocations.
468+
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size, bool allow_gc);
472469

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

0 commit comments

Comments
 (0)