From 5d1b911c92b933c257c8e9afe1464ec175ca1cc2 Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Wed, 2 Aug 2023 09:17:41 +0000 Subject: [PATCH] 8310311: Serial: move Generation::contribute_scratch to DefNewGeneration Reviewed-by: tschatzl, kbarrett --- .../share/gc/serial/defNewGeneration.cpp | 21 +++----- .../share/gc/serial/defNewGeneration.hpp | 15 ++---- src/hotspot/share/gc/serial/genMarkSweep.cpp | 19 +++---- .../share/gc/shared/genCollectedHeap.cpp | 50 ------------------- .../share/gc/shared/genCollectedHeap.hpp | 11 ---- src/hotspot/share/gc/shared/generation.hpp | 16 ------ 6 files changed, 20 insertions(+), 112 deletions(-) diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index 4d0d01b8fa3..5c5b68e1414 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -981,27 +981,18 @@ bool DefNewGeneration::no_allocs_since_save_marks() { return to()->saved_mark_at_top(); } -void DefNewGeneration::contribute_scratch(ScratchBlock*& list, Generation* requestor, - size_t max_alloc_words) { - if (requestor == this || _promotion_failed) { +void DefNewGeneration::contribute_scratch(void*& scratch, size_t& num_words) { + if (_promotion_failed) { return; } - assert(GenCollectedHeap::heap()->is_old_gen(requestor), "We should not call our own generation"); - /* $$$ Assert this? "trace" is a "MarkSweep" function so that's not appropriate. - if (to_space->top() > to_space->bottom()) { - trace("to_space not empty when contribute_scratch called"); - } - */ + const size_t MinFreeScratchWords = 100; ContiguousSpace* to_space = to(); - assert(to_space->end() >= to_space->top(), "pointers out of order"); - size_t free_words = pointer_delta(to_space->end(), to_space->top()); + const size_t free_words = pointer_delta(to_space->end(), to_space->top()); if (free_words >= MinFreeScratchWords) { - ScratchBlock* sb = (ScratchBlock*)to_space->top(); - sb->num_words = free_words; - sb->next = list; - list = sb; + scratch = to_space->top(); + num_words = free_words; } } diff --git a/src/hotspot/share/gc/serial/defNewGeneration.hpp b/src/hotspot/share/gc/serial/defNewGeneration.hpp index 0313d408224..bdd99ec234c 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.hpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.hpp @@ -143,12 +143,6 @@ class DefNewGeneration: public Generation { StringDedup::Requests _string_dedup_requests; - enum SomeProtectedConstants { - // Generations are GenGrain-aligned and have size that are multiples of - // GenGrain. - MinFreeScratchWords = 100 - }; - // Return the size of a survivor space if this generation were of size // gen_size. size_t compute_survivor_size(size_t gen_size, size_t alignment) const { @@ -248,13 +242,12 @@ class DefNewGeneration: public Generation { template void oop_since_save_marks_iterate(OopClosureType* cl); - // For non-youngest collection, the DefNewGeneration can contribute - // "to-space". - virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor, - size_t max_alloc_words); + // For Old collection (part of running Full GC), the DefNewGeneration can + // contribute the free part of "to-space" as the scratch space. + void contribute_scratch(void*& scratch, size_t& num_words); // Reset for contribution of "to-space". - virtual void reset_scratch(); + void reset_scratch(); // GC support virtual void compute_new_size(); diff --git a/src/hotspot/share/gc/serial/genMarkSweep.cpp b/src/hotspot/share/gc/serial/genMarkSweep.cpp index 581ac5e6edf..c4d8241c929 100644 --- a/src/hotspot/share/gc/serial/genMarkSweep.cpp +++ b/src/hotspot/share/gc/serial/genMarkSweep.cpp @@ -33,6 +33,7 @@ #include "code/icBuffer.hpp" #include "compiler/oopMap.hpp" #include "gc/serial/cardTableRS.hpp" +#include "gc/serial/defNewGeneration.hpp" #include "gc/serial/genMarkSweep.hpp" #include "gc/serial/serialGcRefProcProxyTask.hpp" #include "gc/shared/collectedHeap.inline.hpp" @@ -126,15 +127,13 @@ void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) { } void GenMarkSweep::allocate_stacks() { - GenCollectedHeap* gch = GenCollectedHeap::heap(); - // Scratch request on behalf of old generation; will do no allocation. - ScratchBlock* scratch = gch->gather_scratch(gch->old_gen(), 0); + void* scratch = nullptr; + size_t num_words; + DefNewGeneration* young_gen = (DefNewGeneration*)GenCollectedHeap::heap()->young_gen(); + young_gen->contribute_scratch(scratch, num_words); - // $$$ To cut a corner, we'll only use the first scratch block, and then - // revert to malloc. if (scratch != nullptr) { - _preserved_count_max = - scratch->num_words * HeapWordSize / sizeof(PreservedMark); + _preserved_count_max = num_words * HeapWordSize / sizeof(PreservedMark); } else { _preserved_count_max = 0; } @@ -147,8 +146,10 @@ void GenMarkSweep::allocate_stacks() { void GenMarkSweep::deallocate_stacks() { - GenCollectedHeap* gch = GenCollectedHeap::heap(); - gch->release_scratch(); + if (_preserved_count_max != 0) { + DefNewGeneration* young_gen = (DefNewGeneration*)GenCollectedHeap::heap()->young_gen(); + young_gen->reset_scratch(); + } _preserved_overflow_stack_set.reclaim(); _marking_stack.clear(); diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.cpp b/src/hotspot/share/gc/shared/genCollectedHeap.cpp index f7e93d7d984..5c67fa7eb82 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp @@ -905,56 +905,6 @@ HeapWord* GenCollectedHeap::allocate_new_tlab(size_t min_size, return result; } -// Requires "*prev_ptr" to be non-null. Deletes and a block of minimal size -// from the list headed by "*prev_ptr". -static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) { - bool first = true; - size_t min_size = 0; // "first" makes this conceptually infinite. - ScratchBlock **smallest_ptr, *smallest; - ScratchBlock *cur = *prev_ptr; - while (cur) { - assert(*prev_ptr == cur, "just checking"); - if (first || cur->num_words < min_size) { - smallest_ptr = prev_ptr; - smallest = cur; - min_size = smallest->num_words; - first = false; - } - prev_ptr = &cur->next; - cur = cur->next; - } - smallest = *smallest_ptr; - *smallest_ptr = smallest->next; - return smallest; -} - -// Sort the scratch block list headed by res into decreasing size order, -// and set "res" to the result. -static void sort_scratch_list(ScratchBlock*& list) { - ScratchBlock* sorted = nullptr; - ScratchBlock* unsorted = list; - while (unsorted) { - ScratchBlock *smallest = removeSmallestScratch(&unsorted); - smallest->next = sorted; - sorted = smallest; - } - list = sorted; -} - -ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor, - size_t max_alloc_words) { - ScratchBlock* res = nullptr; - _young_gen->contribute_scratch(res, requestor, max_alloc_words); - _old_gen->contribute_scratch(res, requestor, max_alloc_words); - sort_scratch_list(res); - return res; -} - -void GenCollectedHeap::release_scratch() { - _young_gen->reset_scratch(); - _old_gen->reset_scratch(); -} - void GenCollectedHeap::prepare_for_verify() { ensure_parsability(false); // no need to retire TLABs } diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.hpp b/src/hotspot/share/gc/shared/genCollectedHeap.hpp index 6d6b54f69ce..b8d811421e1 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp @@ -228,17 +228,6 @@ public: size_t requested_size, size_t* actual_size) override; - // The "requestor" generation is performing some garbage collection - // action for which it would be useful to have scratch space. The - // requestor promises to allocate no more than "max_alloc_words" in any - // older generation (via promotion say.) Any blocks of space that can - // be provided are returned as a list of ScratchBlocks, sorted by - // decreasing size. - ScratchBlock* gather_scratch(Generation* requestor, size_t max_alloc_words); - // Allow each generation to reset any scratch space that it has - // contributed as it needs. - void release_scratch(); - // Ensure parsability void ensure_parsability(bool retire_tlabs) override; diff --git a/src/hotspot/share/gc/shared/generation.hpp b/src/hotspot/share/gc/shared/generation.hpp index cfb64b17354..4bf6c8b12a8 100644 --- a/src/hotspot/share/gc/shared/generation.hpp +++ b/src/hotspot/share/gc/shared/generation.hpp @@ -326,22 +326,6 @@ class Generation: public CHeapObj { // generation since the last call to "save_marks". virtual bool no_allocs_since_save_marks() = 0; - // The "requestor" generation is performing some garbage collection - // action for which it would be useful to have scratch space. If - // the target is not the requestor, no gc actions will be required - // of the target. The requestor promises to allocate no more than - // "max_alloc_words" in the target generation (via promotion say, - // if the requestor is a young generation and the target is older). - // If the target generation can provide any scratch space, it adds - // it to "list", leaving "list" pointing to the head of the - // augmented list. The default is to offer no space. - virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor, - size_t max_alloc_words) {} - - // Give each generation an opportunity to do clean up for any - // contributed scratch. - virtual void reset_scratch() {} - // When an older generation has been collected, and perhaps resized, // this method will be invoked on all younger generations (from older to // younger), allowing them to resize themselves as appropriate.