Skip to content

Commit 8600d0d

Browse files
committed
8255614: Shenandoah: Consolidate/streamline runtime LRBs
Reviewed-by: zgu
1 parent 9b1eebc commit 8600d0d

File tree

7 files changed

+55
-69
lines changed

7 files changed

+55
-69
lines changed

src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *
175175
}
176176
}
177177

178+
void ShenandoahAsserts::assert_in_heap_or_null(void* interior_loc, oop obj, const char *file, int line) {
179+
ShenandoahHeap* heap = ShenandoahHeap::heap();
180+
181+
if (obj != NULL && !heap->is_in(obj)) {
182+
print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap_or_null failed",
183+
"oop must point to a heap address",
184+
file, line);
185+
}
186+
}
187+
178188
void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
179189
ShenandoahHeap* heap = ShenandoahHeap::heap();
180190

src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ShenandoahAsserts {
5454
const char *file, int line);
5555

5656
static void assert_in_heap(void* interior_loc, oop obj, const char* file, int line);
57+
static void assert_in_heap_or_null(void* interior_loc, oop obj, const char* file, int line);
5758
static void assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line);
5859

5960
static void assert_correct(void* interior_loc, oop obj, const char* file, int line);
@@ -76,6 +77,8 @@ class ShenandoahAsserts {
7677
#ifdef ASSERT
7778
#define shenandoah_assert_in_heap(interior_loc, obj) \
7879
ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__)
80+
#define shenandoah_assert_in_heap_or_null(interior_loc, obj) \
81+
ShenandoahAsserts::assert_in_heap_or_null(interior_loc, obj, __FILE__, __LINE__)
7982
#define shenandoah_assert_in_correct_region(interior_loc, obj) \
8083
ShenandoahAsserts::assert_in_correct_region(interior_loc, obj, __FILE__, __LINE__)
8184

