src/hotspot/share/prims/jvm.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54957 b6b02a503d02
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    36 #include "classfile/symbolTable.hpp"
    36 #include "classfile/symbolTable.hpp"
    37 #include "classfile/systemDictionary.hpp"
    37 #include "classfile/systemDictionary.hpp"
    38 #include "classfile/vmSymbols.hpp"
    38 #include "classfile/vmSymbols.hpp"
    39 #include "gc/shared/collectedHeap.inline.hpp"
    39 #include "gc/shared/collectedHeap.inline.hpp"
    40 #include "interpreter/bytecode.hpp"
    40 #include "interpreter/bytecode.hpp"
       
    41 #include "interpreter/bytecodeUtils.hpp"
    41 #include "jfr/jfrEvents.hpp"
    42 #include "jfr/jfrEvents.hpp"
    42 #include "logging/log.hpp"
    43 #include "logging/log.hpp"
    43 #include "memory/heapShared.hpp"
    44 #include "memory/heapShared.hpp"
    44 #include "memory/oopFactory.hpp"
    45 #include "memory/oopFactory.hpp"
    45 #include "memory/referenceType.hpp"
    46 #include "memory/referenceType.hpp"
   529 
   530 
   530 
   531 
   531 
   532 
   532 // java.lang.Throwable //////////////////////////////////////////////////////
   533 // java.lang.Throwable //////////////////////////////////////////////////////
   533 
   534 
   534 
       
   535 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
   535 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
   536   JVMWrapper("JVM_FillInStackTrace");
   536   JVMWrapper("JVM_FillInStackTrace");
   537   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
   537   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
   538   java_lang_Throwable::fill_in_stack_trace(exception);
   538   java_lang_Throwable::fill_in_stack_trace(exception);
   539 JVM_END
   539 JVM_END
   540 
   540 
       
   541 // java.lang.NullPointerException ///////////////////////////////////////////
       
   542 
       
   543 JVM_ENTRY(jstring, JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable))
       
   544   if (!ShowCodeDetailsInExceptionMessages) return NULL;
       
   545 
       
   546   oop exc = JNIHandles::resolve_non_null(throwable);
       
   547 
       
   548   Method* method;
       
   549   int bci;
       
   550   if (!java_lang_Throwable::get_top_method_and_bci(exc, &method, &bci)) {
       
   551     return NULL;
       
   552   }
       
   553   if (method->is_native()) {
       
   554     return NULL;
       
   555   }
       
   556 
       
   557   stringStream ss;
       
   558   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
       
   559   if (ok) {
       
   560     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_0);
       
   561     return (jstring) JNIHandles::make_local(env, result);
       
   562   } else {
       
   563     return NULL;
       
   564   }
       
   565 JVM_END
   541 
   566 
   542 // java.lang.StackTraceElement //////////////////////////////////////////////
   567 // java.lang.StackTraceElement //////////////////////////////////////////////
   543 
   568 
   544 
   569 
   545 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
   570 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
   714 JVM_END
   739 JVM_END
   715 
   740 
   716 
   741 
   717 // Misc. class handling ///////////////////////////////////////////////////////////
   742 // Misc. class handling ///////////////////////////////////////////////////////////
   718 
   743 
       
   744 
       
   745 JVM_ENTRY(void, JVM_LinkClass(JNIEnv* env, jclass classClass, jclass arg))
       
   746   JVMWrapper("JVM_LinkClass");
       
   747 
       
   748   oop r = JNIHandles::resolve(arg);
       
   749   Klass* klass = java_lang_Class::as_Klass(r);
       
   750 
       
   751   if (!ClassForNameDeferLinking && klass->is_instance_klass()) {
       
   752     InstanceKlass::cast(klass)->link_class(CHECK);
       
   753   }
       
   754 JVM_END
   719 
   755 
   720 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   756 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   721   JVMWrapper("JVM_GetCallerClass");
   757   JVMWrapper("JVM_GetCallerClass");
   722 
   758 
   723   // Getting the class of the caller frame.
   759   // Getting the class of the caller frame.
   760 
   796 
   761 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
   797 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
   762   JVMWrapper("JVM_FindPrimitiveClass");
   798   JVMWrapper("JVM_FindPrimitiveClass");
   763   oop mirror = NULL;
   799   oop mirror = NULL;
   764   BasicType t = name2type(utf);
   800   BasicType t = name2type(utf);
   765   if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
   801   if (t != T_ILLEGAL && !is_reference_type(t)) {
   766     mirror = Universe::java_mirror(t);
   802     mirror = Universe::java_mirror(t);
   767   }
   803   }
   768   if (mirror == NULL) {
   804   if (mirror == NULL) {
   769     THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
   805     THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
   770   } else {
   806   } else {
   825     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   861     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   826   }
   862   }
   827 
   863 
   828   Handle h_loader(THREAD, loader_oop);
   864   Handle h_loader(THREAD, loader_oop);
   829   Handle h_prot(THREAD, protection_domain);
   865   Handle h_prot(THREAD, protection_domain);
   830   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   866 
       
   867   jboolean link = !ClassForNameDeferLinking;
       
   868   jclass result = find_class_from_class_loader(env, h_name, init, link, h_loader,
   831                                                h_prot, false, THREAD);
   869                                                h_prot, false, THREAD);
   832 
       
   833   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   870   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   834     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   871     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   835   }
   872   }
   836   return result;
   873   return result;
   837 JVM_END
   874 JVM_END
   864     class_loader = from_class->class_loader();
   901     class_loader = from_class->class_loader();
   865     protection_domain = from_class->protection_domain();
   902     protection_domain = from_class->protection_domain();
   866   }
   903   }
   867   Handle h_loader(THREAD, class_loader);
   904   Handle h_loader(THREAD, class_loader);
   868   Handle h_prot  (THREAD, protection_domain);
   905   Handle h_prot  (THREAD, protection_domain);
   869   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   906   jclass result = find_class_from_class_loader(env, h_name, init, false, h_loader,
   870                                                h_prot, true, thread);
   907                                                h_prot, true, thread);
   871 
   908 
   872   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   909   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
   873     // this function is generally only used for class loading during verification.
   910     // this function is generally only used for class loading during verification.
   874     ResourceMark rm;
   911     ResourceMark rm;
   976 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
  1013 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
   977   JVMWrapper("JVM_FindLoadedClass");
  1014   JVMWrapper("JVM_FindLoadedClass");
   978   ResourceMark rm(THREAD);
  1015   ResourceMark rm(THREAD);
   979 
  1016 
   980   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
  1017   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
   981   Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
  1018   char* str = java_lang_String::as_utf8_string(h_name());
   982 
  1019 
   983   const char* str   = java_lang_String::as_utf8_string(string());
       
   984   // Sanity check, don't expect null
  1020   // Sanity check, don't expect null
   985   if (str == NULL) return NULL;
  1021   if (str == NULL) return NULL;
   986 
  1022 
   987   const int str_len = (int)strlen(str);
  1023   // Internalize the string, converting '.' to '/' in string.
       
  1024   char* p = (char*)str;
       
  1025   while (*p != '\0') {
       
  1026       if (*p == '.') {
       
  1027           *p = '/';
       
  1028       }
       
  1029       p++;
       
  1030   }
       
  1031 
       
  1032   const int str_len = (int)(p - str);
   988   if (str_len > Symbol::max_length()) {
  1033   if (str_len > Symbol::max_length()) {
   989     // It's impossible to create this class;  the name cannot fit
  1034     // It's impossible to create this class;  the name cannot fit
   990     // into the constant pool.
  1035     // into the constant pool.
   991     return NULL;
  1036     return NULL;
   992   }
  1037   }
  1103   }
  1148   }
  1104   return (jobjectArray) JNIHandles::make_local(env, result());
  1149   return (jobjectArray) JNIHandles::make_local(env, result());
  1105 JVM_END
  1150 JVM_END
  1106 
  1151 
  1107 
  1152 
  1108 JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
  1153 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
  1109   JVMWrapper("JVM_IsInterface");
  1154   JVMWrapper("JVM_IsInterface");
  1110   oop mirror = JNIHandles::resolve_non_null(cls);
  1155   oop mirror = JNIHandles::resolve_non_null(cls);
  1111   if (java_lang_Class::is_primitive(mirror)) {
  1156   if (java_lang_Class::is_primitive(mirror)) {
  1112     return JNI_FALSE;
  1157     return JNI_FALSE;
  1113   }
  1158   }
  1243       protection_domain  = caller_klass->protection_domain();
  1288       protection_domain  = caller_klass->protection_domain();
  1244     } else {
  1289     } else {
  1245       protection_domain = method->method_holder()->protection_domain();
  1290       protection_domain = method->method_holder()->protection_domain();
  1246     }
  1291     }
  1247 
  1292 
  1248     if ((!oopDesc::equals(previous_protection_domain, protection_domain)) && (protection_domain != NULL)) {
  1293     if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
  1249       local_array->push(protection_domain);
  1294       local_array->push(protection_domain);
  1250       previous_protection_domain = protection_domain;
  1295       previous_protection_domain = protection_domain;
  1251     }
  1296     }
  1252 
  1297 
  1253     if (is_privileged) break;
  1298     if (is_privileged) break;
  1276 
  1321 
  1277   return JNIHandles::make_local(env, result);
  1322   return JNIHandles::make_local(env, result);
  1278 JVM_END
  1323 JVM_END
  1279 
  1324 
  1280 
  1325 
  1281 JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
  1326 JVM_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
  1282   JVMWrapper("JVM_IsArrayClass");
  1327   JVMWrapper("JVM_IsArrayClass");
  1283   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1328   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1284   return (k != NULL) && k->is_array_klass() ? true : false;
  1329   return (k != NULL) && k->is_array_klass() ? true : false;
  1285 JVM_END
  1330 JVM_END
  1286 
  1331 
  1287 
  1332 
  1288 JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
  1333 JVM_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
  1289   JVMWrapper("JVM_IsPrimitiveClass");
  1334   JVMWrapper("JVM_IsPrimitiveClass");
  1290   oop mirror = JNIHandles::resolve_non_null(cls);
  1335   oop mirror = JNIHandles::resolve_non_null(cls);
  1291   return (jboolean) java_lang_Class::is_primitive(mirror);
  1336   return (jboolean) java_lang_Class::is_primitive(mirror);
  1292 JVM_END
  1337 JVM_END
  1293 
  1338 
  2251   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2296   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2252   return k->name()->as_utf8();
  2297   return k->name()->as_utf8();
  2253 JVM_END
  2298 JVM_END
  2254 
  2299 
  2255 
  2300 
  2256 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
  2301 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
  2257   JVMWrapper("JVM_GetClassCPTypes");
  2302   JVMWrapper("JVM_GetClassCPTypes");
  2258   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2303   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2259   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2304   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2260   // types will have length zero if this is not an InstanceKlass
  2305   // types will have length zero if this is not an InstanceKlass
  2261   // (length is determined by call to JVM_GetClassCPEntriesCount)
  2306   // (length is determined by call to JVM_GetClassCPEntriesCount)
  2267     }
  2312     }
  2268   }
  2313   }
  2269 JVM_END
  2314 JVM_END
  2270 
  2315 
  2271 
  2316 
  2272 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
  2317 JVM_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
  2273   JVMWrapper("JVM_GetClassCPEntriesCount");
  2318   JVMWrapper("JVM_GetClassCPEntriesCount");
  2274   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2319   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2275   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2320   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2276   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
  2321   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
  2277 JVM_END
  2322 JVM_END
  2278 
  2323 
  2279 
  2324 
  2280 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
  2325 JVM_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
  2281   JVMWrapper("JVM_GetClassFieldsCount");
  2326   JVMWrapper("JVM_GetClassFieldsCount");
  2282   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2327   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2283   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2328   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2284   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
  2329   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
  2285 JVM_END
  2330 JVM_END
  2286 
  2331 
  2287 
  2332 
  2288 JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
  2333 JVM_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
  2289   JVMWrapper("JVM_GetClassMethodsCount");
  2334   JVMWrapper("JVM_GetClassMethodsCount");
  2290   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2335   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2291   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2336   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2292   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->methods()->length();
  2337   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->methods()->length();
  2293 JVM_END
  2338 JVM_END
  2296 // The following methods, used for the verifier, are never called with
  2341 // The following methods, used for the verifier, are never called with
  2297 // array klasses, so a direct cast to InstanceKlass is safe.
  2342 // array klasses, so a direct cast to InstanceKlass is safe.
  2298 // Typically, these methods are called in a loop with bounds determined
  2343 // Typically, these methods are called in a loop with bounds determined
  2299 // by the results of JVM_GetClass{Fields,Methods}Count, which return
  2344 // by the results of JVM_GetClass{Fields,Methods}Count, which return
  2300 // zero for arrays.
  2345 // zero for arrays.
  2301 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
  2346 JVM_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
  2302   JVMWrapper("JVM_GetMethodIxExceptionIndexes");
  2347   JVMWrapper("JVM_GetMethodIxExceptionIndexes");
  2303   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2348   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2304   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2349   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2305   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2350   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2306   int length = method->checked_exceptions_length();
  2351   int length = method->checked_exceptions_length();
  2311     }
  2356     }
  2312   }
  2357   }
  2313 JVM_END
  2358 JVM_END
  2314 
  2359 
  2315 
  2360 
  2316 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
  2361 JVM_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
  2317   JVMWrapper("JVM_GetMethodIxExceptionsCount");
  2362   JVMWrapper("JVM_GetMethodIxExceptionsCount");
  2318   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2363   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2319   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2364   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2320   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2365   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2321   return method->checked_exceptions_length();
  2366   return method->checked_exceptions_length();
  2322 JVM_END
  2367 JVM_END
  2323 
  2368 
  2324 
  2369 
  2325 JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
  2370 JVM_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
  2326   JVMWrapper("JVM_GetMethodIxByteCode");
  2371   JVMWrapper("JVM_GetMethodIxByteCode");
  2327   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2372   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2328   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2373   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2329   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2374   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2330   memcpy(code, method->code_base(), method->code_size());
  2375   memcpy(code, method->code_base(), method->code_size());
  2331 JVM_END
  2376 JVM_END
  2332 
  2377 
  2333 
  2378 
  2334 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
  2379 JVM_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
  2335   JVMWrapper("JVM_GetMethodIxByteCodeLength");
  2380   JVMWrapper("JVM_GetMethodIxByteCodeLength");
  2336   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2381   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2337   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2382   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2338   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2383   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2339   return method->code_size();
  2384   return method->code_size();
  2340 JVM_END
  2385 JVM_END
  2341 
  2386 
  2342 
  2387 
  2343 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
  2388 JVM_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
  2344   JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
  2389   JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
  2345   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2390   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2346   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2391   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2347   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2392   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2348   ExceptionTable extable(method);
  2393   ExceptionTable extable(method);
  2351   entry->handler_pc = extable.handler_pc(entry_index);
  2396   entry->handler_pc = extable.handler_pc(entry_index);
  2352   entry->catchType  = extable.catch_type_index(entry_index);
  2397   entry->catchType  = extable.catch_type_index(entry_index);
  2353 JVM_END
  2398 JVM_END
  2354 
  2399 
  2355 
  2400 
  2356 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
  2401 JVM_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
  2357   JVMWrapper("JVM_GetMethodIxExceptionTableLength");
  2402   JVMWrapper("JVM_GetMethodIxExceptionTableLength");
  2358   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2403   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2359   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2404   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2360   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2405   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2361   return method->exception_table_length();
  2406   return method->exception_table_length();
  2362 JVM_END
  2407 JVM_END
  2363 
  2408 
  2364 
  2409 
  2365 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
  2410 JVM_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
  2366   JVMWrapper("JVM_GetMethodIxModifiers");
  2411   JVMWrapper("JVM_GetMethodIxModifiers");
  2367   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2412   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2368   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2413   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2369   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2414   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2370   return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
  2415   return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
  2371 JVM_END
  2416 JVM_END
  2372 
  2417 
  2373 
  2418 
  2374 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
  2419 JVM_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
  2375   JVMWrapper("JVM_GetFieldIxModifiers");
  2420   JVMWrapper("JVM_GetFieldIxModifiers");
  2376   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2421   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2377   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2422   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2378   return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
  2423   return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
  2379 JVM_END
  2424 JVM_END
  2380 
  2425 
  2381 
  2426 
  2382 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
  2427 JVM_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
  2383   JVMWrapper("JVM_GetMethodIxLocalsCount");
  2428   JVMWrapper("JVM_GetMethodIxLocalsCount");
  2384   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2429   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2385   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2430   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2386   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2431   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2387   return method->max_locals();
  2432   return method->max_locals();
  2388 JVM_END
  2433 JVM_END
  2389 
  2434 
  2390 
  2435 
  2391 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
  2436 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
  2392   JVMWrapper("JVM_GetMethodIxArgsSize");
  2437   JVMWrapper("JVM_GetMethodIxArgsSize");
  2393   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2438   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2394   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2439   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2395   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2440   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2396   return method->size_of_parameters();
  2441   return method->size_of_parameters();
  2397 JVM_END
  2442 JVM_END
  2398 
  2443 
  2399 
  2444 
  2400 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
  2445 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
  2401   JVMWrapper("JVM_GetMethodIxMaxStack");
  2446   JVMWrapper("JVM_GetMethodIxMaxStack");
  2402   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2447   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2403   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2448   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2404   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2449   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2405   return method->verifier_max_stack();
  2450   return method->verifier_max_stack();
  2406 JVM_END
  2451 JVM_END
  2407 
  2452 
  2408 
  2453 
  2409 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
  2454 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
  2410   JVMWrapper("JVM_IsConstructorIx");
  2455   JVMWrapper("JVM_IsConstructorIx");
  2411   ResourceMark rm(THREAD);
  2456   ResourceMark rm(THREAD);
  2412   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2457   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2413   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2458   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2414   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2459   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2415   return method->name() == vmSymbols::object_initializer_name();
  2460   return method->name() == vmSymbols::object_initializer_name();
  2416 JVM_END
  2461 JVM_END
  2417 
  2462 
  2418 
  2463 
  2419 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
  2464 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
  2420   JVMWrapper("JVM_IsVMGeneratedMethodIx");
  2465   JVMWrapper("JVM_IsVMGeneratedMethodIx");
  2421   ResourceMark rm(THREAD);
  2466   ResourceMark rm(THREAD);
  2422   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2467   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2423   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2468   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2424   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2469   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  2591   ShouldNotReachHere();
  2636   ShouldNotReachHere();
  2592   return 0;
  2637   return 0;
  2593 JVM_END
  2638 JVM_END
  2594 
  2639 
  2595 
  2640 
  2596 JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
  2641 JVM_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
  2597   JVMWrapper("JVM_GetCPMethodModifiers");
  2642   JVMWrapper("JVM_GetCPMethodModifiers");
  2598   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2643   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  2599   Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
  2644   Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
  2600   k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2645   k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  2601   k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
  2646   k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
  2960 
  3005 
  2961   if (millis < 0) {
  3006   if (millis < 0) {
  2962     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
  3007     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
  2963   }
  3008   }
  2964 
  3009 
  2965   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
  3010   if (thread->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
  2966     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  3011     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  2967   }
  3012   }
  2968 
  3013 
  2969   // Save current thread state and restore it at the end of this block.
  3014   // Save current thread state and restore it at the end of this block.
  2970   // And set new thread state to SLEEPING.
  3015   // And set new thread state to SLEEPING.
  2976   if (millis == 0) {
  3021   if (millis == 0) {
  2977     os::naked_yield();
  3022     os::naked_yield();
  2978   } else {
  3023   } else {
  2979     ThreadState old_state = thread->osthread()->get_state();
  3024     ThreadState old_state = thread->osthread()->get_state();
  2980     thread->osthread()->set_state(SLEEPING);
  3025     thread->osthread()->set_state(SLEEPING);
  2981     if (os::sleep(thread, millis, true) == OS_INTRPT) {
  3026     if (!thread->sleep(millis)) { // interrupted
  2982       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
  3027       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
  2983       // us while we were sleeping. We do not overwrite those.
  3028       // us while we were sleeping. We do not overwrite those.
  2984       if (!HAS_PENDING_EXCEPTION) {
  3029       if (!HAS_PENDING_EXCEPTION) {
  2985         if (event.should_commit()) {
  3030         if (event.should_commit()) {
  2986           post_thread_sleep_event(&event, millis);
  3031           post_thread_sleep_event(&event, millis);
  3057   ThreadsListHandle tlh(thread);
  3102   ThreadsListHandle tlh(thread);
  3058   JavaThread* receiver = NULL;
  3103   JavaThread* receiver = NULL;
  3059   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
  3104   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
  3060   if (is_alive) {
  3105   if (is_alive) {
  3061     // jthread refers to a live JavaThread.
  3106     // jthread refers to a live JavaThread.
  3062     Thread::interrupt(receiver);
  3107     receiver->interrupt();
  3063   }
  3108   }
  3064 JVM_END
  3109 JVM_END
  3065 
  3110 
  3066 
  3111 
  3067 JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
  3112 JVM_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
  3068   JVMWrapper("JVM_IsInterrupted");
  3113   JVMWrapper("JVM_IsInterrupted");
  3069 
  3114 
  3070   ThreadsListHandle tlh(thread);
  3115   ThreadsListHandle tlh(thread);
  3071   JavaThread* receiver = NULL;
  3116   JavaThread* receiver = NULL;
  3072   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
  3117   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
  3073   if (is_alive) {
  3118   if (is_alive) {
  3074     // jthread refers to a live JavaThread.
  3119     // jthread refers to a live JavaThread.
  3075     return (jboolean) Thread::is_interrupted(receiver, clear_interrupted != 0);
  3120     return (jboolean) receiver->is_interrupted(clear_interrupted != 0);
  3076   } else {
  3121   } else {
  3077     return JNI_FALSE;
  3122     return JNI_FALSE;
  3078   }
  3123   }
  3079 JVM_END
  3124 JVM_END
  3080 
  3125 
  3382   oop result = StringTable::intern(string, CHECK_NULL);
  3427   oop result = StringTable::intern(string, CHECK_NULL);
  3383   return (jstring) JNIHandles::make_local(env, result);
  3428   return (jstring) JNIHandles::make_local(env, result);
  3384 JVM_END
  3429 JVM_END
  3385 
  3430 
  3386 
  3431 
  3387 // Raw monitor support //////////////////////////////////////////////////////////////////////
  3432 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
  3388 
  3433 
  3389 // The lock routine below calls lock_without_safepoint_check in order to get a raw lock
  3434 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
  3390 // without interfering with the safepoint mechanism. The routines are not JVM_LEAF because
  3435 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
  3391 // they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check
  3436 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate
  3392 // that only works with java threads.
  3437 // in the safepoint protocol, thread suspension, thread interruption, or anything of that
       
  3438 // nature. JavaThreads will be "in native" when using this API from JDK code.
  3393 
  3439 
  3394 
  3440 
  3395 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
  3441 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
  3396   VM_Exit::block_if_vm_exited();
  3442   VM_Exit::block_if_vm_exited();
  3397   JVMWrapper("JVM_RawMonitorCreate");
  3443   JVMWrapper("JVM_RawMonitorCreate");
  3398   return new Mutex(Mutex::native, "JVM_RawMonitorCreate");
  3444   return new os::PlatformMutex();
  3399 }
  3445 }
  3400 
  3446 
  3401 
  3447 
  3402 JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
  3448 JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
  3403   VM_Exit::block_if_vm_exited();
  3449   VM_Exit::block_if_vm_exited();
  3404   JVMWrapper("JVM_RawMonitorDestroy");
  3450   JVMWrapper("JVM_RawMonitorDestroy");
  3405   delete ((Mutex*) mon);
  3451   delete ((os::PlatformMutex*) mon);
  3406 }
  3452 }
  3407 
  3453 
  3408 
  3454 
  3409 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
  3455 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
  3410   VM_Exit::block_if_vm_exited();
  3456   VM_Exit::block_if_vm_exited();
  3411   JVMWrapper("JVM_RawMonitorEnter");
  3457   JVMWrapper("JVM_RawMonitorEnter");
  3412   ((Mutex*) mon)->jvm_raw_lock();
  3458   ((os::PlatformMutex*) mon)->lock();
  3413   return 0;
  3459   return 0;
  3414 }
  3460 }
  3415 
  3461 
  3416 
  3462 
  3417 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
  3463 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
  3418   VM_Exit::block_if_vm_exited();
  3464   VM_Exit::block_if_vm_exited();
  3419   JVMWrapper("JVM_RawMonitorExit");
  3465   JVMWrapper("JVM_RawMonitorExit");
  3420   ((Mutex*) mon)->jvm_raw_unlock();
  3466   ((os::PlatformMutex*) mon)->unlock();
  3421 }
  3467 }
  3422 
  3468 
  3423 
  3469 
  3424 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3470 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  3425 
  3471 
  3426 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
  3472 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jboolean link,
  3427                                     Handle loader, Handle protection_domain,
  3473                                     Handle loader, Handle protection_domain,
  3428                                     jboolean throwError, TRAPS) {
  3474                                     jboolean throwError, TRAPS) {
       
  3475   // Initialization also implies linking - check for coherent args
       
  3476   assert((init && link) || !init, "incorrect use of init/link arguments");
       
  3477 
  3429   // Security Note:
  3478   // Security Note:
  3430   //   The Java level wrapper will perform the necessary security check allowing
  3479   //   The Java level wrapper will perform the necessary security check allowing
  3431   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3480   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  3432   //   the checkPackageAccess relative to the initiating class loader via the
  3481   //   the checkPackageAccess relative to the initiating class loader via the
  3433   //   protection_domain. The protection_domain is passed as NULL by the java code
  3482   //   protection_domain. The protection_domain is passed as NULL by the java code
  3434   //   if there is no security manager in 3-arg Class.forName().
  3483   //   if there is no security manager in 3-arg Class.forName().
  3435   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3484   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  3436 
  3485 
  3437   // Check if we should initialize the class
  3486   // Check if we should initialize the class (which implies linking), or just link it
  3438   if (init && klass->is_instance_klass()) {
  3487   if (init && klass->is_instance_klass()) {
  3439     klass->initialize(CHECK_NULL);
  3488     klass->initialize(CHECK_NULL);
       
  3489   } else if (link && klass->is_instance_klass()) {
       
  3490     InstanceKlass::cast(klass)->link_class(CHECK_NULL);
  3440   }
  3491   }
  3441   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3492   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
  3442 }
  3493 }
  3443 
  3494 
  3444 
  3495