From 497f9e760da6342c611a2f542090c5cf4428b9fd Mon Sep 17 00:00:00 2001 From: Tom Rodriguez Date: Mon, 17 Apr 2023 16:45:56 +0000 Subject: [PATCH] 8305755: [JVMCI] missing barriers in CompilerToVM.readFieldValue for Reference.referent Reviewed-by: eosterlund, dnsimon --- src/hotspot/share/jvmci/jvmciCompilerToVM.cpp | 16 +++++++++------- src/hotspot/share/jvmci/jvmciRuntime.cpp | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp index 5811cc3f778..74672c4ee30 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp @@ -2050,14 +2050,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::load(obj->field_addr(displacement)); break; + case T_BYTE: value = HeapAccess::load(obj->field_addr(displacement)); break; + case T_SHORT: value = HeapAccess::load(obj->field_addr(displacement)); break; + case T_CHAR: value = HeapAccess::load(obj->field_addr(displacement)); break; case T_FLOAT: - case T_INT: value = obj->int_field_acquire(displacement); break; + case T_INT: value = HeapAccess::load(obj->field_addr(displacement)); break; case T_DOUBLE: - case T_LONG: value = obj->long_field_acquire(displacement); break; + case T_LONG: value = HeapAccess::load(obj->field_addr(displacement)); break; case T_OBJECT: { if (displacement == java_lang_Class::component_mirror_offset() && java_lang_Class::is_instance(obj()) && @@ -2067,7 +2067,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(displacement); if (value == nullptr) { return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER()); diff --git a/src/hotspot/share/jvmci/jvmciRuntime.cpp b/src/hotspot/share/jvmci/jvmciRuntime.cpp index f93fdddf806..eb1fe403575 100644 --- a/src/hotspot/share/jvmci/jvmciRuntime.cpp +++ b/src/hotspot/share/jvmci/jvmciRuntime.cpp @@ -939,7 +939,9 @@ int JVMCIRuntime::release_cleared_oop_handles() { // Example: to_release: 2 // Bulk release the handles with a null referent - object_handles()->release(_oop_handles.adr_at(num_alive), to_release); + 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);