8331562: G1: Remove API to force allocation of new regions

Reviewed-by: iwalulya, ayang, gli
This commit is contained in:
Thomas Schatzl 2024-05-03 13:10:00 +00:00
parent 9697bc3858
commit 1d083eb15a
8 changed files with 15 additions and 48 deletions

View File

@ -130,13 +130,12 @@ size_t G1AllocRegion::retire(bool fill_up) {
return waste;
}
HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size,
bool force) {
HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size) {
assert_alloc_region(_alloc_region == _dummy_region, "pre-condition");
assert_alloc_region(_used_bytes_before == 0, "pre-condition");
trace("attempting region allocation");
HeapRegion* new_alloc_region = allocate_new_region(word_size, force);
HeapRegion* new_alloc_region = allocate_new_region(word_size);
if (new_alloc_region != nullptr) {
new_alloc_region->reset_pre_dummy_top();
// Need to do this before the allocation
@ -258,9 +257,8 @@ G1AllocRegion::G1AllocRegion(const char* name,
_node_index(node_index)
{ }
HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size,
bool force) {
return _g1h->new_mutator_alloc_region(word_size, force, _node_index);
HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size) {
return _g1h->new_mutator_alloc_region(word_size, _node_index);
}
void MutatorAllocRegion::retire_region(HeapRegion* alloc_region,
@ -344,9 +342,7 @@ HeapRegion* MutatorAllocRegion::release() {
return ret;
}
HeapRegion* G1GCAllocRegion::allocate_new_region(size_t word_size,
bool force) {
assert(!force, "not supported for GC alloc regions");
HeapRegion* G1GCAllocRegion::allocate_new_region(size_t word_size) {
return _g1h->new_gc_alloc_region(word_size, _purpose, _node_index);
}

View File

@ -83,10 +83,8 @@ private:
void update_alloc_region(HeapRegion* alloc_region);
// Allocate a new active region and use it to perform a word_size
// allocation. The force parameter will be passed on to
// G1CollectedHeap::allocate_new_alloc_region() and tells it to try
// to allocate a new region even if the max has been reached.
HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
// allocation.
HeapWord* new_alloc_region_and_allocate(size_t word_size);
// Perform an allocation out of a new allocation region, retiring the current one.
inline HeapWord* attempt_allocation_using_new_region(size_t min_word_size,
@ -132,7 +130,7 @@ protected:
// For convenience as subclasses use it.
static G1CollectedHeap* _g1h;
virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
virtual HeapRegion* allocate_new_region(size_t word_size) = 0;
virtual void retire_region(HeapRegion* alloc_region,
size_t allocated_bytes) = 0;
@ -172,12 +170,6 @@ public:
size_t desired_word_size,
size_t* actual_word_size);
// Should be called to allocate a new region even if the max of this
// type of regions has been reached. Should only be called if other
// allocation attempts have failed and we are not holding a valid
// active region.
inline HeapWord* attempt_allocation_force(size_t word_size);
// Should be called before we start using this object.
virtual void init();
@ -213,7 +205,7 @@ private:
// in it and the free size in the currently retained region, if any.
bool should_retain(HeapRegion* region);
protected:
virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
virtual HeapRegion* allocate_new_region(size_t word_size);
virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
virtual size_t retire(bool fill_up);
public:
@ -249,7 +241,7 @@ protected:
G1EvacStats* _stats;
G1HeapRegionAttr::region_type_t _purpose;
virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
virtual HeapRegion* allocate_new_region(size_t word_size);
virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
virtual size_t retire(bool fill_up);

View File

@ -98,7 +98,7 @@ inline HeapWord* G1AllocRegion::attempt_allocation_using_new_region(size_t min_w
size_t desired_word_size,
size_t* actual_word_size) {
retire(true /* fill_up */);
HeapWord* result = new_alloc_region_and_allocate(desired_word_size, false /* force */);
HeapWord* result = new_alloc_region_and_allocate(desired_word_size);
if (result != nullptr) {
*actual_word_size = desired_word_size;
trace("alloc locked (second attempt)", min_word_size, desired_word_size, *actual_word_size, result);
@ -108,19 +108,6 @@ inline HeapWord* G1AllocRegion::attempt_allocation_using_new_region(size_t min_w
return nullptr;
}
inline HeapWord* G1AllocRegion::attempt_allocation_force(size_t word_size) {
assert_alloc_region(_alloc_region != nullptr, "not initialized properly");
trace("forcing alloc", word_size, word_size);
HeapWord* result = new_alloc_region_and_allocate(word_size, true /* force */);
if (result != nullptr) {
trace("alloc forced", word_size, word_size, word_size, result);
return result;
}
trace("alloc forced failed", word_size, word_size);
return nullptr;
}
inline HeapWord* MutatorAllocRegion::attempt_retained_allocation(size_t min_word_size,
size_t desired_word_size,
size_t* actual_word_size) {

View File

@ -121,8 +121,6 @@ public:
// current allocation region, and then attempts an allocation using a new region.
inline HeapWord* attempt_allocation_locked(size_t word_size);
inline HeapWord* attempt_allocation_force(size_t word_size);
size_t unsafe_max_tlab_alloc();
size_t used_in_alloc_regions();

View File

@ -71,11 +71,6 @@ inline HeapWord* G1Allocator::attempt_allocation_locked(size_t word_size) {
return result;
}
inline HeapWord* G1Allocator::attempt_allocation_force(size_t word_size) {
uint node_index = current_node_index();
return mutator_alloc_region(node_index)->attempt_allocation_force(word_size);
}
inline PLAB* G1PLABAllocator::alloc_buffer(G1HeapRegionAttr dest, uint node_index) const {
assert(dest.is_valid(),
"Allocation buffer index out of bounds: %s", dest.get_type_str());

View File

@ -2846,18 +2846,17 @@ void G1CollectedHeap::rebuild_region_sets(bool free_list_only) {
// Methods for the mutator alloc region
HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size,
bool force,
uint node_index) {
assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
bool should_allocate = policy()->should_allocate_mutator_region();
if (force || should_allocate) {
if (should_allocate) {
HeapRegion* new_alloc_region = new_region(word_size,
HeapRegionType::Eden,
false /* do_expand */,
node_index);
if (new_alloc_region != nullptr) {
set_region_short_lived_locked(new_alloc_region);
G1HRPrinter::alloc(new_alloc_region, !should_allocate);
G1HRPrinter::alloc(new_alloc_region);
_policy->remset_tracker()->update_at_allocate(new_alloc_region);
return new_alloc_region;
}

View File

@ -465,7 +465,7 @@ private:
// These methods are the "callbacks" from the G1AllocRegion class.
// For mutator alloc regions.
HeapRegion* new_mutator_alloc_region(size_t word_size, bool force, uint node_index);
HeapRegion* new_mutator_alloc_region(size_t word_size, uint node_index);
void retire_mutator_alloc_region(HeapRegion* alloc_region,
size_t allocated_bytes);

View File

@ -51,7 +51,7 @@ public:
// The methods below are convenient wrappers for the print() method.
static void alloc(HeapRegion* hr, bool force = false) { print(force ? "ALLOC-FORCE" : "ALLOC", hr); }
static void alloc(HeapRegion* hr) { print("ALLOC", hr); }
static void retire(HeapRegion* hr) { print("RETIRE", hr); }