8166583: Add oopDesc::klass_or_null_acquire()
authorkbarrett
Fri, 23 Sep 2016 18:23:12 -0400
changeset 41310 28c707fe71ce
parent 41309 88c1272e94d3
child 41311 92d8edabd52c
8166583: Add oopDesc::klass_or_null_acquire() Summary: Added new function. Reviewed-by: dholmes, tschatzl
hotspot/src/share/vm/oops/oop.hpp
hotspot/src/share/vm/oops/oop.inline.hpp
--- a/hotspot/src/share/vm/oops/oop.hpp	Fri Sep 23 13:44:01 2016 -0700
+++ b/hotspot/src/share/vm/oops/oop.hpp	Fri Sep 23 18:23:12 2016 -0400
@@ -83,6 +83,7 @@
 
   inline Klass* klass() const;
   inline Klass* klass_or_null() const volatile;
+  inline Klass* klass_or_null_acquire() const volatile;
   inline Klass** klass_addr();
   inline narrowKlass* compressed_klass_addr();
 
--- a/hotspot/src/share/vm/oops/oop.inline.hpp	Fri Sep 23 13:44:01 2016 -0700
+++ b/hotspot/src/share/vm/oops/oop.inline.hpp	Fri Sep 23 18:23:12 2016 -0400
@@ -109,7 +109,6 @@
 }
 
 Klass* oopDesc::klass_or_null() const volatile {
-  // can be NULL in CMS
   if (UseCompressedClassPointers) {
     return Klass::decode_klass(_metadata._compressed_klass);
   } else {
@@ -117,6 +116,17 @@
   }
 }
 
+Klass* oopDesc::klass_or_null_acquire() const volatile {
+  if (UseCompressedClassPointers) {
+    // Workaround for non-const load_acquire parameter.
+    const volatile narrowKlass* addr = &_metadata._compressed_klass;
+    volatile narrowKlass* xaddr = const_cast<volatile narrowKlass*>(addr);
+    return Klass::decode_klass(OrderAccess::load_acquire(xaddr));
+  } else {
+    return (Klass*)OrderAccess::load_ptr_acquire(&_metadata._klass);
+  }
+}
+
 Klass** oopDesc::klass_addr() {
   // Only used internally and with CMS and will not work with
   // UseCompressedOops