Skip to content

Commit d9d926d

Browse files
committedApr 23, 2024
8330145: Serial: Refactor SerialHeap::scan_evacuated_objs
Reviewed-by: gli, tschatzl
1 parent 1a6da3d commit d9d926d

13 files changed

+34
-154
lines changed
 

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
#include "memory/iterator.inline.hpp"
3232
#include "utilities/align.hpp"
3333

34-
void CardTableRS::scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_mark_word) {
34+
void CardTableRS::scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_top) {
3535
const MemRegion ur = tg->used_region();
36-
const MemRegion urasm = MemRegion(tg->space()->bottom(), saved_mark_word);
36+
const MemRegion urasm = MemRegion(tg->space()->bottom(), saved_top);
3737

3838
assert(ur.contains(urasm),
39-
"Did you forget to call save_marks()? "
4039
"[" PTR_FORMAT ", " PTR_FORMAT ") is not contained in "
4140
"[" PTR_FORMAT ", " PTR_FORMAT ")",
4241
p2i(urasm.start()), p2i(urasm.end()), p2i(ur.start()), p2i(ur.end()));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CardTableRS : public CardTable {
6060
public:
6161
CardTableRS(MemRegion whole_heap);
6262

63-
void scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_mark_word);
63+
void scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_top);
6464

