Skip to content

Commit

Permalink
8293295: Add type check asserts to java_lang_ref_Reference accessors
Browse files Browse the repository at this point in the history
Reviewed-by: phh
Backport-of: 32f4dc84037696f664114e40357bca66337c6178
  • Loading branch information
shipilev committed May 30, 2023
1 parent 213d0db commit bc78e07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/javaClasses.hpp
Expand Up @@ -925,6 +925,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); }
Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/share/classfile/javaClasses.inline.hpp
Expand Up @@ -27,6 +27,7 @@

#include "classfile/javaClasses.hpp"

#include "memory/referenceType.hpp"
#include "oops/access.inline.hpp"
#include "oops/method.hpp"
#include "oops/oop.inline.hpp"
Expand Down Expand Up @@ -130,10 +131,12 @@ bool java_lang_String::is_instance_inlined(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::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);
}

Expand Down Expand Up @@ -189,6 +192,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 void java_lang_invoke_CallSite::set_target_volatile(oop site, oop target) {
site->obj_field_put_volatile(_target_offset, target);
}
Expand Down

1 comment on commit bc78e07

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.