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: stefank, kbarrett, coleenp
  • Loading branch information
xmas92 authored and stefank committed Sep 5, 2022
1 parent e945619 commit 32f4dc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/javaClasses.hpp
Expand Up @@ -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); }
Expand Down
12 changes: 12 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/instanceKlass.inline.hpp"
#include "oops/method.hpp"
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down

1 comment on commit 32f4dc8

@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.