Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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.
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down
21 changes: 9 additions & 12 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,14 @@ class G1CollectedHeap : public CollectedHeap {
//
// * 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,
Expand All @@ -463,12 +459,13 @@ class G1CollectedHeap : public CollectedHeap {
// 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.
Expand Down