< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page

 347         protection_domain = Handle(THREAD, fromClass->protection_domain());
 348       }
 349     } else {
 350       loader = Handle(THREAD, k->class_loader());
 351     }
 352   }
 353 
 354   result = find_class_from_class_loader(env, class_name, true, loader,
 355                                         protection_domain, true, thread);
 356 
 357   if (log_is_enabled(Debug, class, resolve) && result != nullptr) {
 358     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 359   }
 360 
 361   return result;
 362 JNI_END
 363 
 364 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 365                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 366 








 367 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 368   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(env, method);
 369 
 370   jmethodID ret = nullptr;
 371   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 372 
 373   // method is a handle to a java.lang.reflect.Method object
 374   oop reflected  = JNIHandles::resolve_non_null(method);
 375   oop mirror     = nullptr;
 376   int slot       = 0;
 377 
 378   if (reflected->klass() == vmClasses::reflect_Constructor_klass()) {
 379     mirror = java_lang_reflect_Constructor::clazz(reflected);
 380     slot   = java_lang_reflect_Constructor::slot(reflected);
 381   } else {
 382     assert(reflected->klass() == vmClasses::reflect_Method_klass(), "wrong type");
 383     mirror = java_lang_reflect_Method::clazz(reflected);
 384     slot   = java_lang_reflect_Method::slot(reflected);
 385   }
 386   Klass* k1 = java_lang_Class::as_Klass(mirror);
 387 
 388   // Make sure class is initialized before handing id's out to methods

 389   k1->initialize(CHECK_NULL);
 390   Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
 391   ret = m==nullptr? nullptr : m->jmethod_id();  // return null if reflected method deleted
 392   return ret;
 393 JNI_END
 394 
 395 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 396                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 397 
 398 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 399   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(env, field);
 400 
 401   jfieldID ret = nullptr;
 402   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 403 
 404   // field is a handle to a java.lang.reflect.Field object
 405   oop reflected   = JNIHandles::resolve_non_null(field);
 406   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 407   Klass* k1       = java_lang_Class::as_Klass(mirror);
 408   int slot        = java_lang_reflect_Field::slot(reflected);
 409   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 410 
 411   // Make sure class is initialized before handing id's out to fields

 412   k1->initialize(CHECK_NULL);
 413 
 414   // First check if this is a static field
 415   if (modifiers & JVM_ACC_STATIC) {
 416     int offset = InstanceKlass::cast(k1)->field_offset( slot );
 417     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 418     assert(id != nullptr, "corrupt Field object");
 419     debug_only(id->set_is_static_field_id();)
 420     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 421     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 422     return ret;
 423   }
 424 
 425   // The slot is the index of the field description in the field-array
 426   // The jfieldID is the offset of the field within the object
 427   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 428   int offset = InstanceKlass::cast(k1)->field_offset( slot );
 429   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 430   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
 431   return ret;

 952   result->set_type(args->return_type());
 953 
 954   // Invoke the method. Result is returned as oop.
 955   JavaCalls::call(result, method, &java_args, CHECK);
 956 
 957   // Convert result
 958   if (is_reference_type(result->get_type())) {
 959     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 960   }
 961 }
 962 
 963 DT_RETURN_MARK_DECL(AllocObject, jobject
 964                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
 965 
 966 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
 967   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
 968 
 969   jobject ret = nullptr;
 970   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 971 
 972   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
 973   ret = JNIHandles::make_local(THREAD, i);
 974   return ret;
 975 JNI_END
 976 
 977 DT_RETURN_MARK_DECL(NewObjectA, jobject
 978                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
 979 
 980 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
 981   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
 982 
 983   jobject obj = nullptr;
 984   DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
 985 
 986   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
 987   obj = JNIHandles::make_local(THREAD, i);
 988   JavaValue jvalue(T_VOID);
 989   JNI_ArgumentPusherArray ap(methodID, args);
 990   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
 991   return obj;
 992 JNI_END
 993 
 994 
 995 DT_RETURN_MARK_DECL(NewObjectV, jobject
 996                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
 997 
 998 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
 999   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
1000 
1001   jobject obj = nullptr;
1002   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1003 
1004   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
1005   obj = JNIHandles::make_local(THREAD, i);
1006   JavaValue jvalue(T_VOID);
1007   JNI_ArgumentPusherVaArg ap(methodID, args);
1008   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1009   return obj;
1010 JNI_END
1011 
1012 
1013 DT_RETURN_MARK_DECL(NewObject, jobject
1014                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1015 
1016 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1017   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1018 
1019   jobject obj = nullptr;
1020   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1021 
1022   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
1023   obj = JNIHandles::make_local(THREAD, i);
1024   va_list args;
1025   va_start(args, methodID);
1026   JavaValue jvalue(T_VOID);
1027   JNI_ArgumentPusherVaArg ap(methodID, args);
1028   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1029   va_end(args);
1030   return obj;
1031 JNI_END
1032 
1033 
1034 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1035   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1036 
1037   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1038   jclass ret =
1039     (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1040 
1041   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1042   return ret;

1072                         : name_str;
1073   TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
1074   TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));
1075 
1076   if (name == nullptr || signature == nullptr) {
1077     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1078   }
1079 
1080   oop mirror = JNIHandles::resolve_non_null(clazz);
1081   Klass* klass = java_lang_Class::as_Klass(mirror);
1082 
1083   // Throw a NoSuchMethodError exception if we have an instance of a
1084   // primitive java.lang.Class
1085   if (java_lang_Class::is_primitive(mirror)) {
1086     ResourceMark rm(THREAD);
1087     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));
1088   }
1089 
1090   // Make sure class is linked and initialized before handing id's out to
1091   // Method*s.

1092   klass->initialize(CHECK_NULL);
1093 
1094   Method* m;
1095   if (name == vmSymbols::object_initializer_name() ||
1096       name == vmSymbols::class_initializer_name()) {
1097     // Never search superclasses for constructors
1098     if (klass->is_instance_klass()) {
1099       m = InstanceKlass::cast(klass)->find_method(name, signature);
1100     } else {
1101       m = nullptr;
1102     }
1103   } else {
1104     m = klass->lookup_method(name, signature);
1105     if (m == nullptr &&  klass->is_instance_klass()) {
1106       m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
1107     }
1108   }
1109   if (m == nullptr || (m->is_static() != is_static)) {
1110     ResourceMark rm(THREAD);
1111     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));

