< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page

  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/modules.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "compiler/compiler_globals.hpp"
  41 #include "gc/shared/collectedHeap.hpp"
  42 #include "gc/shared/stringdedup/stringDedup.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "jni.h"
  45 #include "jvm.h"
  46 #include "logging/log.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "nmt/memTracker.hpp"
  52 #include "oops/access.inline.hpp"
  53 #include "oops/arrayOop.hpp"


  54 #include "oops/instanceKlass.inline.hpp"
  55 #include "oops/instanceOop.hpp"
  56 #include "oops/klass.inline.hpp"
  57 #include "oops/markWord.hpp"
  58 #include "oops/method.hpp"
  59 #include "oops/objArrayKlass.hpp"
  60 #include "oops/objArrayOop.inline.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "oops/symbol.hpp"
  63 #include "oops/typeArrayKlass.hpp"
  64 #include "oops/typeArrayOop.inline.hpp"

  65 #include "prims/jniCheck.hpp"
  66 #include "prims/jniExport.hpp"
  67 #include "prims/jniFastGetField.hpp"
  68 #include "prims/jvm_misc.hpp"
  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/jvmtiThreadState.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomicAccess.hpp"
  73 #include "runtime/fieldDescriptor.inline.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/interfaceSupport.inline.hpp"
  76 #include "runtime/java.hpp"
  77 #include "runtime/javaCalls.hpp"
  78 #include "runtime/javaThread.inline.hpp"
  79 #include "runtime/jfieldIDWorkaround.hpp"
  80 #include "runtime/jniHandles.inline.hpp"
  81 #include "runtime/reflection.hpp"
  82 #include "runtime/safepointVerifiers.hpp"
  83 #include "runtime/sharedRuntime.hpp"
  84 #include "runtime/signature.hpp"

 401   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 402 
 403   // Make sure class is initialized before handing id's out to fields
 404   k1->initialize(CHECK_NULL);
 405 
 406   // First check if this is a static field
 407   if (modifiers & JVM_ACC_STATIC) {
 408     int offset = InstanceKlass::cast(k1)->field_offset( slot );
 409     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 410     assert(id != nullptr, "corrupt Field object");
 411     DEBUG_ONLY(id->set_is_static_field_id();)
 412     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 413     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 414     return ret;
 415   }
 416 
 417   // The slot is the index of the field description in the field-array
 418   // The jfieldID is the offset of the field within the object
 419   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 420   int offset = InstanceKlass::cast(k1)->field_offset( slot );

 421   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 422   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
 423   return ret;
 424 JNI_END
 425 
 426 
 427 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 428                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 429 
 430 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 431   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(env, cls, (uintptr_t) method_id, isStatic);
 432 
 433   jobject ret = nullptr;
 434   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 435 
 436   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 437   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 438   oop reflection_method;
 439   if (m->is_object_initializer()) {
 440     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 441   } else {
 442     // Note: Static initializers can theoretically be here, if JNI users manage
 443     // to get their jmethodID. Record them as plain methods.
 444     reflection_method = Reflection::new_method(m, false, CHECK_NULL);
 445   }
 446   ret = JNIHandles::make_local(THREAD, reflection_method);
 447   return ret;
 448 JNI_END
 449 
 450 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 451                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 452 
 453 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 454   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(env, sub);
 455 
 456   jclass obj = nullptr;
 457   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 458 
 459   oop mirror = JNIHandles::resolve_non_null(sub);

 778   }
 779 
 780   friend class SignatureIterator;  // so do_parameters_on can call do_type
 781   void do_type(BasicType type) {
 782     switch (type) {
 783     // these are coerced to int when using va_arg
 784     case T_BYTE:
 785     case T_CHAR:
 786     case T_SHORT:
 787     case T_INT:         push_int(va_arg(_ap, jint)); break;
 788     case T_BOOLEAN:     push_boolean((jboolean) va_arg(_ap, jint)); break;
 789 
 790     // each of these paths is exercised by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
 791 
 792     case T_LONG:        push_long(va_arg(_ap, jlong)); break;
 793     // float is coerced to double w/ va_arg
 794     case T_FLOAT:       push_float((jfloat) va_arg(_ap, jdouble)); break;
 795     case T_DOUBLE:      push_double(va_arg(_ap, jdouble)); break;
 796 
 797     case T_ARRAY:
 798     case T_OBJECT:      push_object(va_arg(_ap, jobject)); break;
 799     default:            ShouldNotReachHere();
 800     }
 801   }
 802 
 803  public:
 804   JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
 805       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)) {
 806     set_ap(rap);
 807   }
 808 
 809   ~JNI_ArgumentPusherVaArg() {
 810     va_end(_ap);
 811   }
 812 
 813   virtual void push_arguments_on(JavaCallArguments* arguments) {
 814     _arguments = arguments;
 815     do_parameters_on(this);
 816   }
 817 };
 818 

 945   result->set_type(args->return_type());
 946 
 947   // Invoke the method. Result is returned as oop.
 948   JavaCalls::call(result, method, &java_args, CHECK);
 949 
 950   // Convert result
 951   if (is_reference_type(result->get_type())) {
 952     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 953   }
 954 }
 955 
 956 DT_RETURN_MARK_DECL(AllocObject, jobject
 957                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
 958 
 959 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
 960   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
 961 
 962   jobject ret = nullptr;
 963   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 964 
 965   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);






 966   ret = JNIHandles::make_local(THREAD, i);
 967   return ret;
 968 JNI_END
 969 
 970 DT_RETURN_MARK_DECL(NewObjectA, jobject
 971                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
 972 
 973 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
 974   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
 975 
 976   jobject obj = nullptr;
 977   DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
 978 
 979   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);







 980   obj = JNIHandles::make_local(THREAD, i);
 981   JavaValue jvalue(T_VOID);
 982   JNI_ArgumentPusherArray ap(methodID, args);
 983   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);

 984   return obj;
 985 JNI_END
 986 
 987 
 988 DT_RETURN_MARK_DECL(NewObjectV, jobject
 989                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
 990 
 991 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
 992   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
 993 
 994   jobject obj = nullptr;
 995   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
 996 
 997   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);







 998   obj = JNIHandles::make_local(THREAD, i);
 999   JavaValue jvalue(T_VOID);
