Skip to content

Commit ec96b1f

Browse files
committed
8290291: G1: Merge multiple calls of block_size in HeapRegion::block_start
Reviewed-by: tschatzl, iwalulya
1 parent fd4b2f2 commit ec96b1f

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

src/hotspot/share/gc/g1/heapRegion.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,9 @@ class HeapRegion : public CHeapObj<mtGC> {
139139
// This version synchronizes with other calls to par_allocate_impl().
140140
inline HeapWord* par_allocate_impl(size_t min_word_size, size_t desired_word_size, size_t* actual_word_size);
141141

142-
// Return the address of the beginning of the block that contains "addr".
143-
// "q" is a block boundary that is <= "addr"; "n" is the address of the
144-
// next block (or the end of the HeapRegion.)
145-
inline HeapWord* forward_to_block_containing_addr(HeapWord* q, HeapWord* n,
146-
const void* addr,
147-
HeapWord* pb) const;
142+
inline HeapWord* advance_to_block_containing_addr(const void* addr,
143+
HeapWord* const pb,
144+
HeapWord* first_block) const;
148145

149146
static bool obj_is_filler(oop obj);
150147

src/hotspot/share/gc/g1/heapRegion.inline.hpp

+19-24
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,30 @@ inline HeapWord* HeapRegion::par_allocate_impl(size_t min_word_size,
8282
} while (true);
8383
}
8484

85-
inline HeapWord* HeapRegion::forward_to_block_containing_addr(HeapWord* q, HeapWord* n,
86-
const void* addr,
87-
HeapWord* pb) const {
88-
while (n <= addr) {
89-
// When addr is not covered by the block starting at q we need to
90-
// step forward until we find the correct block. With the BOT
91-
// being precise, we should never have to step through more than
92-
// a single card.
93-
assert(!G1BlockOffsetTablePart::is_crossing_card_boundary(n, (HeapWord*)addr), "must be");
94-
q = n;
95-
assert(cast_to_oop(q)->klass_or_null() != nullptr,
96-
"start of block must be an initialized object");
97-
n += block_size(q, pb);
98-
}
99-
assert(q <= addr, "wrong order for q and addr");
100-
assert(addr < n, "wrong order for addr and n");
101-
return q;
102-
}
103-
10485
inline HeapWord* HeapRegion::block_start(const void* addr) const {
10586
return block_start(addr, parsable_bottom_acquire());
10687
}
10788

89+
inline HeapWord* HeapRegion::advance_to_block_containing_addr(const void* addr,
90+
HeapWord* const pb,
91+
HeapWord* first_block) const {
92+
HeapWord* cur_block = first_block;
93+
while (true) {
94+
HeapWord* next_block = cur_block + block_size(cur_block, pb);
95+
if (next_block > addr) {
96+
assert(cur_block <= addr, "postcondition");
97+
return cur_block;
98+
}
99+
cur_block = next_block;
100+
// Because the BOT is precise, we should never step into the next card
101+
// (i.e. crossing the card boundary).
102+
assert(!G1BlockOffsetTablePart::is_crossing_card_boundary(cur_block, (HeapWord*)addr), "must be");
103+
}
104+
}
105+
108106
inline HeapWord* HeapRegion::block_start(const void* addr, HeapWord* const pb) const {
109-
HeapWord* q = _bot_part.block_start_reaching_into_card(addr);
110-
// The returned address is the block that reaches into the card of addr. Walk
111-
// the heap to get to the block reaching into addr.
112-
HeapWord* n = q + block_size(q, pb);
113-
return forward_to_block_containing_addr(q, n, addr, pb);
107+
HeapWord* first_block = _bot_part.block_start_reaching_into_card(addr);
108+
return advance_to_block_containing_addr(addr, pb, first_block);
114109
}
115110

116111
inline bool HeapRegion::obj_in_unparsable_area(oop obj, HeapWord* const pb) {

0 commit comments

Comments
 (0)