From 1d083eb15a653dbfbd262de76c1312207192bda7 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Fri, 3 May 2024 13:10:00 +0000 Subject: [PATCH] 8331562: G1: Remove API to force allocation of new regions Reviewed-by: iwalulya, ayang, gli --- src/hotspot/share/gc/g1/g1AllocRegion.cpp | 14 +++++--------- src/hotspot/share/gc/g1/g1AllocRegion.hpp | 18 +++++------------- .../share/gc/g1/g1AllocRegion.inline.hpp | 15 +-------------- src/hotspot/share/gc/g1/g1Allocator.hpp | 2 -- src/hotspot/share/gc/g1/g1Allocator.inline.hpp | 5 ----- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 5 ++--- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 2 +- src/hotspot/share/gc/g1/g1HRPrinter.hpp | 2 +- 8 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1AllocRegion.cpp b/src/hotspot/share/gc/g1/g1AllocRegion.cpp index f20f24bcde4..b86fe1099ac 100644 --- a/src/hotspot/share/gc/g1/g1AllocRegion.cpp +++ b/src/hotspot/share/gc/g1/g1AllocRegion.cpp @@ -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); } diff --git a/src/hotspot/share/gc/g1/g1AllocRegion.hpp b/src/hotspot/share/gc/g1/g1AllocRegion.hpp index b39a717d3b7..9ea20c676f4 100644 --- a/src/hotspot/share/gc/g1/g1AllocRegion.hpp +++ b/src/hotspot/share/gc/g1/g1AllocRegion.hpp @@ -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); diff --git a/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp b/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp index 00ef254e84c..9e702a4f8c9 100644 --- a/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp +++ b/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp @@ -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) { diff --git a/src/hotspot/share/gc/g1/g1Allocator.hpp b/src/hotspot/share/gc/g1/g1Allocator.hpp index 32f37778a18..e273365b12f 100644 --- a/src/hotspot/share/gc/g1/g1Allocator.hpp +++ b/src/hotspot/share/gc/g1/g1Allocator.hpp @@ -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(); diff --git a/src/hotspot/share/gc/g1/g1Allocator.inline.hpp b/src/hotspot/share/gc/g1/g1Allocator.inline.hpp index 13ae9b9bbbd..ff84306e74f 100644 --- a/src/hotspot/share/gc/g1/g1Allocator.inline.hpp +++ b/src/hotspot/share/gc/g1/g1Allocator.inline.hpp @@ -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()); diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 45f570dcd2b..c411b7a7534 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -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; } diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 6f31122014f..3aaa6d8b723 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -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); diff --git a/src/hotspot/share/gc/g1/g1HRPrinter.hpp b/src/hotspot/share/gc/g1/g1HRPrinter.hpp index 035e92fefac..57e451bbb61 100644 --- a/src/hotspot/share/gc/g1/g1HRPrinter.hpp +++ b/src/hotspot/share/gc/g1/g1HRPrinter.hpp @@ -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); }