@@ -149,6 +152,7 @@ class ShenandoahAsserts {
149152
ShenandoahAsserts::assert_heaplocked_or_safepoint(__FILE__, __LINE__)
150153
#else
151154
#define shenandoah_assert_in_heap(interior_loc, obj)
155+
#define shenandoah_assert_in_heap_or_null(interior_loc, obj)
152156
#define shenandoah_assert_in_correct_region(interior_loc, obj)
153157

154158
#define shenandoah_assert_correct_if(interior_loc, obj, condition)

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,41 +109,6 @@ bool ShenandoahBarrierSet::need_keep_alive_barrier(DecoratorSet decorators,Basic
109109
return (on_weak_ref || unknown) && keep_alive;
110110
}
111111

112-
oop ShenandoahBarrierSet::load_reference_barrier_not_null(oop obj) {
113-
if (ShenandoahLoadRefBarrier && _heap->has_forwarded_objects()) {
114-
return load_reference_barrier_impl(obj);
115-
} else {
116-
return obj;
117-
}
118-
}
119-
120-
oop ShenandoahBarrierSet::load_reference_barrier(oop obj) {
121-
if (obj != NULL) {
122-
return load_reference_barrier_not_null(obj);
123-
} else {
124-
return obj;
125-
}
126-
}
127-
128-
oop ShenandoahBarrierSet::load_reference_barrier_impl(oop obj) {
129-
assert(ShenandoahLoadRefBarrier, "should be enabled");
130-
if (!CompressedOops::is_null(obj)) {
131-
bool evac_in_progress = _heap->is_evacuation_in_progress();
132-
oop fwd = resolve_forwarded_not_null(obj);
133-
if (evac_in_progress &&
134-
_heap->in_collection_set(obj) &&
135-
obj == fwd) {
136-
Thread *t = Thread::current();
137-
ShenandoahEvacOOMScope oom_evac_scope(t);
138-
return _heap->evacuate_object(obj, t);
139-
} else {
140-
return fwd;
141-
}
142-
} else {
143-
return obj;
144-
}
145-
}
146-
147112
void ShenandoahBarrierSet::on_thread_create(Thread* thread) {
148113
// Create thread local data
149114
ShenandoahThreadLocalData::create(thread);

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class ShenandoahBarrierSet: public BarrierSet {
8787

8888
inline void enqueue(oop obj);
8989

90-
oop load_reference_barrier(oop obj);
91-
oop load_reference_barrier_not_null(oop obj);
90+
inline oop load_reference_barrier(oop obj);
9291

9392
template <class T>
9493
inline oop load_reference_barrier_mutator(oop obj, T* load_addr);
@@ -111,8 +110,6 @@ class ShenandoahBarrierSet: public BarrierSet {
111110
template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
112111
inline void arraycopy_work(T* src, size_t count);
113112

114-
oop load_reference_barrier_impl(oop obj);
115-
116113
inline bool need_bulk_update(HeapWord* dst);
117114
public:
118115
// Callbacks for runtime accesses.

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ inline oop ShenandoahBarrierSet::load_reference_barrier_mutator(oop obj, T* load
7676
return fwd;
7777
}
7878

79+
inline oop ShenandoahBarrierSet::load_reference_barrier(oop obj) {
80+
if (!ShenandoahLoadRefBarrier) {
81+
return obj;
82+
}
83+
if (_heap->has_forwarded_objects() &&
84+
_heap->in_collection_set(obj)) { // Subsumes NULL-check
85+
assert(obj != NULL, "cset check must have subsumed NULL-check");
86+
oop fwd = resolve_forwarded_not_null(obj);
87+
// TODO: It should not be necessary to check evac-in-progress here.
88+
// We do it for mark-compact, which may have forwarded objects,
89+
// and objects in cset and gets here via runtime barriers.
90+
// We can probably fix this as soon as mark-compact has its own
91+
// marking phase.
92+
if (obj == fwd && _heap->is_evacuation_in_progress()) {
93+
Thread* t = Thread::current();
94+
ShenandoahEvacOOMScope oom_evac_scope(t);
95+
return _heap->evacuate_object(obj, t);
96+
}
97+
return fwd;
98+
}
99+
return obj;
100+
}
101+
79102
template <class T>
80103
inline oop ShenandoahBarrierSet::load_reference_barrier_native(oop obj, T* load_addr) {
81104
if (CompressedOops::is_null(obj)) {
@@ -92,7 +115,7 @@ inline oop ShenandoahBarrierSet::load_reference_barrier_native(oop obj, T* load_
92115
}
93116
}
94117

95-
oop fwd = load_reference_barrier_not_null(obj);
118+
oop fwd = load_reference_barrier(obj);
96119
if (ShenandoahSelfFixing && load_addr != NULL && fwd != obj) {
97120
// Since we are here and we know the load address, update the reference.
98121
ShenandoahHeap::cas_oop(fwd, load_addr, obj);
@@ -128,8 +151,7 @@ inline void ShenandoahBarrierSet::satb_barrier(T *field) {
128151
}
129152

130153
inline void ShenandoahBarrierSet::satb_enqueue(oop value) {
131-
assert(value != NULL, "checked before");
132-
if (ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
154+
if (value != NULL && ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
133155
enqueue(value);
134156
}
135157
}
@@ -142,7 +164,6 @@ inline void ShenandoahBarrierSet::storeval_barrier(oop obj) {
142164

143165
inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oop value) {
144166
assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
145-
assert(value != NULL, "checked by caller");
146167
const bool on_strong_oop_ref = (decorators & ON_STRONG_OOP_REF) != 0;
147168
const bool peek = (decorators & AS_NO_KEEPALIVE) != 0;
148169
if (!peek && !on_strong_oop_ref) {
@@ -152,7 +173,6 @@ inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oo
152173

153174
template <DecoratorSet decorators>
154175
inline void ShenandoahBarrierSet::keep_alive_if_weak(oop value) {
155-
assert(value != NULL, "checked by caller");
156176
assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
157177
if (!HasDecorator<decorators, ON_STRONG_OOP_REF>::value &&
158178
!HasDecorator<decorators, AS_NO_KEEPALIVE>::value) {
@@ -167,9 +187,7 @@ inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_loa
167187
if (value != NULL) {
168188
ShenandoahBarrierSet *const bs = ShenandoahBarrierSet::barrier_set();
169189
value = bs->load_reference_barrier_native(value, addr);
170-
if (value != NULL) {
171-
bs->keep_alive_if_weak<decorators>(value);
172-
}
190+
bs->keep_alive_if_weak<decorators>(value);
173191
}
174192
return value;
175193
}
@@ -178,23 +196,19 @@ template <DecoratorSet decorators, typename BarrierSetT>
178196
template <typename T>
179197
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
180198
oop value = Raw::oop_load_in_heap(addr);
181-
if (value != NULL) {
182-
ShenandoahBarrierSet *const bs = ShenandoahBarrierSet::barrier_set();
183-
value = bs->load_reference_barrier_not_null(value);
184-
bs->keep_alive_if_weak<decorators>(value);
185-
}
199+
ShenandoahBarrierSet *const bs = ShenandoahBarrierSet::barrier_set();
200+
value = bs->load_reference_barrier(value);
201+
bs->keep_alive_if_weak<decorators>(value);
186202
return value;
187203
}
188204

189205
template <DecoratorSet decorators, typename BarrierSetT>
190206
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
191207
oop value = Raw::oop_load_in_heap_at(base, offset);
192-
if (value != NULL) {
193-
ShenandoahBarrierSet *const bs = ShenandoahBarrierSet::barrier_set();
194-
value = bs->load_reference_barrier_not_null(value);
195-
bs->keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset),
196-
value);
197-
}
208+
ShenandoahBarrierSet *const bs = ShenandoahBarrierSet::barrier_set();
209+
value = bs->load_reference_barrier(value);
210+
bs->keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset),
211+
value);
198212
return value;
199213
}
200214

@@ -239,10 +253,8 @@ inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_ato
239253

240254
// Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,
241255
// because it must be the previous value.
242-
if (res != NULL) {
243-
res = ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(res);
244-
bs->satb_enqueue(res);
245-
}
256+
res = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(res);
257+
bs->satb_enqueue(res);
246258
return res;
247259
}
248260

@@ -267,10 +279,8 @@ inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_ato
267279

268280
// Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,
269281
// because it must be the previous value.
270-
if (previous != NULL) {
271-
previous = ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(previous);
272-
bs->satb_enqueue(previous);
273-
}
282+
previous = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(previous);
283+
bs->satb_enqueue(previous);
274284
return previous;
275285
}
276286

src/hotspot/share/gc/shenandoah/shenandoahCollectionSet.inline.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ bool ShenandoahCollectionSet::is_in(ShenandoahHeapRegion* r) const {
4040
}
4141

4242
bool ShenandoahCollectionSet::is_in(oop p) const {
43-
shenandoah_assert_in_heap(NULL, p);
43+
shenandoah_assert_in_heap_or_null(NULL, p);
4444
return is_in_loc(cast_from_oop<void*>(p));
4545
}
4646

4747
bool ShenandoahCollectionSet::is_in_loc(void* p) const {
48-
assert(_heap->is_in(p), "Must be in the heap");
48+
assert(p == NULL || _heap->is_in(p), "Must be in the heap");
4949
uintx index = ((uintx) p) >> _region_size_bytes_shift;
5050
// no need to subtract the bottom of the heap from p,
5151
// _biased_cset_map is biased

src/hotspot/share/runtime/stackValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "gc/z/zBarrier.inline.hpp"
3434
#endif
3535
#if INCLUDE_SHENANDOAHGC
36-
#include "gc/shenandoah/shenandoahBarrierSet.hpp"
36+
#include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
3737
#endif
3838

3939
StackValue* StackValue::create_stack_value(const frame* fr, const RegisterMap* reg_map, ScopeValue* sv) {

0 commit comments

Comments
 (0)