Skip to content

Commit 675d1d5

Browse files
author
Kim Barrett
committed
8256516: Simplify clearing References
Provide and use explicit referent clearing instead of set to null. Reviewed-by: rkennke, shade, pliden, mchung
1 parent ba721f5 commit 675d1d5

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ class java_lang_ref_Reference: AllStatic {
875875
static inline oop weak_referent_no_keepalive(oop ref);
876876
static inline oop phantom_referent_no_keepalive(oop ref);
877877
static inline oop unknown_referent_no_keepalive(oop ref);
878-
static inline void set_referent_raw(oop ref, oop value);
878+
static inline void clear_referent(oop ref);
879879
static inline HeapWord* referent_addr_raw(oop ref);
880880
static inline oop next(oop ref);
881881
static inline void set_next(oop ref, oop value);

src/hotspot/share/classfile/javaClasses.inline.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ oop java_lang_ref_Reference::unknown_referent_no_keepalive(oop ref) {
113113
return ref->obj_field_access<ON_UNKNOWN_OOP_REF | AS_NO_KEEPALIVE>(_referent_offset);
114114
}
115115

116-
void java_lang_ref_Reference::set_referent_raw(oop ref, oop value) {
117-
ref->obj_field_put_raw(_referent_offset, value);
116+
void java_lang_ref_Reference::clear_referent(oop ref) {
117+
ref->obj_field_put_raw(_referent_offset, nullptr);
118118
}
119119

120120
HeapWord* java_lang_ref_Reference::referent_addr_raw(oop ref) {

src/hotspot/share/gc/shared/referenceProcessor.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ void DiscoveredListIterator::load_ptrs(DEBUG_ONLY(bool allow_null_referent)) {
260260
assert(_current_discovered_addr && oopDesc::is_oop_or_null(discovered),
261261
"Expected an oop or NULL for discovered field at " PTR_FORMAT, p2i(discovered));
262262
_next_discovered = discovered;
263-
264-
_referent_addr = java_lang_ref_Reference::referent_addr_raw(_current_discovered);
265263
_referent = java_lang_ref_Reference::unknown_referent_no_keepalive(_current_discovered);
266264
assert(Universe::heap()->is_in_or_null(_referent),
267265
"Wrong oop found in java.lang.Reference object");
@@ -295,8 +293,17 @@ void DiscoveredListIterator::remove() {
295293
_refs_list.dec_length(1);
296294
}
297295

296+
void DiscoveredListIterator::make_referent_alive() {
297+
HeapWord* addr = java_lang_ref_Reference::referent_addr_raw(_current_discovered);
298+
if (UseCompressedOops) {
299+
_keep_alive->do_oop((narrowOop*)addr);
300+
} else {
301+
_keep_alive->do_oop((oop*)addr);
302+
}
303+
}
304+
298305
void DiscoveredListIterator::clear_referent() {
299-
RawAccess<>::oop_store(_referent_addr, oop(NULL));
306+
java_lang_ref_Reference::clear_referent(_current_discovered);
300307
}
301308

302309
void DiscoveredListIterator::enqueue() {

src/hotspot/share/gc/shared/referenceProcessor.hpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class DiscoveredListIterator {
7171
HeapWord* _current_discovered_addr;
7272
oop _next_discovered;
7373

74-
HeapWord* _referent_addr;
7574
oop _referent;
7675

7776
OopClosure* _keep_alive;
@@ -120,14 +119,8 @@ class DiscoveredListIterator {
120119
// Remove the current reference from the list
121120
void remove();
122121

123-
// Make the referent alive.
124-
inline void make_referent_alive() {
125-
if (UseCompressedOops) {
126-
_keep_alive->do_oop((narrowOop*)_referent_addr);
127-
} else {
128-
_keep_alive->do_oop((oop*)_referent_addr);
129-
}
130-
}
122+
// Apply the keep_alive function to the referent address.
123+
void make_referent_alive();
131124

132125
// Do enqueuing work, i.e. notifying the GC about the changed discovered pointers.
133126
void enqueue();

src/hotspot/share/gc/shared/referenceProcessor.inline.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ DiscoveredListIterator::DiscoveredListIterator(DiscoveredList& refs_list,
6161
_current_discovered(refs_list.head()),
6262
_current_discovered_addr(NULL),
6363
_next_discovered(NULL),
64-
_referent_addr(NULL),
6564
_referent(NULL),
6665
_keep_alive(keep_alive),
6766
_is_alive(is_alive),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static oop reference_referent(oop reference) {
8888
return CompressedOops::decode(heap_oop);
8989
}
9090

91-
static void reference_set_referent(oop reference, oop referent) {
92-
java_lang_ref_Reference::set_referent_raw(reference, referent);
91+
static void reference_clear_referent(oop reference) {
92+
java_lang_ref_Reference::clear_referent(reference);
9393
}
9494

9595
template <typename T>
@@ -316,7 +316,7 @@ void ShenandoahReferenceProcessor::make_inactive(oop reference, ReferenceType ty
316316
reference_set_next(reference, reference);
317317
} else {
318318
// Clear referent
319-
reference_set_referent(reference, NULL);
319+
reference_clear_referent(reference);
320320
}
321321
}
322322

@@ -590,4 +590,4 @@ void ShenandoahReferenceProcessor::collect_statistics() {
590590
discovered[REF_SOFT], discovered[REF_WEAK], discovered[REF_FINAL], discovered[REF_PHANTOM]);
591591
log_info(gc,ref)("Enqueued references: Soft: " SIZE_FORMAT ", Weak: " SIZE_FORMAT ", Final: " SIZE_FORMAT ", Phantom: " SIZE_FORMAT,
592592
enqueued[REF_SOFT], enqueued[REF_WEAK], enqueued[REF_FINAL], enqueued[REF_PHANTOM]);
593-
}
593+
}

src/hotspot/share/gc/z/zReferenceProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static oop reference_referent(oop reference) {
7272
return Atomic::load(reference_referent_addr(reference));
7373
}
7474

75-
static void reference_set_referent(oop reference, oop referent) {
76-
java_lang_ref_Reference::set_referent_raw(reference, referent);
75+
static void reference_clear_referent(oop reference) {
76+
java_lang_ref_Reference::clear_referent(reference);
7777
}
7878

7979
static oop* reference_discovered_addr(oop reference) {
@@ -226,7 +226,7 @@ void ZReferenceProcessor::make_inactive(oop reference, ReferenceType type) const
226226
reference_set_next(reference, reference);
227227
} else {
228228
// Clear referent
229-
reference_set_referent(reference, NULL);
229+
reference_clear_referent(reference);
230230
}
231231
}
232232

0 commit comments

Comments
 (0)