Blame SOURCES/8165489-pr3589.patch

95d809
# HG changeset patch
95d809
# User mdoerr
95d809
# Date 1473159687 -7200
95d809
#      Tue Sep 06 13:01:27 2016 +0200
95d809
# Node ID 7f6e1069a5719c8908b53774d3560ce851c7cd70
95d809
# Parent  b8fc1e640c4c7f38ca94131279cb67c4d3de6961
95d809
8165489, PR3589: Missing G1 barrier in Unsafe_GetObjectVolatile
95d809
Summary: Add missing barrier, sharing code with Unsafe_GetObject.
95d809
Reviewed-by: kbarrett, mgerdin, pliden, tschatzl
95d809
95d809
diff --git openjdk.orig/hotspot/src/share/vm/prims/unsafe.cpp openjdk/hotspot/src/share/vm/prims/unsafe.cpp
95d809
--- openjdk.orig/hotspot/src/share/vm/prims/unsafe.cpp
95d809
+++ openjdk/hotspot/src/share/vm/prims/unsafe.cpp
95d809
@@ -199,37 +199,40 @@
95d809
 
95d809
 // Get/SetObject must be special-cased, since it works with handles.
95d809
 
95d809
+// We could be accessing the referent field in a reference
95d809
+// object. If G1 is enabled then we need to register non-null
95d809
+// referent with the SATB barrier.
95d809
+
95d809
+#if INCLUDE_ALL_GCS
95d809
+static bool is_java_lang_ref_Reference_access(oop o, jlong offset) {
95d809
+  if (offset == java_lang_ref_Reference::referent_offset && o != NULL) {
95d809
+    Klass* k = o->klass();
95d809
+    if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
95d809
+      assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
95d809
+      return true;
95d809
+    }
95d809
+  }
95d809
+ return false;
95d809
+}
95d809
+#endif
95d809
+
95d809
+static void ensure_satb_referent_alive(oop o, jlong offset, oop v) {
95d809
+#if INCLUDE_ALL_GCS
95d809
+  if (UseG1GC && v != NULL && is_java_lang_ref_Reference_access(o, offset)) {
95d809
+    G1SATBCardTableModRefBS::enqueue(v);
95d809
+  }
95d809
+#endif
95d809
+}
95d809
+
95d809
 // The xxx140 variants for backward compatibility do not allow a full-width offset.
95d809
 UNSAFE_ENTRY(jobject, Unsafe_GetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset))
95d809
   UnsafeWrapper("Unsafe_GetObject");
95d809
   if (obj == NULL)  THROW_0(vmSymbols::java_lang_NullPointerException());
95d809
   GET_OOP_FIELD(obj, offset, v)
95d809
-  jobject ret = JNIHandles::make_local(env, v);
95d809
-#if INCLUDE_ALL_GCS
95d809
-  // We could be accessing the referent field in a reference
95d809
-  // object. If G1 is enabled then we need to register a non-null
95d809
-  // referent with the SATB barrier.
95d809
-  if (UseG1GC) {
95d809
-    bool needs_barrier = false;
95d809
 
95d809
-    if (ret != NULL) {
95d809
-      if (offset == java_lang_ref_Reference::referent_offset) {
95d809
-        oop o = JNIHandles::resolve_non_null(obj);
95d809
-        Klass* k = o->klass();
95d809
-        if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
95d809
-          assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
95d809
-          needs_barrier = true;
95d809
-        }
95d809
-      }
95d809
-    }
95d809
+  ensure_satb_referent_alive(p, offset, v);
95d809
 
95d809
-    if (needs_barrier) {
95d809
-      oop referent = JNIHandles::resolve(ret);
95d809
-      G1SATBCardTableModRefBS::enqueue(referent);
95d809
-    }
95d809
-  }
95d809
-#endif // INCLUDE_ALL_GCS
95d809
-  return ret;
95d809
+  return JNIHandles::make_local(env, v);
95d809
 UNSAFE_END
95d809
 
95d809
 UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h))
95d809
@@ -262,32 +265,10 @@
95d809
 UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset))
95d809
   UnsafeWrapper("Unsafe_GetObject");
95d809
   GET_OOP_FIELD(obj, offset, v)
95d809
-  jobject ret = JNIHandles::make_local(env, v);
95d809
-#if INCLUDE_ALL_GCS
95d809
-  // We could be accessing the referent field in a reference
95d809
-  // object. If G1 is enabled then we need to register non-null
95d809
-  // referent with the SATB barrier.
95d809
-  if (UseG1GC) {
95d809
-    bool needs_barrier = false;
95d809
 
95d809
-    if (ret != NULL) {
95d809
-      if (offset == java_lang_ref_Reference::referent_offset && obj != NULL) {
95d809
-        oop o = JNIHandles::resolve(obj);
95d809
-        Klass* k = o->klass();
95d809
-        if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
95d809
-          assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
95d809
-          needs_barrier = true;
95d809
-        }
95d809
-      }
95d809
-    }
95d809
+  ensure_satb_referent_alive(p, offset, v);
95d809
 
95d809
-    if (needs_barrier) {
95d809
-      oop referent = JNIHandles::resolve(ret);
95d809
-      G1SATBCardTableModRefBS::enqueue(referent);
95d809
-    }
95d809
-  }
95d809
-#endif // INCLUDE_ALL_GCS
95d809
-  return ret;
95d809
+  return JNIHandles::make_local(env, v);
95d809
 UNSAFE_END
95d809
 
95d809
 UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h))
95d809
@@ -312,6 +293,9 @@
95d809
   } else {
95d809
     (void)const_cast<oop&>(v = *(volatile oop*) addr);
95d809
   }
95d809
+
95d809
+  ensure_satb_referent_alive(p, offset, v);
95d809
+
95d809
   OrderAccess::acquire();
95d809
   return JNIHandles::make_local(env, v);
95d809
 UNSAFE_END