8293295: Add type check asserts to java_lang_ref_Reference accessors

Reviewed-by: stefank, kbarrett, coleenp
This commit is contained in:
Axel Boldt-Christmas 2022-09-05 08:34:13 +00:00 committed by Stefan Karlsson
parent e945619ddd
commit 32f4dc8403
2 changed files with 14 additions and 0 deletions
src/hotspot/share/classfile

@ -988,6 +988,8 @@ class java_lang_ref_Reference: AllStatic {
static bool is_referent_field(oop obj, ptrdiff_t offset);
static inline bool is_final(oop ref);
static inline bool is_phantom(oop ref);
static inline bool is_weak(oop ref);
static inline bool is_soft(oop ref);
static int referent_offset() { CHECK_INIT(_referent_offset); }
static int queue_offset() { CHECK_INIT(_queue_offset); }

@ -27,6 +27,7 @@
#include "classfile/javaClasses.hpp"
#include "memory/referenceType.hpp"
#include "oops/access.inline.hpp"
#include "oops/instanceKlass.inline.hpp"
#include "oops/method.hpp"
@ -132,14 +133,17 @@ bool java_lang_String::is_instance(oop obj) {
// Accessors
oop java_lang_ref_Reference::weak_referent_no_keepalive(oop ref) {
assert(java_lang_ref_Reference::is_weak(ref) || java_lang_ref_Reference::is_soft(ref), "must be Weak or Soft Reference");
return ref->obj_field_access<ON_WEAK_OOP_REF | AS_NO_KEEPALIVE>(_referent_offset);
}
oop java_lang_ref_Reference::weak_referent(oop ref) {
assert(java_lang_ref_Reference::is_weak(ref) || java_lang_ref_Reference::is_soft(ref), "must be Weak or Soft Reference");
return ref->obj_field_access<ON_WEAK_OOP_REF>(_referent_offset);
}
oop java_lang_ref_Reference::phantom_referent_no_keepalive(oop ref) {
assert(java_lang_ref_Reference::is_phantom(ref), "must be Phantom Reference");
return ref->obj_field_access<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>(_referent_offset);
}
@ -195,6 +199,14 @@ bool java_lang_ref_Reference::is_phantom(oop ref) {
return InstanceKlass::cast(ref->klass())->reference_type() == REF_PHANTOM;
}
bool java_lang_ref_Reference::is_weak(oop ref) {
return InstanceKlass::cast(ref->klass())->reference_type() == REF_WEAK;
}
bool java_lang_ref_Reference::is_soft(oop ref) {
return InstanceKlass::cast(ref->klass())->reference_type() == REF_SOFT;
}
inline oop java_lang_Thread::continuation(oop java_thread) {
return java_thread->obj_field(_continuation_offset);
}