1.1 --- a/src/share/vm/prims/jni.cpp Tue Apr 05 19:14:03 2011 -0700 1.2 +++ b/src/share/vm/prims/jni.cpp Thu Apr 07 09:53:20 2011 -0700 1.3 @@ -29,6 +29,9 @@ 1.4 #include "classfile/systemDictionary.hpp" 1.5 #include "classfile/vmSymbols.hpp" 1.6 #include "interpreter/linkResolver.hpp" 1.7 +#ifndef SERIALGC 1.8 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 1.9 +#endif // SERIALGC 1.10 #include "memory/allocation.inline.hpp" 1.11 #include "memory/gcLocker.inline.hpp" 1.12 #include "memory/oopFactory.hpp" 1.13 @@ -1724,6 +1727,26 @@ 1.14 o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); 1.15 } 1.16 jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); 1.17 +#ifndef SERIALGC 1.18 + // If G1 is enabled and we are accessing the value of the referent 1.19 + // field in a reference object then we need to register a non-null 1.20 + // referent with the SATB barrier. 1.21 + if (UseG1GC) { 1.22 + bool needs_barrier = false; 1.23 + 1.24 + if (ret != NULL && 1.25 + offset == java_lang_ref_Reference::referent_offset && 1.26 + instanceKlass::cast(k)->reference_type() != REF_NONE) { 1.27 + assert(instanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); 1.28 + needs_barrier = true; 1.29 + } 1.30 + 1.31 + if (needs_barrier) { 1.32 + oop referent = JNIHandles::resolve(ret); 1.33 + G1SATBCardTableModRefBS::enqueue(referent); 1.34 + } 1.35 + } 1.36 +#endif // SERIALGC 1.37 DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); 1.38 return ret; 1.39 JNI_END