1000   JNI_ArgumentPusherVaArg ap(methodID, args);
1001   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);

1002   return obj;
1003 JNI_END
1004 
1005 
1006 DT_RETURN_MARK_DECL(NewObject, jobject
1007                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1008 
1009 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1010   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1011 
1012   jobject obj = nullptr;
1013   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1014 
1015   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);







1016   obj = JNIHandles::make_local(THREAD, i);
1017   va_list args;
1018   va_start(args, methodID);
1019   JavaValue jvalue(T_VOID);
1020   JNI_ArgumentPusherVaArg ap(methodID, args);
1021   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1022   va_end(args);

1023   return obj;
1024 JNI_END
1025 
1026 
1027 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1028   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1029 
1030   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1031   jclass ret =
1032     (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1033 
1034   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1035   return ret;
1036 JNI_END
1037 
1038 JNI_ENTRY_NO_PRESERVE(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
1039   HOTSPOT_JNI_ISINSTANCEOF_ENTRY(env, obj, clazz);
1040 
1041   jboolean ret = JNI_TRUE;
1042   if (obj != nullptr) {

1753   // table.  If they're not there, the field doesn't exist.
1754   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1755   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1756   if (fieldname == nullptr || signame == nullptr) {
1757     ResourceMark rm;
1758     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1759   }
1760 
1761   // Make sure class is initialized before handing id's out to fields
1762   k->initialize(CHECK_NULL);
1763 
1764   fieldDescriptor fd;
1765   if (!k->is_instance_klass() ||
1766       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
1767     ResourceMark rm;
1768     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1769   }
1770 
1771   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
1772   // It may also have hash bits for k, if VerifyJNIFields is turned on.
1773   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
1774   return ret;
1775 JNI_END
1776 
1777 
1778 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
1779   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
1780   oop o = JNIHandles::resolve_non_null(obj);
1781   Klass* k = o->klass();
1782   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);

1783   // Keep JVMTI addition small and only check enabled flag here.
1784   // jni_GetField_probe() assumes that is okay to create handles.
1785   if (JvmtiExport::should_post_field_access()) {
1786     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
1787   }
1788   oop loaded_obj = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(o, offset);
1789   jobject ret = JNIHandles::make_local(THREAD, loaded_obj);









1790   HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
1791   return ret;
1792 JNI_END
1793 
1794 
1795 
1796 #define DEFINE_GETFIELD(Return,Fieldname,Result \
1797   , EntryProbe, ReturnProbe) \
1798 \
1799   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
1800   , ReturnProbe); \
1801 \
1802 JNI_ENTRY_NO_PRESERVE(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
1803 \
1804   EntryProbe; \
1805   Return ret = 0;\
1806   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
1807 \
1808   oop o = JNIHandles::resolve_non_null(obj); \
1809   Klass* k = o->klass(); \
1810   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1811   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1812   if (JvmtiExport::should_post_field_access()) { \
1813     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); \
1814   } \
1815   ret = o->Fieldname##_field(offset); \