1592                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
1593 
1594 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
1595                                 , EntryProbe, ResultProbe) \
1596 \
1597   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
1598                           , ResultProbe);                               \
1599 \
1600 JNI_ENTRY(ResultType, \
1601           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
1602 \
1603   EntryProbe; \
1604   ResultType ret = 0;\
1605   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
1606                      (const ResultType&)ret);\
1607 \
1608   JavaValue jvalue(Tag); \
1609   JNI_ArgumentPusherVaArg ap(methodID, args); \
1610   /* Make sure class is initialized before trying to invoke its method */ \
1611   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \

1612   k->initialize(CHECK_0); \
1613   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_0); \
1614   va_end(args); \
1615   ret = jvalue.get_##ResultType(); \
1616   return ret;\
1617 JNI_END
1618 
1619 // the runtime type of subword integral basic types is integer
1620 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
1621                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1622                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
1623 DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
1624                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1625                         HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
1626 DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
1627                         , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1628                         HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
1629 DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
1630                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1631                         HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));

1749 
1750 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
1751           const char *name, const char *sig))
1752   HOTSPOT_JNI_GETFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1753   jfieldID ret = 0;
1754   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
1755 
1756   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1757 
1758   // The class should have been loaded (we have an instance of the class
1759   // passed in) so the field and signature should already be in the symbol
1760   // table.  If they're not there, the field doesn't exist.
1761   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1762   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1763   if (fieldname == nullptr || signame == nullptr) {
1764     ResourceMark rm;
1765     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1766   }
1767 
1768   // Make sure class is initialized before handing id's out to fields

