Skip to content

Commit

Permalink
8330006: Serial: Extract out ContiguousSpace::block_start_const
Browse files Browse the repository at this point in the history
Reviewed-by: ayang, tschatzl
  • Loading branch information
lgxbslgx committed Apr 12, 2024
1 parent 2c8b432 commit c7fcd62
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 58 deletions.
12 changes: 6 additions & 6 deletions src/hotspot/share/gc/serial/cardTableRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#include "memory/iterator.inline.hpp"
#include "utilities/align.hpp"

void CardTableRS::scan_old_to_young_refs(TenuredSpace* sp, HeapWord* saved_mark_word) {
const MemRegion ur = sp->used_region();
const MemRegion urasm = MemRegion(sp->bottom(), saved_mark_word);
void CardTableRS::scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_mark_word) {
const MemRegion ur = tg->used_region();
const MemRegion urasm = MemRegion(tg->space()->bottom(), saved_mark_word);

assert(ur.contains(urasm),
"Did you forget to call save_marks()? "
Expand All @@ -43,7 +43,7 @@ void CardTableRS::scan_old_to_young_refs(TenuredSpace* sp, HeapWord* saved_mark_

if (!urasm.is_empty()) {
OldGenScanClosure cl(SerialHeap::heap()->young_gen());
non_clean_card_iterate(sp, urasm, &cl);
non_clean_card_iterate(tg, urasm, &cl);
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ static void scan_obj_with_limit(oop obj,
}
}

void CardTableRS::non_clean_card_iterate(TenuredSpace* sp,
void CardTableRS::non_clean_card_iterate(TenuredGeneration* tg,
MemRegion mr,
OldGenScanClosure* cl) {
struct {
Expand All @@ -238,7 +238,7 @@ void CardTableRS::non_clean_card_iterate(TenuredSpace* sp,
assert(cached_obj.start_addr != nullptr, "inv");
return cached_obj.start_addr;
}
HeapWord* result = sp->block_start_const(addr);
HeapWord* result = tg->block_start(addr);

cached_obj.start_addr = result;
cached_obj.end_addr = result + cast_to_oop(result)->size();
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/serial/cardTableRS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CardTableRS : public CardTable {
public:
CardTableRS(MemRegion whole_heap);

void scan_old_to_young_refs(TenuredSpace* sp, HeapWord* saved_mark_word);
void scan_old_to_young_refs(TenuredGeneration* tg, HeapWord* saved_mark_word);

void inline_write_ref_field_gc(void* field) {
CardValue* byte = byte_for(field);
Expand All @@ -83,7 +83,7 @@ class CardTableRS : public CardTable {
// Iterate over the portion of the card-table which covers the given
// region mr in the given space and apply cl to any dirty sub-regions
// of mr. Clears the dirty cards as they are processed.
void non_clean_card_iterate(TenuredSpace* sp,
void non_clean_card_iterate(TenuredGeneration* tg,
MemRegion mr,
OldGenScanClosure* cl);

Expand Down
29 changes: 26 additions & 3 deletions src/hotspot/share/gc/serial/defNewGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,38 @@ void DefNewGeneration::object_iterate(ObjectClosure* blk) {
from()->object_iterate(blk);
}

// If "p" is in the space, returns the address of the start of the
// "block" that contains "p". We say "block" instead of "object" since
// some heaps may not pack objects densely; a chunk may either be an
// object or a non-object. If "p" is not in the space, return null.
// Very general, slow implementation.
static HeapWord* block_start_const(const ContiguousSpace* cs, const void* p) {
assert(MemRegion(cs->bottom(), cs->end()).contains(p),
"p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
p2i(p), p2i(cs->bottom()), p2i(cs->end()));
if (p >= cs->top()) {
return cs->top();
} else {
HeapWord* last = cs->bottom();
HeapWord* cur = last;
while (cur <= p) {
last = cur;
cur += cast_to_oop(cur)->size();
}
assert(oopDesc::is_oop(cast_to_oop(last)), PTR_FORMAT " should be an object start", p2i(last));
return last;
}
}

HeapWord* DefNewGeneration::block_start(const void* p) const {
if (eden()->is_in_reserved(p)) {
return eden()->block_start_const(p);
return block_start_const(eden(), p);
}
if (from()->is_in_reserved(p)) {
return from()->block_start_const(p);
return block_start_const(from(), p);
}
assert(to()->is_in_reserved(p), "inv");
return to()->block_start_const(p);
return block_start_const(to(), p);
}

// The last collection bailed out, we are running out of heap space,
Expand Down
18 changes: 15 additions & 3 deletions src/hotspot/share/gc/serial/tenuredGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,24 @@ void TenuredGeneration::compute_new_size_inner() {
}
}

HeapWord* TenuredGeneration::block_start(const void* p) const {
return space()->block_start_const(p);
HeapWord* TenuredGeneration::block_start(const void* addr) const {
HeapWord* cur_block = _bts->block_start_reaching_into_card(addr);

while (true) {
HeapWord* next_block = cur_block + cast_to_oop(cur_block)->size();
if (next_block > addr) {
assert(cur_block <= addr, "postcondition");
return cur_block;
}
cur_block = next_block;
// Because the BOT is precise, we should never step into the next card
// (i.e. crossing the card boundary).
assert(!SerialBlockOffsetTable::is_crossing_card_boundary(cur_block, (HeapWord*)addr), "must be");
}
}

void TenuredGeneration::scan_old_to_young_refs() {
_rs->scan_old_to_young_refs(space(), saved_mark_word());
_rs->scan_old_to_young_refs(this, saved_mark_word());
}

TenuredGeneration::TenuredGeneration(ReservedSpace rs,
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/serial/tenuredGeneration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TenuredGeneration: public Generation {
return _virtual_space.uncommitted_size() == 0;
}

HeapWord* block_start(const void* p) const;
HeapWord* block_start(const void* addr) const;

void scan_old_to_young_refs();

Expand Down
35 changes: 0 additions & 35 deletions src/hotspot/share/gc/shared/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,6 @@ void ContiguousSpace::object_iterate(ObjectClosure* blk) {
}
}

// Very general, slow implementation.
HeapWord* ContiguousSpace::block_start_const(const void* p) const {
assert(MemRegion(bottom(), end()).contains(p),
"p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
p2i(p), p2i(bottom()), p2i(end()));
if (p >= top()) {
return top();
} else {
HeapWord* last = bottom();
HeapWord* cur = last;
while (cur <= p) {
last = cur;
cur += cast_to_oop(cur)->size();
}
assert(oopDesc::is_oop(cast_to_oop(last)), PTR_FORMAT " should be an object start", p2i(last));
return last;
}
}

// This version requires locking.
inline HeapWord* ContiguousSpace::allocate_impl(size_t size) {
assert(Heap_lock->owned_by_self() ||
Expand Down Expand Up @@ -191,22 +172,6 @@ HeapWord* ContiguousSpace::par_allocate(size_t size) {
}

#if INCLUDE_SERIALGC
HeapWord* TenuredSpace::block_start_const(const void* addr) const {
HeapWord* cur_block = _offsets->block_start_reaching_into_card(addr);

while (true) {
HeapWord* next_block = cur_block + cast_to_oop(cur_block)->size();
if (next_block > addr) {
assert(cur_block <= addr, "postcondition");
return cur_block;
}
cur_block = next_block;
// Because the BOT is precise, we should never step into the next card
// (i.e. crossing the card boundary).
assert(!SerialBlockOffsetTable::is_crossing_card_boundary(cur_block, (HeapWord*)addr), "must be");
}
}

TenuredSpace::TenuredSpace(SerialBlockOffsetTable* offsets,
MemRegion mr) :
_offsets(offsets)
Expand Down
8 changes: 0 additions & 8 deletions src/hotspot/share/gc/shared/space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ class ContiguousSpace: public CHeapObj<mtGC> {
// Iteration
void object_iterate(ObjectClosure* blk);

// If "p" is in the space, returns the address of the start of the
// "block" that contains "p". We say "block" instead of "object" since
// some heaps may not pack objects densely; a chunk may either be an
// object or a non-object. If "p" is not in the space, return null.
virtual HeapWord* block_start_const(const void* p) const;

// Addresses for inlined allocation
HeapWord** top_addr() { return &_top; }

Expand All @@ -197,8 +191,6 @@ class TenuredSpace: public ContiguousSpace {
TenuredSpace(SerialBlockOffsetTable* offsets,
MemRegion mr);

HeapWord* block_start_const(const void* addr) const override;

// Add offset table update.
inline HeapWord* allocate(size_t word_size) override;
inline HeapWord* par_allocate(size_t word_size) override;
Expand Down

1 comment on commit c7fcd62

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.