1887     assert(found, "bad field offset");
1888     assert(!fd.is_static(), "static/instance mismatch");
1889     if (fd.is_final()) {
1890       ResourceMark rm(current);
1891       log_debug(jni)("%s mutated final instance field %s.%s", func_name, ik->external_name(), fd.name()->as_C_string());
1892     }
1893   }
1894 }
1895 
1896 JNI_ENTRY_NO_PRESERVE(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
1897   HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID, value);
1898   oop o = JNIHandles::resolve_non_null(obj);
1899   Klass* k = o->klass();
1900   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1901   // Keep JVMTI addition small and only check enabled flag here.
1902   if (JvmtiExport::should_post_field_modification()) {
1903     jvalue field_value;
1904     field_value.l = value;
1905     o = JvmtiExport::jni_SetField_probe(thread, obj, o, k, fieldID, false, JVM_SIGNATURE_CLASS, (jvalue *)&field_value);
1906   }
1907   HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(o, offset, JNIHandles::resolve(value));


















1908   log_debug_if_final_instance_field(thread, "SetObjectField", InstanceKlass::cast(k), offset);
1909   HOTSPOT_JNI_SETOBJECTFIELD_RETURN();
1910 JNI_END
1911 
1912 // TODO: make this a template
1913 
1914 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
1915                         , EntryProbe, ReturnProbe) \
1916 \
1917 JNI_ENTRY_NO_PRESERVE(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
1918 \
1919   EntryProbe; \
1920 \
1921   oop o = JNIHandles::resolve_non_null(obj); \
1922   Klass* k = o->klass(); \
1923   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1924   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1925   if (JvmtiExport::should_post_field_modification()) { \
1926     jvalue field_value; \
1927     field_value.unionType = value; \

2320 
2321   oop initial_value = JNIHandles::resolve(initialElement);
2322   if (initial_value != nullptr) {  // array already initialized with null
2323     for (int index = 0; index < length; index++) {
2324       result->obj_at_put(index, initial_value);
2325     }
2326   }
2327   ret = (jobjectArray) JNIHandles::make_local(THREAD, result);
2328   return ret;
2329 JNI_END
2330 
2331 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
2332                     , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
2333 
2334 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
2335  HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(env, array, index);
2336   jobject ret = nullptr;
2337   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
2338   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2339   if (a->is_within_bounds(index)) {
2340     ret = JNIHandles::make_local(THREAD, a->obj_at(index));


2341     return ret;
2342   } else {
2343     ResourceMark rm(THREAD);
2344     stringStream ss;
2345     ss.print("Index %d out of bounds for length %d", index, a->length());
2346     THROW_MSG_NULL(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2347   }
2348 JNI_END
2349 
2350 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
2351                          , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
2352 
2353 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
2354  HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(env, array, index, value);
2355   DT_VOID_RETURN_MARK(SetObjectArrayElement);
2356 
2357   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2358   oop v = JNIHandles::resolve(value);
2359   if (a->is_within_bounds(index)) {
2360     if (v == nullptr || v->is_a(ObjArrayKlass::cast(a->klass())->element_klass())) {
2361       a->obj_at_put(index, v);

2362     } else {
2363       ResourceMark rm(THREAD);
2364       stringStream ss;
2365       Klass *bottom_kl = ObjArrayKlass::cast(a->klass())->bottom_klass();
2366       ss.print("type mismatch: can not store %s to %s[%d]",
2367                v->klass()->external_name(),
2368                bottom_kl->is_typeArray_klass() ? type2name_tab[ArrayKlass::cast(bottom_kl)->element_type()] : bottom_kl->external_name(),
2369                index);
2370       for (int dims = ArrayKlass::cast(a->klass())->dimension(); dims > 1; --dims) {
2371         ss.print("[]");
2372       }
2373       THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
2374     }
2375   } else {
2376     ResourceMark rm(THREAD);
2377     stringStream ss;
2378     ss.print("Index %d out of bounds for length %d", index, a->length());
2379     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2380   }
2381 JNI_END
2382 
2383 
2384 
2385 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
2386                               ,EntryProbe,ReturnProbe)  \
2387 \
2388   DT_RETURN_MARK_DECL(New##Result##Array, Return \
2389                       , ReturnProbe); \
2390 \
2391 JNI_ENTRY(Return, \
2392           jni_New##Result##Array(JNIEnv *env, jsize len)) \
2393   EntryProbe; \
2394   Return ret = nullptr;\
2395   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
2396 \
2397   oop obj= oopFactory::Allocator(len, CHECK_NULL); \
2398   ret = (Return) JNIHandles::make_local(THREAD, obj); \
2399   return ret;\
2400 JNI_END

2736 JNI_END
2737 
2738 //
2739 // Monitor functions
2740 //
2741 
2742 DT_RETURN_MARK_DECL(MonitorEnter, jint
2743                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
2744 
2745 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
2746  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
2747   jint ret = JNI_ERR;
2748   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
2749 
2750   // If the object is null, we can't do anything with it
2751   if (jobj == nullptr) {
2752     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2753   }
2754 
2755   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2756   ObjectSynchronizer::jni_enter(obj, thread);
2757   return JNI_OK;
2758 JNI_END
2759 
2760 DT_RETURN_MARK_DECL(MonitorExit, jint
2761                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
2762 
2763 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
2764  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
2765   jint ret = JNI_ERR;
2766   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
2767 
2768   // Don't do anything with a null object
2769   if (jobj == nullptr) {
2770     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2771   }
2772 
2773   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
2774   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2775   return JNI_OK;
2776 JNI_END

  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/modules.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmClasses.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "compiler/compiler_globals.hpp"
  41 #include "gc/shared/collectedHeap.hpp"
  42 #include "gc/shared/stringdedup/stringDedup.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "jni.h"
  45 #include "jvm.h"
  46 #include "logging/log.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "nmt/memTracker.hpp"
  52 #include "oops/access.inline.hpp"
  53 #include "oops/arrayOop.hpp"
  54 #include "oops/flatArrayOop.inline.hpp"
  55 #include "oops/inlineKlass.inline.hpp"
  56 #include "oops/instanceKlass.inline.hpp"
  57 #include "oops/instanceOop.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/markWord.hpp"
  60 #include "oops/method.hpp"
  61 #include "oops/objArrayKlass.hpp"
  62 #include "oops/objArrayOop.inline.hpp"
  63 #include "oops/oop.inline.hpp"
  64 #include "oops/symbol.hpp"
  65 #include "oops/typeArrayKlass.hpp"
  66 #include "oops/typeArrayOop.inline.hpp"
  67 #include "oops/valuePayload.inline.hpp"
  68 #include "prims/jniCheck.hpp"
  69 #include "prims/jniExport.hpp"
  70 #include "prims/jniFastGetField.hpp"
  71 #include "prims/jvm_misc.hpp"
  72 #include "prims/jvmtiExport.hpp"
  73 #include "prims/jvmtiThreadState.hpp"
  74 #include "runtime/arguments.hpp"
  75 #include "runtime/atomicAccess.hpp"
  76 #include "runtime/fieldDescriptor.inline.hpp"
  77 #include "runtime/handles.inline.hpp"
  78 #include "runtime/interfaceSupport.inline.hpp"
  79 #include "runtime/java.hpp"
  80 #include "runtime/javaCalls.hpp"
  81 #include "runtime/javaThread.inline.hpp"
  82 #include "runtime/jfieldIDWorkaround.hpp"
  83 #include "runtime/jniHandles.inline.hpp"
  84 #include "runtime/reflection.hpp"
  85 #include "runtime/safepointVerifiers.hpp"
  86 #include "runtime/sharedRuntime.hpp"
  87 #include "runtime/signature.hpp"

 404   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 405 
 406   // Make sure class is initialized before handing id's out to fields
 407   k1->initialize(CHECK_NULL);
 408 
 409   // First check if this is a static field
 410   if (modifiers & JVM_ACC_STATIC) {
 411     int offset = InstanceKlass::cast(k1)->field_offset( slot );
 412     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 413     assert(id != nullptr, "corrupt Field object");
 414     DEBUG_ONLY(id->set_is_static_field_id();)
 415     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 416     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 417     return ret;
 418   }
 419 
 420   // The slot is the index of the field description in the field-array
 421   // The jfieldID is the offset of the field within the object
 422   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 423   int offset = InstanceKlass::cast(k1)->field_offset( slot );
 424   bool is_flat = InstanceKlass::cast(k1)->field_is_flat(slot);
 425   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 426   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset, is_flat);
 427   return ret;
 428 JNI_END
 429 
 430 
 431 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 432                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 433 
 434 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 435   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(env, cls, (uintptr_t) method_id, isStatic);
 436 
 437   jobject ret = nullptr;
 438   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 439 
 440   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 441   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 442   oop reflection_method;
 443   if (m->is_object_constructor()) {
 444     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 445   } else {
 446     // Note: Static initializers can theoretically be here, if JNI users manage
 447     // to get their jmethodID. Record them as plain methods.
 448     reflection_method = Reflection::new_method(m, false, CHECK_NULL);
 449   }
 450   ret = JNIHandles::make_local(THREAD, reflection_method);
 451   return ret;
 452 JNI_END
 453 
 454 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 455                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 456 
 457 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 458   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(env, sub);
 459 
 460   jclass obj = nullptr;
 461   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 462 
 463   oop mirror = JNIHandles::resolve_non_null(sub);

 782   }
 783 
 784   friend class SignatureIterator;  // so do_parameters_on can call do_type
 785   void do_type(BasicType type) {
 786     switch (type) {
 787     // these are coerced to int when using va_arg
 788     case T_BYTE:
 789     case T_CHAR:
 790     case T_SHORT:
 791     case T_INT:         push_int(va_arg(_ap, jint)); break;
 792     case T_BOOLEAN:     push_boolean((jboolean) va_arg(_ap, jint)); break;
 793 
 794     // each of these paths is exercised by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
 795 
 796     case T_LONG:        push_long(va_arg(_ap, jlong)); break;
 797     // float is coerced to double w/ va_arg
 798     case T_FLOAT:       push_float((jfloat) va_arg(_ap, jdouble)); break;
 799     case T_DOUBLE:      push_double(va_arg(_ap, jdouble)); break;
 800 
 801     case T_ARRAY:
 802     case T_OBJECT: push_object(va_arg(_ap, jobject)); break;
 803     default:            ShouldNotReachHere();
 804     }
 805   }
 806 
 807  public:
 808   JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
 809       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)) {
 810     set_ap(rap);
 811   }
 812 
 813   ~JNI_ArgumentPusherVaArg() {
 814     va_end(_ap);
 815   }
 816 
 817   virtual void push_arguments_on(JavaCallArguments* arguments) {
 818     _arguments = arguments;
 819     do_parameters_on(this);
 820   }
 821 };
 822 

 949   result->set_type(args->return_type());
 950 
 951   // Invoke the method. Result is returned as oop.
 952   JavaCalls::call(result, method, &java_args, CHECK);
 953 
 954   // Convert result
 955   if (is_reference_type(result->get_type())) {
 956     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 957   }
 958 }
 959 
 960 DT_RETURN_MARK_DECL(AllocObject, jobject
 961                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
 962 
 963 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
 964   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
 965 
 966   jobject ret = nullptr;
 967   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 968 
 969   oop clazzoop = JNIHandles::resolve_non_null(clazz);
 970   Klass* k = java_lang_Class::as_Klass(clazzoop);
 971   if (k == nullptr || k->is_inline_klass()) {
 972     ResourceMark rm(THREAD);
 973     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
 974   }
 975   instanceOop i = InstanceKlass::allocate_instance(clazzoop, CHECK_NULL);
 976   ret = JNIHandles::make_local(THREAD, i);
 977   return ret;
 978 JNI_END
 979 
 980 DT_RETURN_MARK_DECL(NewObjectA, jobject
 981                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
 982 
 983 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
 984   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
 985 
 986   jobject obj = nullptr;
 987   DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
 988 
 989   oop clazzoop = JNIHandles::resolve_non_null(clazz);
 990   Klass* k = java_lang_Class::as_Klass(clazzoop);
 991   if (k == nullptr) {
 992     ResourceMark rm(THREAD);
 993     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
 994   }
 995 
 996   instanceOop i = InstanceKlass::allocate_instance(clazzoop, CHECK_NULL);
 997   obj = JNIHandles::make_local(THREAD, i);
 998   JavaValue jvalue(T_VOID);
 999   JNI_ArgumentPusherArray ap(methodID, args);
1000   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1001 
1002   return obj;
1003   JNI_END
1004 
1005 
1006 DT_RETURN_MARK_DECL(NewObjectV, jobject
1007                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
1008 
1009 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
1010   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
1011 
1012   jobject obj = nullptr;
1013   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1014 
1015   oop clazzoop = JNIHandles::resolve_non_null(clazz);
1016   Klass* k = java_lang_Class::as_Klass(clazzoop);
1017   if (k == nullptr) {
1018     ResourceMark rm(THREAD);
1019     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1020   }
1021 
1022   instanceOop i = InstanceKlass::allocate_instance(clazzoop, CHECK_NULL);
1023   obj = JNIHandles::make_local(THREAD, i);
1024   JavaValue jvalue(T_VOID);
1025   JNI_ArgumentPusherVaArg ap(methodID, args);
1026   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1027 
1028   return obj;
1029 JNI_END
1030 
1031 
1032 DT_RETURN_MARK_DECL(NewObject, jobject
1033                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1034 
1035 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1036   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1037 
1038   jobject obj = nullptr;
1039   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1040 
1041   oop clazzoop = JNIHandles::resolve_non_null(clazz);
1042   Klass* k = java_lang_Class::as_Klass(clazzoop);
1043   if (k == nullptr) {
1044     ResourceMark rm(THREAD);
1045     THROW_(vmSymbols::java_lang_InstantiationException(), nullptr);
1046   }
1047 
1048   instanceOop i = InstanceKlass::allocate_instance(clazzoop, CHECK_NULL);
1049   obj = JNIHandles::make_local(THREAD, i);
1050   va_list args;
1051   va_start(args, methodID);
1052   JavaValue jvalue(T_VOID);
1053   JNI_ArgumentPusherVaArg ap(methodID, args);
1054   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1055   va_end(args);
1056 
1057   return obj;
1058 JNI_END
1059 
1060 
1061 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1062   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1063 
1064   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1065   jclass ret =
1066     (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1067 
1068   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1069   return ret;
1070 JNI_END
1071 
1072 JNI_ENTRY_NO_PRESERVE(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
1073   HOTSPOT_JNI_ISINSTANCEOF_ENTRY(env, obj, clazz);
1074 
1075   jboolean ret = JNI_TRUE;
1076   if (obj != nullptr) {

1787   // table.  If they're not there, the field doesn't exist.
1788   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1789   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1790   if (fieldname == nullptr || signame == nullptr) {
1791     ResourceMark rm;
1792     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1793   }
1794 
1795   // Make sure class is initialized before handing id's out to fields
1796   k->initialize(CHECK_NULL);
1797 
1798   fieldDescriptor fd;
1799   if (!k->is_instance_klass() ||
1800       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
1801     ResourceMark rm;
1802     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1803   }
1804 
1805   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
1806   // It may also have hash bits for k, if VerifyJNIFields is turned on.
1807   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset(), fd.is_flat());
1808   return ret;
1809 JNI_END
1810 
1811 
1812 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
1813   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
1814   oop o = JNIHandles::resolve_non_null(obj);
1815   Klass* k = o->klass();
1816   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1817   oop res = nullptr;
1818   // Keep JVMTI addition small and only check enabled flag here.
1819   // jni_GetField_probe() assumes that is okay to create handles.
1820   if (JvmtiExport::should_post_field_access()) {
1821     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
1822   }
1823   if (!jfieldIDWorkaround::is_flat_jfieldID(fieldID)) {
1824     res = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(o, offset);
1825   } else {
1826     InstanceKlass* ik = InstanceKlass::cast(k);
1827     fieldDescriptor fd;
1828     bool found = ik->find_field_from_offset(offset, false, &fd);  // performance bottleneck
1829     assert(found, "Field not found");
1830     FlatFieldPayload payload(instanceOop(o), &fd);
1831     res = payload.read(CHECK_NULL);
1832   }
1833   jobject ret = JNIHandles::make_local(THREAD, res);
1834   HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
1835   return ret;
1836 JNI_END
1837 


1838 #define DEFINE_GETFIELD(Return,Fieldname,Result \
1839   , EntryProbe, ReturnProbe) \
1840 \
1841   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
1842   , ReturnProbe); \
1843 \
1844 JNI_ENTRY_NO_PRESERVE(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
1845 \
1846   EntryProbe; \
1847   Return ret = 0;\
1848   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
1849 \
1850   oop o = JNIHandles::resolve_non_null(obj); \
1851   Klass* k = o->klass(); \
1852   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1853   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1854   if (JvmtiExport::should_post_field_access()) { \
1855     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); \
1856   } \
1857   ret = o->Fieldname##_field(offset); \

1929     assert(found, "bad field offset");
1930     assert(!fd.is_static(), "static/instance mismatch");
1931     if (fd.is_final()) {
1932       ResourceMark rm(current);
1933       log_debug(jni)("%s mutated final instance field %s.%s", func_name, ik->external_name(), fd.name()->as_C_string());
1934     }
1935   }
1936 }
1937 
1938 JNI_ENTRY_NO_PRESERVE(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
1939   HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID, value);
1940   oop o = JNIHandles::resolve_non_null(obj);
1941   Klass* k = o->klass();
1942   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1943   // Keep JVMTI addition small and only check enabled flag here.
1944   if (JvmtiExport::should_post_field_modification()) {
1945     jvalue field_value;
1946     field_value.l = value;
1947     o = JvmtiExport::jni_SetField_probe(thread, obj, o, k, fieldID, false, JVM_SIGNATURE_CLASS, (jvalue *)&field_value);
1948   }
1949   if (!jfieldIDWorkaround::is_flat_jfieldID(fieldID)) {
1950     oop v = JNIHandles::resolve(value);
1951     if (v == nullptr) {
1952       InstanceKlass *ik = InstanceKlass::cast(k);
1953       fieldDescriptor fd;
1954       ik->find_field_from_offset(offset, false, &fd);
1955       if (fd.is_null_free_inline_type()) {
1956         THROW_MSG(vmSymbols::java_lang_NullPointerException(), "Cannot store null in a null-restricted field");
1957       }
1958     }
1959     HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(o, offset, v);
1960   } else {
1961     assert(k->is_instance_klass(), "Only instances can have flat fields");
1962     InstanceKlass* ik = InstanceKlass::cast(k);
1963     fieldDescriptor fd;
1964     ik->find_field_from_offset(offset, false, &fd);
1965     FlatFieldPayload payload(instanceOop(o), &fd);
1966     payload.write(inlineOop(JNIHandles::resolve(value)), CHECK);
1967   }
1968   log_debug_if_final_instance_field(thread, "SetObjectField", InstanceKlass::cast(k), offset);
1969   HOTSPOT_JNI_SETOBJECTFIELD_RETURN();
1970 JNI_END
1971 
1972 // TODO: make this a template
1973 
1974 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
1975                         , EntryProbe, ReturnProbe) \
1976 \
1977 JNI_ENTRY_NO_PRESERVE(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
1978 \
1979   EntryProbe; \
1980 \
1981   oop o = JNIHandles::resolve_non_null(obj); \
1982   Klass* k = o->klass(); \
1983   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1984   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1985   if (JvmtiExport::should_post_field_modification()) { \
1986     jvalue field_value; \
1987     field_value.unionType = value; \

2380 
2381   oop initial_value = JNIHandles::resolve(initialElement);
2382   if (initial_value != nullptr) {  // array already initialized with null
2383     for (int index = 0; index < length; index++) {
2384       result->obj_at_put(index, initial_value);
2385     }
2386   }
2387   ret = (jobjectArray) JNIHandles::make_local(THREAD, result);
2388   return ret;
2389 JNI_END
2390 
2391 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
2392                     , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
2393 
2394 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
2395  HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(env, array, index);
2396   jobject ret = nullptr;
2397   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
2398   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2399   if (a->is_within_bounds(index)) {
2400     oop res = a->obj_at(index, CHECK_NULL);
2401     assert(res != nullptr || !a->is_null_free_array(), "Invalid value");
2402     ret = JNIHandles::make_local(THREAD, res);
2403     return ret;
2404   } else {
2405     ResourceMark rm(THREAD);
2406     stringStream ss;
2407     ss.print("Index %d out of bounds for length %d", index, a->length());
2408     THROW_MSG_NULL(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2409   }
2410 JNI_END
2411 
2412 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
2413                          , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
2414 
2415 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
2416  HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(env, array, index, value);
2417   DT_VOID_RETURN_MARK(SetObjectArrayElement);
2418 
2419    objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2420    oop v = JNIHandles::resolve(value);
2421    if (a->is_within_bounds(index)) {
2422     Klass* ek = a->is_flatArray() ? FlatArrayKlass::cast(a->klass())->element_klass() : RefArrayKlass::cast(a->klass())->element_klass();
2423     if (v == nullptr || v->is_a(ek)) {
2424       a->obj_at_put(index, v, CHECK);
2425     } else {
2426       ResourceMark rm(THREAD);
2427       stringStream ss;
2428       Klass *bottom_kl = ObjArrayKlass::cast(a->klass())->bottom_klass();
2429       ss.print("type mismatch: can not store %s to %s[%d]",
2430                v->klass()->external_name(),
2431                bottom_kl->is_typeArray_klass() ? type2name_tab[ArrayKlass::cast(bottom_kl)->element_type()] : bottom_kl->external_name(),
2432                index);
2433       for (int dims = ArrayKlass::cast(a->klass())->dimension(); dims > 1; --dims) {
2434         ss.print("[]");
2435       }
2436       THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
2437     }
2438    } else {
2439      ResourceMark rm(THREAD);
2440      stringStream ss;
2441      ss.print("Index %d out of bounds for length %d", index, a->length());
2442      THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2443    }
2444 JNI_END
2445 
2446 
2447 
2448 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
2449                               ,EntryProbe,ReturnProbe)  \
2450 \
2451   DT_RETURN_MARK_DECL(New##Result##Array, Return \
2452                       , ReturnProbe); \
2453 \
2454 JNI_ENTRY(Return, \
2455           jni_New##Result##Array(JNIEnv *env, jsize len)) \
2456   EntryProbe; \
2457   Return ret = nullptr;\
2458   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
2459 \
2460   oop obj= oopFactory::Allocator(len, CHECK_NULL); \
2461   ret = (Return) JNIHandles::make_local(THREAD, obj); \
2462   return ret;\
2463 JNI_END

2799 JNI_END
2800 
2801 //
2802 // Monitor functions
2803 //
2804 
2805 DT_RETURN_MARK_DECL(MonitorEnter, jint
2806                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
2807 
2808 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
2809  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
2810   jint ret = JNI_ERR;
2811   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
2812 
2813   // If the object is null, we can't do anything with it
2814   if (jobj == nullptr) {
2815     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2816   }
2817 
2818   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2819   ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR));
2820   return JNI_OK;
2821 JNI_END
2822 
2823 DT_RETURN_MARK_DECL(MonitorExit, jint
2824                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
2825 
2826 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
2827  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
2828   jint ret = JNI_ERR;
2829   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
2830 
2831   // Don't do anything with a null object
2832   if (jobj == nullptr) {
2833     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2834   }
2835 
2836   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
2837   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2838   return JNI_OK;
2839 JNI_END
< prev index next >