1769   k->initialize(CHECK_NULL);
1770 
1771   fieldDescriptor fd;
1772   if (!k->is_instance_klass() ||
1773       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
1774     ResourceMark rm;
1775     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1776   }
1777 
1778   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
1779   // It may also have hash bits for k, if VerifyJNIFields is turned on.
1780   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
1781   return ret;
1782 JNI_END
1783 
1784 
1785 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
1786   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
1787   oop o = JNIHandles::resolve_non_null(obj);
1788   Klass* k = o->klass();

1973 //
1974 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
1975                     , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
1976 
1977 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
1978           const char *name, const char *sig))
1979   HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1980   jfieldID ret = nullptr;
1981   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
1982 
1983   // The class should have been loaded (we have an instance of the class
1984   // passed in) so the field and signature should already be in the symbol
1985   // table.  If they're not there, the field doesn't exist.
1986   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1987   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1988   if (fieldname == nullptr || signame == nullptr) {
1989     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
1990   }
1991   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1992   // Make sure class is initialized before handing id's out to static fields

1993   k->initialize(CHECK_NULL);
1994 
1995   fieldDescriptor fd;
1996   if (!k->is_instance_klass() ||
1997       !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
1998     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
1999   }
2000 
2001   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
2002   JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
2003   debug_only(id->set_is_static_field_id();)
2004 
2005   debug_only(id->verify(fd.field_holder()));
2006 
2007   ret = jfieldIDWorkaround::to_static_jfieldID(id);
2008   return ret;
2009 JNI_END
2010 
2011 
2012 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))

 347         protection_domain = Handle(THREAD, fromClass->protection_domain());
 348       }
 349     } else {
 350       loader = Handle(THREAD, k->class_loader());
 351     }
 352   }
 353 
 354   result = find_class_from_class_loader(env, class_name, true, loader,
 355                                         protection_domain, true, thread);
 356 
 357   if (log_is_enabled(Debug, class, resolve) && result != nullptr) {
 358     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 359   }
 360 
 361   return result;
 362 JNI_END
 363 
 364 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 365                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 366 
 367 #define NOTE_JNI_CLASSINIT(k1, reason)                                  \
 368   if (RecordTraining && k1->is_instance_klass()) {                      \
 369     InstanceKlass::cast(k1)                                             \
 370       ->record_initialization_touch(reason, nullptr, nullptr,           \
 371                                     nullptr, "jni", CHECK_0);           \
 372   }
 373 
 374 
 375 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 376   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(env, method);
 377 
 378   jmethodID ret = nullptr;
 379   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 380 
 381   // method is a handle to a java.lang.reflect.Method object
 382   oop reflected  = JNIHandles::resolve_non_null(method);
 383   oop mirror     = nullptr;
 384   int slot       = 0;
 385 
 386   if (reflected->klass() == vmClasses::reflect_Constructor_klass()) {
 387     mirror = java_lang_reflect_Constructor::clazz(reflected);
 388     slot   = java_lang_reflect_Constructor::slot(reflected);
 389   } else {
 390     assert(reflected->klass() == vmClasses::reflect_Method_klass(), "wrong type");
 391     mirror = java_lang_reflect_Method::clazz(reflected);
 392     slot   = java_lang_reflect_Method::slot(reflected);
 393   }
 394   Klass* k1 = java_lang_Class::as_Klass(mirror);
 395 
 396   // Make sure class is initialized before handing id's out to methods
 397   NOTE_JNI_CLASSINIT(k1, "reflect");
 398   k1->initialize(CHECK_NULL);
 399   Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
 400   ret = m==nullptr? nullptr : m->jmethod_id();  // return null if reflected method deleted
 401   return ret;
 402 JNI_END
 403 
 404 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 405                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 406 
 407 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 408   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(env, field);
 409 
 410   jfieldID ret = nullptr;
 411   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 412 
 413   // field is a handle to a java.lang.reflect.Field object
 414   oop reflected   = JNIHandles::resolve_non_null(field);
 415   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 416   Klass* k1       = java_lang_Class::as_Klass(mirror);
 417   int slot        = java_lang_reflect_Field::slot(reflected);
 418   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 419 
 420   // Make sure class is initialized before handing id's out to fields
 421   NOTE_JNI_CLASSINIT(k1, "reflect");
 422   k1->initialize(CHECK_NULL);
 423 
 424   // First check if this is a static field
 425   if (modifiers & JVM_ACC_STATIC) {
 426     int offset = InstanceKlass::cast(k1)->field_offset( slot );
 427     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 428     assert(id != nullptr, "corrupt Field object");
 429     debug_only(id->set_is_static_field_id();)
 430     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 431     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 432     return ret;
 433   }
 434 
 435   // The slot is the index of the field description in the field-array
 436   // The jfieldID is the offset of the field within the object
 437   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 438   int offset = InstanceKlass::cast(k1)->field_offset( slot );
 439   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 440   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
 441   return ret;

 962   result->set_type(args->return_type());
 963 
 964   // Invoke the method. Result is returned as oop.
 965   JavaCalls::call(result, method, &java_args, CHECK);
 966 
 967   // Convert result
 968   if (is_reference_type(result->get_type())) {
 969     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 970   }
 971 }
 972 
 973 DT_RETURN_MARK_DECL(AllocObject, jobject
 974                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
 975 
 976 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
 977   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
 978 
 979   jobject ret = nullptr;
 980   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 981 
 982   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
 983   ret = JNIHandles::make_local(THREAD, i);
 984   return ret;
 985 JNI_END
 986 
 987 DT_RETURN_MARK_DECL(NewObjectA, jobject
 988                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
 989 
 990 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
 991   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
 992 
 993   jobject obj = nullptr;
 994   DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
 995 
 996   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", 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   return obj;
1002 JNI_END
1003 
1004 
1005 DT_RETURN_MARK_DECL(NewObjectV, jobject
1006                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
1007 
1008 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
1009   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
1010 
1011   jobject obj = nullptr;
1012   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1013 
1014   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
1015   obj = JNIHandles::make_local(THREAD, i);
1016   JavaValue jvalue(T_VOID);
1017   JNI_ArgumentPusherVaArg ap(methodID, args);
1018   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1019   return obj;
1020 JNI_END
1021 
1022 
1023 DT_RETURN_MARK_DECL(NewObject, jobject
1024                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1025 
1026 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1027   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1028 
1029   jobject obj = nullptr;
1030   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1031 
1032   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), "jni", CHECK_NULL);
1033   obj = JNIHandles::make_local(THREAD, i);
1034   va_list args;
1035   va_start(args, methodID);
1036   JavaValue jvalue(T_VOID);
1037   JNI_ArgumentPusherVaArg ap(methodID, args);
1038   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1039   va_end(args);
1040   return obj;
1041 JNI_END
1042 
1043 
1044 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1045   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1046 
1047   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1048   jclass ret =
1049     (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1050 
1051   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1052   return ret;

1082                         : name_str;
1083   TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
1084   TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));
1085 
1086   if (name == nullptr || signature == nullptr) {
1087     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1088   }
1089 
1090   oop mirror = JNIHandles::resolve_non_null(clazz);
1091   Klass* klass = java_lang_Class::as_Klass(mirror);
1092 
1093   // Throw a NoSuchMethodError exception if we have an instance of a
1094   // primitive java.lang.Class
1095   if (java_lang_Class::is_primitive(mirror)) {
1096     ResourceMark rm(THREAD);
1097     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));
1098   }
1099 
1100   // Make sure class is linked and initialized before handing id's out to
1101   // Method*s.
1102   NOTE_JNI_CLASSINIT(klass, "resolve");
1103   klass->initialize(CHECK_NULL);
1104 
1105   Method* m;
1106   if (name == vmSymbols::object_initializer_name() ||
1107       name == vmSymbols::class_initializer_name()) {
1108     // Never search superclasses for constructors
1109     if (klass->is_instance_klass()) {
1110       m = InstanceKlass::cast(klass)->find_method(name, signature);
1111     } else {
1112       m = nullptr;
1113     }
1114   } else {
1115     m = klass->lookup_method(name, signature);
1116     if (m == nullptr &&  klass->is_instance_klass()) {
1117       m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
1118     }
1119   }
1120   if (m == nullptr || (m->is_static() != is_static)) {
1121     ResourceMark rm(THREAD);
1122     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));

