< prev index next >

src/share/vm/prims/jni.cpp

Print this page
rev 14282 : Factor out keep-alive barrier from usual pre-barrier implementations.


  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/orderAccess.inline.hpp"
  72 #include "runtime/reflection.hpp"
  73 #include "runtime/sharedRuntime.hpp"
  74 #include "runtime/signature.hpp"
  75 #include "runtime/thread.inline.hpp"
  76 #include "runtime/vm_operations.hpp"
  77 #include "services/memTracker.hpp"
  78 #include "services/runtimeService.hpp"
  79 #include "trace/traceMacros.hpp"
  80 #include "trace/tracing.hpp"
  81 #include "utilities/defaultStream.hpp"
  82 #include "utilities/dtrace.hpp"
  83 #include "utilities/events.hpp"
  84 #include "utilities/histogram.hpp"
  85 #include "utilities/internalVMTests.hpp"
  86 #include "utilities/macros.hpp"
  87 #include "utilities/vmError.hpp"
  88 #if INCLUDE_ALL_GCS
  89 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  90 #endif // INCLUDE_ALL_GCS
  91 #if INCLUDE_JVMCI
  92 #include "jvmci/jvmciCompiler.hpp"
  93 #include "jvmci/jvmciRuntime.hpp"
  94 #endif
  95 
  96 static jint CurrentVersion = JNI_VERSION_9;
  97 
  98 #ifdef _WIN32
  99 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
 100 #endif
 101 
 102 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 103 // '-return' probe regardless of the return path is taken out of the function.
 104 // Methods that have multiple return paths use this to avoid having to
 105 // instrument each return path.  Methods that use CHECK or THROW must use this
 106 // since those macros can cause an immedate uninstrumented return.
 107 //
 108 // In order to get the return value, a reference to the variable containing
 109 // the return value must be passed to the contructor of the object, and
 110 // the return value must be set before return (since the mark object has


2060   return ret;
2061 JNI_END
2062 
2063 
2064 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2065   JNIWrapper("GetObjectField");
2066   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
2067   oop o = JNIHandles::resolve_non_null(obj);
2068   Klass* k = o->klass();
2069   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2070   // Keep JVMTI addition small and only check enabled flag here.
2071   // jni_GetField_probe() assumes that is okay to create handles.
2072   if (JvmtiExport::should_post_field_access()) {
2073     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2074   }
2075   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2076 #if INCLUDE_ALL_GCS
2077   // If G1 is enabled and we are accessing the value of the referent
2078   // field in a reference object then we need to register a non-null
2079   // referent with the SATB barrier.
2080   if (UseG1GC || (UseShenandoahGC && ShenandoahWriteBarrier)) {
2081     bool needs_barrier = false;
2082 
2083     if (ret != NULL &&
2084         offset == java_lang_ref_Reference::referent_offset &&
2085         InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2086       assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2087       needs_barrier = true;
2088     }
2089 
2090     if (needs_barrier) {
2091       oop referent = JNIHandles::resolve(ret);
2092       G1SATBCardTableModRefBS::enqueue(referent);
2093     }
2094   }
2095 #endif // INCLUDE_ALL_GCS
2096 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
2097   return ret;
2098 JNI_END
2099 
2100 
2101 
2102 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2103   , EntryProbe, ReturnProbe) \
2104 \
2105   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2106   , ReturnProbe); \
2107 \
2108 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2109   JNIWrapper("Get" XSTR(Result) "Field"); \
2110 \
2111   EntryProbe; \
2112   Return ret = 0;\
2113   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\




  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/orderAccess.inline.hpp"
  72 #include "runtime/reflection.hpp"
  73 #include "runtime/sharedRuntime.hpp"
  74 #include "runtime/signature.hpp"
  75 #include "runtime/thread.inline.hpp"
  76 #include "runtime/vm_operations.hpp"
  77 #include "services/memTracker.hpp"
  78 #include "services/runtimeService.hpp"
  79 #include "trace/traceMacros.hpp"
  80 #include "trace/tracing.hpp"
  81 #include "utilities/defaultStream.hpp"
  82 #include "utilities/dtrace.hpp"
  83 #include "utilities/events.hpp"
  84 #include "utilities/histogram.hpp"
  85 #include "utilities/internalVMTests.hpp"
  86 #include "utilities/macros.hpp"
  87 #include "utilities/vmError.hpp"



  88 #if INCLUDE_JVMCI
  89 #include "jvmci/jvmciCompiler.hpp"
  90 #include "jvmci/jvmciRuntime.hpp"
  91 #endif
  92 
  93 static jint CurrentVersion = JNI_VERSION_9;
  94 
  95 #ifdef _WIN32
  96 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
  97 #endif
  98 
  99 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 100 // '-return' probe regardless of the return path is taken out of the function.
 101 // Methods that have multiple return paths use this to avoid having to
 102 // instrument each return path.  Methods that use CHECK or THROW must use this
 103 // since those macros can cause an immedate uninstrumented return.
 104 //
 105 // In order to get the return value, a reference to the variable containing
 106 // the return value must be passed to the contructor of the object, and
 107 // the return value must be set before return (since the mark object has


2057   return ret;
2058 JNI_END
2059 
2060 
2061 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2062   JNIWrapper("GetObjectField");
2063   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
2064   oop o = JNIHandles::resolve_non_null(obj);
2065   Klass* k = o->klass();
2066   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2067   // Keep JVMTI addition small and only check enabled flag here.
2068   // jni_GetField_probe() assumes that is okay to create handles.
2069   if (JvmtiExport::should_post_field_access()) {
2070     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2071   }
2072   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2073 #if INCLUDE_ALL_GCS
2074   // If G1 is enabled and we are accessing the value of the referent
2075   // field in a reference object then we need to register a non-null
2076   // referent with the SATB barrier.

2077   bool needs_barrier = false;
2078 
2079   if (ret != NULL &&
2080       offset == java_lang_ref_Reference::referent_offset &&
2081       InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2082     assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2083     needs_barrier = true;
2084   }
2085 
2086   if (needs_barrier) {
2087     oop referent = JNIHandles::resolve(ret);
2088     oopDesc::bs()->keep_alive_barrier(referent);

2089   }
2090 #endif // INCLUDE_ALL_GCS
2091 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
2092   return ret;
2093 JNI_END
2094 
2095 
2096 
2097 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2098   , EntryProbe, ReturnProbe) \
2099 \
2100   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2101   , ReturnProbe); \
2102 \
2103 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2104   JNIWrapper("Get" XSTR(Result) "Field"); \
2105 \
2106   EntryProbe; \
2107   Return ret = 0;\
2108   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\


< prev index next >