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