< prev index next >

src/share/vm/prims/jni.cpp

Print this page
rev 12906 : [mq]: gc_interface


  33 #include "classfile/modules.hpp"
  34 #include "classfile/symbolTable.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/vmSymbols.hpp"
  37 #include "gc/shared/gcLocker.inline.hpp"
  38 #include "interpreter/linkResolver.hpp"
  39 #include "memory/allocation.hpp"
  40 #include "memory/allocation.inline.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.inline.hpp"
  44 #include "oops/instanceKlass.hpp"
  45 #include "oops/instanceOop.hpp"
  46 #include "oops/markOop.hpp"
  47 #include "oops/method.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/symbol.hpp"
  52 #include "oops/typeArrayKlass.hpp"
  53 #include "oops/typeArrayOop.hpp"
  54 #include "prims/jni.h"
  55 #include "prims/jniCheck.hpp"
  56 #include "prims/jniExport.hpp"
  57 #include "prims/jniFastGetField.hpp"
  58 #include "prims/jvm.h"
  59 #include "prims/jvm_misc.hpp"
  60 #include "prims/jvmtiExport.hpp"
  61 #include "prims/jvmtiThreadState.hpp"

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


2041   }
2042 
2043   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
2044   // It may also have hash bits for k, if VerifyJNIFields is turned on.
2045   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
2046   return ret;
2047 JNI_END
2048 
2049 
2050 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2051   JNIWrapper("GetObjectField");
2052   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
2053   oop o = JNIHandles::resolve_non_null(obj);
2054   Klass* k = o->klass();
2055   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2056   // Keep JVMTI addition small and only check enabled flag here.
2057   // jni_GetField_probe() assumes that is okay to create handles.
2058   if (JvmtiExport::should_post_field_access()) {
2059     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2060   }
2061   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2062 #if INCLUDE_ALL_GCS
2063   // If G1 is enabled and we are accessing the value of the referent
2064   // field in a reference object then we need to register a non-null
2065   // referent with the SATB barrier.
2066   if (UseG1GC) {
2067     bool needs_barrier = false;
2068 
2069     if (ret != NULL &&
2070         offset == java_lang_ref_Reference::referent_offset &&
2071         InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2072       assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2073       needs_barrier = true;
2074     }
2075 
2076     if (needs_barrier) {
2077       oop referent = JNIHandles::resolve(ret);
2078       G1SATBCardTableModRefBS::enqueue(referent);
2079     }
2080   }
2081 #endif // INCLUDE_ALL_GCS
2082 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
2083   return ret;
2084 JNI_END
2085 
2086 
2087 
2088 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2089   , EntryProbe, ReturnProbe) \
2090 \
2091   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2092   , ReturnProbe); \
2093 \
2094 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2095   JNIWrapper("Get" XSTR(Result) "Field"); \
2096 \
2097   EntryProbe; \
2098   Return ret = 0;\
2099   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
2100 \
2101   oop o = JNIHandles::resolve_non_null(obj); \
2102   Klass* k = o->klass(); \




  33 #include "classfile/modules.hpp"
  34 #include "classfile/symbolTable.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/vmSymbols.hpp"
  37 #include "gc/shared/gcLocker.inline.hpp"
  38 #include "interpreter/linkResolver.hpp"
  39 #include "memory/allocation.hpp"
  40 #include "memory/allocation.inline.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.inline.hpp"
  44 #include "oops/instanceKlass.hpp"
  45 #include "oops/instanceOop.hpp"
  46 #include "oops/markOop.hpp"
  47 #include "oops/method.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/symbol.hpp"
  52 #include "oops/typeArrayKlass.hpp"
  53 #include "oops/typeArrayOop.inline.hpp"
  54 #include "prims/jni.h"
  55 #include "prims/jniCheck.hpp"
  56 #include "prims/jniExport.hpp"
  57 #include "prims/jniFastGetField.hpp"
  58 #include "prims/jvm.h"
  59 #include "prims/jvm_misc.hpp"
  60 #include "prims/jvmtiExport.hpp"
  61 #include "prims/jvmtiThreadState.hpp"
  62 #include "runtime/access.inline.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/compilationPolicy.hpp"
  65 #include "runtime/fieldDescriptor.hpp"
  66 #include "runtime/fprofiler.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/interfaceSupport.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/jfieldIDWorkaround.hpp"
  72 #include "runtime/orderAccess.inline.hpp"
  73 #include "runtime/reflection.hpp"
  74 #include "runtime/sharedRuntime.hpp"
  75 #include "runtime/signature.hpp"
  76 #include "runtime/thread.inline.hpp"
  77 #include "runtime/vm_operations.hpp"
  78 #include "services/memTracker.hpp"
  79 #include "services/runtimeService.hpp"
  80 #include "trace/traceMacros.hpp"
  81 #include "trace/tracing.hpp"
  82 #include "utilities/defaultStream.hpp"
  83 #include "utilities/dtrace.hpp"
  84 #include "utilities/events.hpp"
  85 #include "utilities/histogram.hpp"
  86 #include "utilities/internalVMTests.hpp"
  87 #include "utilities/macros.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


2039   }
2040 
2041   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
2042   // It may also have hash bits for k, if VerifyJNIFields is turned on.
2043   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
2044   return ret;
2045 JNI_END
2046 
2047 
2048 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2049   JNIWrapper("GetObjectField");
2050   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
2051   oop o = JNIHandles::resolve_non_null(obj);
2052   Klass* k = o->klass();
2053   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2054   // Keep JVMTI addition small and only check enabled flag here.
2055   // jni_GetField_probe() assumes that is okay to create handles.
2056   if (JvmtiExport::should_post_field_access()) {
2057     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2058   }
2059   oop loaded_obj = HeapAccess<ACCESS_ON_ANONYMOUS>::oop_load_at(o, offset);
2060   jobject ret = JNIHandles::make_local(env, loaded_obj);
2061   HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);



















2062   return ret;
2063 JNI_END
2064 
2065 
2066 
2067 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2068   , EntryProbe, ReturnProbe) \
2069 \
2070   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2071   , ReturnProbe); \
2072 \
2073 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2074   JNIWrapper("Get" XSTR(Result) "Field"); \
2075 \
2076   EntryProbe; \
2077   Return ret = 0;\
2078   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
2079 \
2080   oop o = JNIHandles::resolve_non_null(obj); \
2081   Klass* k = o->klass(); \


< prev index next >