1603                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
1604 
1605 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
1606                                 , EntryProbe, ResultProbe) \
1607 \
1608   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
1609                           , ResultProbe);                               \
1610 \
1611 JNI_ENTRY(ResultType, \
1612           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
1613 \
1614   EntryProbe; \
1615   ResultType ret = 0;\
1616   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
1617                      (const ResultType&)ret);\
1618 \
1619   JavaValue jvalue(Tag); \
1620   JNI_ArgumentPusherVaArg ap(methodID, args); \
1621   /* Make sure class is initialized before trying to invoke its method */ \
1622   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \
1623   NOTE_JNI_CLASSINIT(k, "invokestatic"); \
1624   k->initialize(CHECK_0); \
1625   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_0); \
1626   va_end(args); \
1627   ret = jvalue.get_##ResultType(); \
1628   return ret;\
1629 JNI_END
1630 
1631 // the runtime type of subword integral basic types is integer
1632 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
1633                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1634                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
1635 DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
1636                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1637                         HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
1638 DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
1639                         , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1640                         HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
1641 DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
1642                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1643                         HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));

1761 
1762 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
1763           const char *name, const char *sig))
1764   HOTSPOT_JNI_GETFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1765   jfieldID ret = 0;
1766   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
1767 
1768   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1769 
1770   // The class should have been loaded (we have an instance of the class
1771   // passed in) so the field and signature should already be in the symbol
1772   // table.  If they're not there, the field doesn't exist.
1773   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1774   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1775   if (fieldname == nullptr || signame == nullptr) {
1776     ResourceMark rm;
1777     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1778   }
1779 
1780   // Make sure class is initialized before handing id's out to fields
1781   NOTE_JNI_CLASSINIT(k, "resolve");
1782   k->initialize(CHECK_NULL);
1783 
1784   fieldDescriptor fd;
1785   if (!k->is_instance_klass() ||
1786       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
1787     ResourceMark rm;
1788     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1789   }
1790 
1791   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
1792   // It may also have hash bits for k, if VerifyJNIFields is turned on.
1793   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
1794   return ret;
1795 JNI_END
1796 
1797 
1798 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
1799   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
1800   oop o = JNIHandles::resolve_non_null(obj);
1801   Klass* k = o->klass();

1986 //
1987 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
1988                     , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
1989 
1990 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
1991           const char *name, const char *sig))
1992   HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1993   jfieldID ret = nullptr;
1994   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
1995 
1996   // The class should have been loaded (we have an instance of the class
1997   // passed in) so the field and signature should already be in the symbol
1998   // table.  If they're not there, the field doesn't exist.
1999   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
2000   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
2001   if (fieldname == nullptr || signame == nullptr) {
2002     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2003   }
2004   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2005   // Make sure class is initialized before handing id's out to static fields
2006   NOTE_JNI_CLASSINIT(k, "resolve");
2007   k->initialize(CHECK_NULL);
2008 
2009   fieldDescriptor fd;
2010   if (!k->is_instance_klass() ||
2011       !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
2012     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2013   }
2014 
2015   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
2016   JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
2017   debug_only(id->set_is_static_field_id();)
2018 
2019   debug_only(id->verify(fd.field_holder()));
2020 
2021   ret = jfieldIDWorkaround::to_static_jfieldID(id);
2022   return ret;
2023 JNI_END
2024 
2025 
2026 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))
< prev index next >