8227085: ZGC: Add on_weak load barrier verification

Reviewed-by: eosterlund
This commit is contained in:
Stefan Karlsson 2019-07-02 12:24:28 +02:00
parent e632ccd508
commit 53fefe466c
2 changed files with 22 additions and 0 deletions

View File

@ -24,10 +24,12 @@
#ifndef SHARE_GC_Z_ZBARRIER_INLINE_HPP
#define SHARE_GC_Z_ZBARRIER_INLINE_HPP
#include "classfile/javaClasses.hpp"
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zBarrier.hpp"
#include "gc/z/zOop.inline.hpp"
#include "gc/z/zResurrection.inline.hpp"
#include "oops/oop.hpp"
#include "runtime/atomic.hpp"
template <ZBarrierFastPath fast_path, ZBarrierSlowPath slow_path>
@ -173,7 +175,21 @@ inline void ZBarrier::load_barrier_on_oop_array(volatile oop* p, size_t length)
}
}
// ON_WEAK barriers should only ever be applied to j.l.r.Reference.referents.
inline void verify_on_weak(volatile oop* referent_addr) {
#ifdef ASSERT
if (referent_addr != NULL) {
uintptr_t base = (uintptr_t)referent_addr - java_lang_ref_Reference::referent_offset;
oop obj = cast_to_oop(base);
assert(oopDesc::is_oop(obj), "Verification failed for: ref " PTR_FORMAT " obj: " PTR_FORMAT, (uintptr_t)referent_addr, base);
assert(java_lang_ref_Reference::is_referent_field(obj, java_lang_ref_Reference::referent_offset), "Sanity");
}
#endif
}
inline oop ZBarrier::load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o) {
verify_on_weak(p);
if (is_resurrection_blocked(p, &o)) {
return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
}
@ -217,6 +233,8 @@ inline oop ZBarrier::weak_load_barrier_on_weak_oop_field(volatile oop* p) {
}
inline oop ZBarrier::weak_load_barrier_on_weak_oop_field_preloaded(volatile oop* p, oop o) {
verify_on_weak(p);
if (is_resurrection_blocked(p, &o)) {
return weak_barrier<is_good_or_null_fast_path, weak_load_barrier_on_weak_oop_slow_path>(p, o);
}

View File

@ -62,6 +62,7 @@ inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::load_barrier_on_
} else if (HasDecorator<decorators, ON_WEAK_OOP_REF>::value) {
return ZBarrier::weak_load_barrier_on_weak_oop_field_preloaded(addr, o);
} else {
assert((HasDecorator<decorators, ON_PHANTOM_OOP_REF>::value), "Must be");
return ZBarrier::weak_load_barrier_on_phantom_oop_field_preloaded(addr, o);
}
} else {
@ -70,6 +71,7 @@ inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::load_barrier_on_
} else if (HasDecorator<decorators, ON_WEAK_OOP_REF>::value) {
return ZBarrier::load_barrier_on_weak_oop_field_preloaded(addr, o);
} else {
assert((HasDecorator<decorators, ON_PHANTOM_OOP_REF>::value), "Must be");
return ZBarrier::load_barrier_on_phantom_oop_field_preloaded(addr, o);
}
}
@ -89,6 +91,7 @@ inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::load_barrier_on_
} else if (decorators_known_strength & ON_WEAK_OOP_REF) {
return ZBarrier::weak_load_barrier_on_weak_oop_field_preloaded(addr, o);
} else {
assert(decorators_known_strength & ON_PHANTOM_OOP_REF, "Must be");
return ZBarrier::weak_load_barrier_on_phantom_oop_field_preloaded(addr, o);
}
} else {
@ -97,6 +100,7 @@ inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::load_barrier_on_
} else if (decorators_known_strength & ON_WEAK_OOP_REF) {
return ZBarrier::load_barrier_on_weak_oop_field_preloaded(addr, o);
} else {
assert(decorators_known_strength & ON_PHANTOM_OOP_REF, "Must be");
return ZBarrier::load_barrier_on_phantom_oop_field_preloaded(addr, o);
}
}