8199739: Use HeapAccess when loading oops from static fields in javaClasses.cpp
authorrkennke
Wed, 21 Mar 2018 16:00:41 +0100
changeset 49473 26958d06b585
parent 49472 982acd800812
child 49474 4be016b14e7b
8199739: Use HeapAccess when loading oops from static fields in javaClasses.cpp Reviewed-by: kbarrett, eosterlund
src/hotspot/share/classfile/javaClasses.cpp
src/hotspot/share/jvmci/jvmciJavaClasses.hpp
src/hotspot/share/oops/instanceKlass.cpp
src/hotspot/share/oops/instanceKlass.hpp
--- a/src/hotspot/share/classfile/javaClasses.cpp	Wed Mar 21 12:47:46 2018 +0100
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Wed Mar 21 16:00:41 2018 +0100
@@ -1866,12 +1866,8 @@
 
 oop java_lang_Throwable::unassigned_stacktrace() {
   InstanceKlass* ik = SystemDictionary::Throwable_klass();
-  address addr = ik->static_field_addr(static_unassigned_stacktrace_offset);
-  if (UseCompressedOops) {
-    return oopDesc::load_decode_heap_oop((narrowOop *)addr);
-  } else {
-    return oopDesc::load_decode_heap_oop((oop*)addr);
-  }
+  oop base = ik->static_field_base_raw();
+  return base->obj_field(static_unassigned_stacktrace_offset);
 }
 
 oop java_lang_Throwable::backtrace(oop throwable) {
@@ -3547,14 +3543,14 @@
 
 jlong java_lang_ref_SoftReference::clock() {
   InstanceKlass* ik = SystemDictionary::SoftReference_klass();
-  jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset);
-  return *offset;
+  oop base = ik->static_field_base_raw();
+  return base->long_field(static_clock_offset);
 }
 
 void java_lang_ref_SoftReference::set_clock(jlong value) {
   InstanceKlass* ik = SystemDictionary::SoftReference_klass();
-  jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset);
-  *offset = value;
+  oop base = ik->static_field_base_raw();
+  base->long_field_put(static_clock_offset, value);
 }
 
 // Support for java_lang_invoke_DirectMethodHandle
@@ -4133,12 +4129,8 @@
 
 bool java_lang_System::has_security_manager() {
   InstanceKlass* ik = SystemDictionary::System_klass();
-  address addr = ik->static_field_addr(static_security_offset);
-  if (UseCompressedOops) {
-    return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL;
-  } else {
-    return oopDesc::load_decode_heap_oop((oop*)addr) != NULL;
-  }
+  oop base = ik->static_field_base_raw();
+  return !oopDesc::is_null(base->obj_field(static_security_offset));
 }
 
 int java_lang_Class::_klass_offset;
--- a/src/hotspot/share/jvmci/jvmciJavaClasses.hpp	Wed Mar 21 12:47:46 2018 +0100
+++ b/src/hotspot/share/jvmci/jvmciJavaClasses.hpp	Wed Mar 21 16:00:41 2018 +0100
@@ -353,30 +353,30 @@
     static type name() {                                                                                       \
       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       InstanceKlass* ik = klassName::klass();                                                                  \
-      address addr = ik->static_field_addr(_##name##_offset);                                                  \
-      oop result = HeapAccess<>::oop_load((HeapWord*)addr);                                                    \
+      oop base = ik->static_field_base_raw();                                                                  \
+      oop result = HeapAccess<>::oop_load_at(base, _##name##_offset);                                          \
       return type(result);                                                                                     \
     }                                                                                                          \
     static void set_##name(type x) {                                                                           \
       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       assert(klassName::klass() != NULL, "Class not yet loaded: " #klassName);                                 \
       InstanceKlass* ik = klassName::klass();                                                                  \
-      address addr = ik->static_field_addr(_##name##_offset);                                                  \
-      HeapAccess<>::oop_store((HeapWord*)addr, x);                                                             \
+      oop base = ik->static_field_base_raw();                                                                  \
+      HeapAccess<>::oop_store_at(base, _##name##_offset, x);                                                   \
     }
 #define STATIC_PRIMITIVE_FIELD(klassName, name, jtypename)                                                     \
     static int _##name##_offset;                                                                               \
     static jtypename name() {                                                                                  \
       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       InstanceKlass* ik = klassName::klass();                                                                  \
-      address addr = ik->static_field_addr(_##name##_offset);                                                  \
-      return HeapAccess<>::load((jtypename*)addr);                                                             \
+      oop base = ik->static_field_base_raw();                                                                  \
+      return HeapAccess<>::load_at(base, _##name##_offset);                                                    \
     }                                                                                                          \
     static void set_##name(jtypename x) {                                                                      \
       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       InstanceKlass* ik = klassName::klass();                                                                  \
-      address addr = ik->static_field_addr(_##name##_offset);                                                  \
-      HeapAccess<>::store((jtypename*)addr, x);                                                                \
+      oop base = ik->static_field_base_raw();                                                                  \
+      HeapAccess<>::store_at(base, _##name##_offset, x);                                                       \
     }
 
 #define STATIC_INT_FIELD(klassName, name) STATIC_PRIMITIVE_FIELD(klassName, name, jint)
--- a/src/hotspot/share/oops/instanceKlass.cpp	Wed Mar 21 12:47:46 2018 +0100
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Wed Mar 21 16:00:41 2018 +0100
@@ -2255,12 +2255,6 @@
   }
 }
 
-address InstanceKlass::static_field_addr(int offset) {
-  assert(offset >= InstanceMirrorKlass::offset_of_static_fields(), "has already been adjusted");
-  return (address)(offset + cast_from_oop<intptr_t>(java_mirror()));
-}
-
-
 const char* InstanceKlass::signature_name() const {
   int hash_len = 0;
   char hash_buf[40];
--- a/src/hotspot/share/oops/instanceKlass.hpp	Wed Mar 21 12:47:46 2018 +0100
+++ b/src/hotspot/share/oops/instanceKlass.hpp	Wed Mar 21 16:00:41 2018 +0100
@@ -1070,7 +1070,7 @@
 
   int  itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; }
 
-  address static_field_addr(int offset);
+  oop static_field_base_raw() { return java_mirror(); }
 
   OopMapBlock* start_of_nonstatic_oop_maps() const {
     return (OopMapBlock*)(start_of_itable() + itable_length());