Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[GR-45212] Missing barriers in CompilerToVM.readFieldValue for Refere…
Browse files Browse the repository at this point in the history
…nce.referent

PullRequest: labsjdk-ce-17/110
  • Loading branch information
tkrodriguez committed Apr 14, 2023
2 parents 51a5808 + 97b0336 commit 7eea82d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,14 +2097,14 @@ static jobject read_field_value(Handle obj, long displacement, jchar type_char,
// folding Unsafe.get* methods with volatile semantics.

switch (basic_type) {
case T_BOOLEAN: value = obj->bool_field_acquire(displacement); break;
case T_BYTE: value = obj->byte_field_acquire(displacement); break;
case T_SHORT: value = obj->short_field_acquire(displacement); break;
case T_CHAR: value = obj->char_field_acquire(displacement); break;
case T_BOOLEAN: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jboolean>(displacement)); break;
case T_BYTE: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jbyte>(displacement)); break;
case T_SHORT: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jshort>(displacement)); break;
case T_CHAR: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jchar>(displacement)); break;
case T_FLOAT:
case T_INT: value = obj->int_field_acquire(displacement); break;
case T_INT: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jint>(displacement)); break;
case T_DOUBLE:
case T_LONG: value = obj->long_field_acquire(displacement); break;
case T_LONG: value = HeapAccess<MO_SEQ_CST>::load(obj->field_addr_of_type<jlong>(displacement)); break;

case T_OBJECT: {
if (displacement == java_lang_Class::component_mirror_offset() && java_lang_Class::is_instance(obj()) &&
Expand All @@ -2114,7 +2114,9 @@ static jobject read_field_value(Handle obj, long displacement, jchar type_char,
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
}

oop value = obj->obj_field_acquire(displacement);
// Perform the read including any barriers required to make the reference strongly reachable
// since it will be wrapped as a JavaConstant.
oop value = obj->obj_field_access<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>(displacement);

if (value == nullptr) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,9 @@ int JVMCIRuntime::release_cleared_oop_handles() {
// Example: to_release: 2

// Bulk release the handles with a null referent
if (to_release != 0) {
object_handles()->release(_oop_handles.adr_at(num_alive), to_release);
}

// Truncate oop handles to only those with a non-null referent
JVMCI_event_1("compacted oop handles in JVMCI runtime %d from %d to %d", _id, _oop_handles.length(), num_alive);
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/oops/oop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class oopDesc {
// field addresses in oop
inline void* field_addr(int offset) const;

// Backport of templating version of field_addr
template<typename T>
inline T* field_addr_of_type(int offset) const;

// Need this as public for garbage collection.
template <class T> inline T* obj_field_addr(int offset) const;

Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/oops/oop.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ void* oopDesc::field_addr(int offset) const { return reinterpret_cast<voi
template <class T>
T* oopDesc::obj_field_addr(int offset) const { return (T*) field_addr(offset); }

template<typename T>
T* oopDesc::field_addr_of_type(int offset) const { return reinterpret_cast<T*>(cast_from_oop<intptr_t>(as_oop()) + offset); }

template <typename T>
size_t oopDesc::field_offset(T* p) const { return pointer_delta((void*)p, (void*)this, 1); }

Expand Down

0 comments on commit 7eea82d

Please sign in to comment.