6565
void inline_write_ref_field_gc(void* field) {
6666
CardValue* byte = byte_for(field);

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

+2-21
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "precompiled.hpp"
2626
#include "gc/serial/cardTableRS.hpp"
27-
#include "gc/serial/defNewGeneration.inline.hpp"
2827
#include "gc/serial/serialGcRefProcProxyTask.hpp"
2928
#include "gc/serial/serialHeap.inline.hpp"
3029
#include "gc/serial/serialStringDedup.inline.hpp"
@@ -678,19 +677,13 @@ void DefNewGeneration::collect(bool full,
678677
// The preserved marks should be empty at the start of the GC.
679678
_preserved_marks_set.init(1);
680679

681-
assert(heap->no_allocs_since_save_marks(),
682-
"save marks have not been newly set.");
683-
684680
YoungGenScanClosure young_gen_cl(this);
685681
OldGenScanClosure old_gen_cl(this);
686682

687683
FastEvacuateFollowersClosure evacuate_followers(heap,
688684
&young_gen_cl,
689685
&old_gen_cl);
690686

691-
assert(heap->no_allocs_since_save_marks(),
692-
"save marks have not been newly set.");
693-
694687
{
695688
StrongRootsScope srs(0);
696689
RootScanClosure root_cl{this};
@@ -700,13 +693,14 @@ void DefNewGeneration::collect(bool full,
700693
NMethodToOopClosure::FixRelocations,
701694
false /* keepalive_nmethods */);
702695

696+
HeapWord* saved_top_in_old_gen = _old_gen->space()->top();
703697
heap->process_roots(SerialHeap::SO_ScavengeCodeCache,
704698
&root_cl,
705699
&cld_cl,
706700
&cld_cl,
707701
&code_cl);
708702

709-
_old_gen->scan_old_to_young_refs();
703+
_old_gen->scan_old_to_young_refs(saved_top_in_old_gen);
710704
}
711705

712706
// "evacuate followers".
@@ -723,16 +717,12 @@ void DefNewGeneration::collect(bool full,
723717
_gc_tracer->report_tenuring_threshold(tenuring_threshold());
724718
pt.print_all_references();
725719
}
726-
assert(heap->no_allocs_since_save_marks(), "save marks have not been newly set.");
727720

728721
{
729722
AdjustWeakRootClosure cl{this};
730723
WeakProcessor::weak_oops_do(&is_alive, &cl);
731724
}
732725

733-
// Verify that the usage of keep_alive didn't copy any objects.
734-
assert(heap->no_allocs_since_save_marks(), "save marks have not been newly set.");
735-
736726
_string_dedup_requests.flush();
737727

738728
if (!_promotion_failed) {
@@ -892,15 +882,6 @@ void DefNewGeneration::drain_promo_failure_scan_stack() {
892882
}
893883
}
894884

895-
void DefNewGeneration::save_marks() {
896-
set_saved_mark_word();
897-
}
898-
899-
900-
bool DefNewGeneration::no_allocs_since_save_marks() {
901-
return saved_mark_at_top();
902-
}
903-
904885
void DefNewGeneration::contribute_scratch(void*& scratch, size_t& num_words) {
905886
if (_promotion_failed) {
906887
return;

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

-15
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ class DefNewGeneration: public Generation {
171171
ContiguousSpace* from() const { return _from_space; }
172172
ContiguousSpace* to() const { return _to_space; }
173173

174-
HeapWord* saved_mark_word() const { return _saved_mark_word; }
175-
void set_saved_mark_word() { _saved_mark_word = to()->top(); }
176-
bool saved_mark_at_top() { return _saved_mark_word == _to_space->top(); }
177-
178174
// Space enquiries
179175
size_t capacity() const;
180176
size_t used() const;
@@ -243,17 +239,6 @@ class DefNewGeneration: public Generation {
243239
// Save the tops for eden, from, and to
244240
void record_spaces_top();
245241

246-
// Accessing marks
247-
void save_marks();
248-
249-
bool no_allocs_since_save_marks();
250-
251-
// Need to declare the full complement of closures, whether we'll
252-
// override them or not, or get message from the compiler:
253-
// oop_since_save_marks_iterate_nv hides virtual function...
254-
template <typename OopClosureType>
255-
void oop_since_save_marks_iterate(OopClosureType* cl);
256-
257242
// For Old collection (part of running Full GC), the DefNewGeneration can
258243
// contribute the free part of "to-space" as the scratch space.
259244
void contribute_scratch(void*& scratch, size_t& num_words);

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

-43
This file was deleted.

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

-26
Original file line numberDiff line numberDiff line change
@@ -200,32 +200,6 @@ class Generation: public CHeapObj<mtGC> {
200200
void set_gc_manager(GCMemoryManager* gc_manager) {
201201
_gc_manager = gc_manager;
202202
}
203-
204-
// Apply "blk->do_oop" to the addresses of all reference fields in objects
205-
// starting with the _saved_mark_word, which was noted during a generation's
206-
// save_marks and is required to denote the head of an object.
207-
// Fields in objects allocated by applications of the closure
208-
// *are* included in the iteration.
209-
// Updates saved_mark_word to point to just after the last object iterated over.
210-
template <typename OopClosureType>
211-
void oop_since_save_marks_iterate_impl(OopClosureType* blk, ContiguousSpace* space, HeapWord* saved_mark_word);
212203
};
213204

214-
template <typename OopClosureType>
215-
void Generation::oop_since_save_marks_iterate_impl(OopClosureType* blk, ContiguousSpace* space, HeapWord* saved_mark_word) {
216-
HeapWord* t;
217-
HeapWord* p = saved_mark_word;
218-
assert(p != nullptr, "expected saved mark");
219-
220-
const intx interval = PrefetchScanIntervalInBytes;
221-
do {
222-
t = space->top();
223-
while (p < t) {
224-
Prefetch::write(p, interval);
225-
oop m = cast_to_oop(p);
226-
p += m->oop_iterate_size(blk);
227-
}
228-
} while (t < space->top());
229-
}
230-
231205
#endif // SHARE_GC_SERIAL_GENERATION_HPP

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

-4
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,6 @@ void SerialFullGC::invoke_at_safepoint(bool clear_all_softrefs) {
748748

749749
restore_marks();
750750

751-
// Set saved marks for allocation profiler (and other things? -- dld)
752-
// (Should this be in general part?)
753-
gch->save_marks();
754-
755751
deallocate_stacks();
756752

757753
SerialFullGC::_string_dedup_requests->flush();

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

+24-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "code/codeCache.hpp"
3131
#include "compiler/oopMap.hpp"
3232
#include "gc/serial/cardTableRS.hpp"
33-
#include "gc/serial/defNewGeneration.inline.hpp"
3433
#include "gc/serial/serialFullGC.hpp"
3534
#include "gc/serial/serialHeap.inline.hpp"
3635
#include "gc/serial/serialMemoryPools.hpp"
@@ -757,17 +756,33 @@ void SerialHeap::process_roots(ScanningOption so,
757756
}
758757
}
759758

760-
bool SerialHeap::no_allocs_since_save_marks() {
761-
return _young_gen->no_allocs_since_save_marks() &&
762-
_old_gen->no_allocs_since_save_marks();
759+
template <typename OopClosureType>
760+
static void oop_iterate_from(OopClosureType* blk, ContiguousSpace* space, HeapWord** from) {
761+
assert(*from != nullptr, "precondition");
762+
HeapWord* t;
763+
HeapWord* p = *from;
764+
765+
const intx interval = PrefetchScanIntervalInBytes;
766+
do {
767+
t = space->top();
768+
while (p < t) {
769+
Prefetch::write(p, interval);
770+
p += cast_to_oop(p)->oop_iterate_size(blk);
771+
}
772+
} while (t < space->top());
773+
774+
*from = space->top();
763775
}
764776

765777
void SerialHeap::scan_evacuated_objs(YoungGenScanClosure* young_cl,
766778
OldGenScanClosure* old_cl) {
779+
ContiguousSpace* to_space = young_gen()->to();
767780
do {
768-
young_gen()->oop_since_save_marks_iterate(young_cl);
769-
old_gen()->oop_since_save_marks_iterate(old_cl);
770-
} while (!no_allocs_since_save_marks());
781+
oop_iterate_from(young_cl, to_space, &_young_gen_saved_top);
782+
oop_iterate_from(old_cl, old_gen()->space(), &_old_gen_saved_top);
783+
// Recheck to-space only, because postcondition of oop_iterate_from is no
784+
// unscanned objs
785+
} while (_young_gen_saved_top != to_space->top());
771786
guarantee(young_gen()->promo_failure_scan_is_complete(), "Failed to finish scan");
772787
}
773788

@@ -934,8 +949,8 @@ bool SerialHeap::is_maximal_no_gc() const {
934949
}
935950

936951
void SerialHeap::save_marks() {
937-
_young_gen->save_marks();
938-
_old_gen->save_marks();
952+
_young_gen_saved_top = _young_gen->to()->top();
953+
_old_gen_saved_top = _old_gen->space()->top();
939954
}
940955

941956
void SerialHeap::verify(VerifyOption option /* ignored */) {

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class SerialHeap : public CollectedHeap {
8585
private:
8686
DefNewGeneration* _young_gen;
8787
TenuredGeneration* _old_gen;
88-
88+
HeapWord* _young_gen_saved_top;
89+
HeapWord* _old_gen_saved_top;
8990
private:
9091
// The singleton CardTable Remembered Set.
9192
CardTableRS* _rem_set;
@@ -279,10 +280,6 @@ class SerialHeap : public CollectedHeap {
279280
// in other generations, it should call this method.
280281
void save_marks();
281282

282-
// Returns "true" iff no allocations have occurred since the last
283-
// call to "save_marks".
284-
bool no_allocs_since_save_marks();
285-
286283
// Returns true if an incremental collection is likely to fail.
287284
// We optionally consult the young gen, if asked to do so;
288285
// otherwise we base our answer on whether the previous incremental

‎src/hotspot/share/gc/serial/serialHeap.inline.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include "gc/serial/serialHeap.hpp"
2929

30-
#include "gc/serial/defNewGeneration.inline.hpp"
3130
#include "gc/serial/tenuredGeneration.inline.hpp"
3231

3332
class ScavengeHelper {

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ HeapWord* TenuredGeneration::block_start(const void* addr) const {
280280
}
281281
}
282282

283-
void TenuredGeneration::scan_old_to_young_refs() {
284-
_rs->scan_old_to_young_refs(this, saved_mark_word());
283+
void TenuredGeneration::scan_old_to_young_refs(HeapWord* saved_top_in_old_gen) {
284+
_rs->scan_old_to_young_refs(this, saved_top_in_old_gen);
285285
}
286286

287287
TenuredGeneration::TenuredGeneration(ReservedSpace rs,
@@ -504,14 +504,6 @@ void TenuredGeneration::complete_loaded_archive_space(MemRegion archive_space) {
504504
}
505505
}
506506

507-
void TenuredGeneration::save_marks() {
508-
set_saved_mark_word();
509-
}
510-
511-
bool TenuredGeneration::no_allocs_since_save_marks() {
512-
return saved_mark_at_top();
513-
}
514-
515507
void TenuredGeneration::gc_epilogue() {
516508
// update the generation and space performance counters
517509
update_counters();

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class TenuredGeneration: public Generation {
9090

9191
TenuredSpace* space() const { return _the_space; }
9292
HeapWord* saved_mark_word() const { return _saved_mark_word; }
93-
void set_saved_mark_word() { _saved_mark_word = _the_space->top(); }
94-
bool saved_mark_at_top() { return _saved_mark_word == space()->top(); }
9593

9694
// Grow generation with specified size (returns false if unable to grow)
9795
bool grow_by(size_t bytes);
@@ -114,7 +112,7 @@ class TenuredGeneration: public Generation {
114112

115113
HeapWord* block_start(const void* addr) const;
116114

117-
void scan_old_to_young_refs();
115+
void scan_old_to_young_refs(HeapWord* saved_top_in_old_gen);
118116

119117
bool is_in(const void* p) const;
120118

@@ -139,13 +137,6 @@ class TenuredGeneration: public Generation {
139137
virtual inline HeapWord* allocate(size_t word_size, bool is_tlab);
140138
virtual inline HeapWord* par_allocate(size_t word_size, bool is_tlab);
141139

142-
template <typename OopClosureType>
143-
void oop_since_save_marks_iterate(OopClosureType* cl);
144-
145-
void save_marks();
146-
147-
bool no_allocs_since_save_marks();
148-
149140
virtual void collect(bool full,
150141
bool clear_all_soft_refs,
151142
size_t size,

‎src/hotspot/share/gc/serial/tenuredGeneration.inline.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,4 @@ HeapWord* TenuredGeneration::par_allocate(size_t word_size,
6161
return _the_space->par_allocate(word_size);
6262
}
6363

64-
template <typename OopClosureType>
65-
void TenuredGeneration::oop_since_save_marks_iterate(OopClosureType* blk) {
66-
Generation::oop_since_save_marks_iterate_impl(blk, _the_space, _saved_mark_word);
67-
set_saved_mark_word();
68-
}
69-
7064
#endif // SHARE_GC_SERIAL_TENUREDGENERATION_INLINE_HPP

0 commit comments

Comments
 (0)
Please sign in to comment.