Skip to content

Commit 5d1b911

Browse files
committedAug 2, 2023
8310311: Serial: move Generation::contribute_scratch to DefNewGeneration
Reviewed-by: tschatzl, kbarrett
1 parent 9454b2b commit 5d1b911

File tree

6 files changed

+20
-112
lines changed

6 files changed

+20
-112
lines changed
 

‎src/hotspot/share/gc/serial/defNewGeneration.cpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -981,27 +981,18 @@ bool DefNewGeneration::no_allocs_since_save_marks() {
981981
return to()->saved_mark_at_top();
982982
}
983983

984-
void DefNewGeneration::contribute_scratch(ScratchBlock*& list, Generation* requestor,
985-
size_t max_alloc_words) {
986-
if (requestor == this || _promotion_failed) {
984+
void DefNewGeneration::contribute_scratch(void*& scratch, size_t& num_words) {
985+
if (_promotion_failed) {
987986
return;
988987
}
989-
assert(GenCollectedHeap::heap()->is_old_gen(requestor), "We should not call our own generation");
990988

991-
/* $$$ Assert this? "trace" is a "MarkSweep" function so that's not appropriate.
992-
if (to_space->top() > to_space->bottom()) {
993-
trace("to_space not empty when contribute_scratch called");
994-
}
995-
*/
989+
const size_t MinFreeScratchWords = 100;
996990

997991
ContiguousSpace* to_space = to();
998-
assert(to_space->end() >= to_space->top(), "pointers out of order");
999-
size_t free_words = pointer_delta(to_space->end(), to_space->top());
992+
const size_t free_words = pointer_delta(to_space->end(), to_space->top());
1000993
if (free_words >= MinFreeScratchWords) {
1001-
ScratchBlock* sb = (ScratchBlock*)to_space->top();
1002-
sb->num_words = free_words;
1003-
sb->next = list;
1004-
list = sb;
994+
scratch = to_space->top();
995+
num_words = free_words;
1005996
}
1006997
}
1007998

‎src/hotspot/share/gc/serial/defNewGeneration.hpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ class DefNewGeneration: public Generation {
143143

144144
StringDedup::Requests _string_dedup_requests;
145145

146-
enum SomeProtectedConstants {
147-
// Generations are GenGrain-aligned and have size that are multiples of
148-
// GenGrain.
149-
MinFreeScratchWords = 100
150-
};
151-
152146
// Return the size of a survivor space if this generation were of size
153147
// gen_size.
154148
size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
@@ -248,13 +242,12 @@ class DefNewGeneration: public Generation {
248242
template <typename OopClosureType>
249243
void oop_since_save_marks_iterate(OopClosureType* cl);
250244

251-
// For non-youngest collection, the DefNewGeneration can contribute
252-
// "to-space".
253-
virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
254-
size_t max_alloc_words);
245+
// For Old collection (part of running Full GC), the DefNewGeneration can
246+
// contribute the free part of "to-space" as the scratch space.
247+
void contribute_scratch(void*& scratch, size_t& num_words);
255248

256249
// Reset for contribution of "to-space".
257-
virtual void reset_scratch();
250+
void reset_scratch();
258251

259252
// GC support
260253
virtual void compute_new_size();

‎src/hotspot/share/gc/serial/genMarkSweep.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "code/icBuffer.hpp"
3434
#include "compiler/oopMap.hpp"
3535
#include "gc/serial/cardTableRS.hpp"
36+
#include "gc/serial/defNewGeneration.hpp"
3637
#include "gc/serial/genMarkSweep.hpp"
3738
#include "gc/serial/serialGcRefProcProxyTask.hpp"
3839
#include "gc/shared/collectedHeap.inline.hpp"
@@ -126,15 +127,13 @@ void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
126127
}
127128

128129
void GenMarkSweep::allocate_stacks() {
129-
GenCollectedHeap* gch = GenCollectedHeap::heap();
130-
// Scratch request on behalf of old generation; will do no allocation.
131-
ScratchBlock* scratch = gch->gather_scratch(gch->old_gen(), 0);
130+
void* scratch = nullptr;
131+
size_t num_words;
132+
DefNewGeneration* young_gen = (DefNewGeneration*)GenCollectedHeap::heap()->young_gen();
133+
young_gen->contribute_scratch(scratch, num_words);
132134

133-
// $$$ To cut a corner, we'll only use the first scratch block, and then
134-
// revert to malloc.
135135
if (scratch != nullptr) {
136-
_preserved_count_max =
137-
scratch->num_words * HeapWordSize / sizeof(PreservedMark);
136+
_preserved_count_max = num_words * HeapWordSize / sizeof(PreservedMark);
138137
} else {
139138
_preserved_count_max = 0;
140139
}
@@ -147,8 +146,10 @@ void GenMarkSweep::allocate_stacks() {
147146

148147

149148
void GenMarkSweep::deallocate_stacks() {
150-
GenCollectedHeap* gch = GenCollectedHeap::heap();
151-
gch->release_scratch();
149+
if (_preserved_count_max != 0) {
150+
DefNewGeneration* young_gen = (DefNewGeneration*)GenCollectedHeap::heap()->young_gen();
151+
young_gen->reset_scratch();
152+
}
152153

153154
_preserved_overflow_stack_set.reclaim();
154155
_marking_stack.clear();

‎src/hotspot/share/gc/shared/genCollectedHeap.cpp

-50
Original file line numberDiff line numberDiff line change
@@ -905,56 +905,6 @@ HeapWord* GenCollectedHeap::allocate_new_tlab(size_t min_size,
905905
return result;
906906
}
907907

908-
// Requires "*prev_ptr" to be non-null. Deletes and a block of minimal size
909-
// from the list headed by "*prev_ptr".
910-
static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) {
911-
bool first = true;
912-
size_t min_size = 0; // "first" makes this conceptually infinite.
913-
ScratchBlock **smallest_ptr, *smallest;
914-
ScratchBlock *cur = *prev_ptr;
915-
while (cur) {
916-
assert(*prev_ptr == cur, "just checking");
917-
if (first || cur->num_words < min_size) {
918-
smallest_ptr = prev_ptr;
919-
smallest = cur;
920-
min_size = smallest->num_words;
921-
first = false;
922-
}
923-
prev_ptr = &cur->next;
924-
cur = cur->next;
925-
}
926-
smallest = *smallest_ptr;
927-
*smallest_ptr = smallest->next;
928-
return smallest;
929-
}
930-
931-
// Sort the scratch block list headed by res into decreasing size order,
932-
// and set "res" to the result.
933-
static void sort_scratch_list(ScratchBlock*& list) {
934-
ScratchBlock* sorted = nullptr;
935-
ScratchBlock* unsorted = list;
936-
while (unsorted) {
937-
ScratchBlock *smallest = removeSmallestScratch(&unsorted);
938-
smallest->next = sorted;
939-
sorted = smallest;
940-
}
941-
list = sorted;
942-
}
943-
944-
ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor,
945-
size_t max_alloc_words) {
946-
ScratchBlock* res = nullptr;
947-
_young_gen->contribute_scratch(res, requestor, max_alloc_words);
948-
_old_gen->contribute_scratch(res, requestor, max_alloc_words);
949-
sort_scratch_list(res);
950-
return res;
951-
}
952-
953-
void GenCollectedHeap::release_scratch() {
954-
_young_gen->reset_scratch();
955-
_old_gen->reset_scratch();
956-
}
957-
958908
void GenCollectedHeap::prepare_for_verify() {
959909
ensure_parsability(false); // no need to retire TLABs
960910
}

‎src/hotspot/share/gc/shared/genCollectedHeap.hpp

-11
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,6 @@ class GenCollectedHeap : public CollectedHeap {
228228
size_t requested_size,
229229
size_t* actual_size) override;
230230

231-
// The "requestor" generation is performing some garbage collection
232-
// action for which it would be useful to have scratch space. The
233-
// requestor promises to allocate no more than "max_alloc_words" in any
234-
// older generation (via promotion say.) Any blocks of space that can
235-
// be provided are returned as a list of ScratchBlocks, sorted by
236-
// decreasing size.
237-
ScratchBlock* gather_scratch(Generation* requestor, size_t max_alloc_words);
238-
// Allow each generation to reset any scratch space that it has
239-
// contributed as it needs.
240-
void release_scratch();
241-
242231
// Ensure parsability
243232
void ensure_parsability(bool retire_tlabs) override;
244233

‎src/hotspot/share/gc/shared/generation.hpp

-16
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,6 @@ class Generation: public CHeapObj<mtGC> {
326326
// generation since the last call to "save_marks".
327327
virtual bool no_allocs_since_save_marks() = 0;
328328

329-
// The "requestor" generation is performing some garbage collection
330-
// action for which it would be useful to have scratch space. If
331-
// the target is not the requestor, no gc actions will be required
332-
// of the target. The requestor promises to allocate no more than
333-
// "max_alloc_words" in the target generation (via promotion say,
334-
// if the requestor is a young generation and the target is older).
335-
// If the target generation can provide any scratch space, it adds
336-
// it to "list", leaving "list" pointing to the head of the
337-
// augmented list. The default is to offer no space.
338-
virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
339-
size_t max_alloc_words) {}
340-
341-
// Give each generation an opportunity to do clean up for any
342-
// contributed scratch.
343-
virtual void reset_scratch() {}
344-
345329
// When an older generation has been collected, and perhaps resized,
346330
// this method will be invoked on all younger generations (from older to
347331
// younger), allowing them to resize themselves as appropriate.

0 commit comments

Comments
 (0)
Please sign in to comment.