725 if (klass->has_finalizer()) { 726 assert(obj->is_instance(), "should be instanceOop"); 727 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL); 728 new_obj = Handle(THREAD, new_obj_oop); 729 } 730 731 return JNIHandles::make_local(env, new_obj()); 732 JVM_END 733 734 // java.io.File /////////////////////////////////////////////////////////////// 735 736 JVM_LEAF(char*, JVM_NativePath(char* path)) 737 JVMWrapper("JVM_NativePath"); 738 return os::native_path(path); 739 JVM_END 740 741 742 // Misc. class handling /////////////////////////////////////////////////////////// 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 755 756 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env)) 757 JVMWrapper("JVM_GetCallerClass"); 758 759 // Getting the class of the caller frame. 760 // 761 // The call stack at this point looks something like this: 762 // 763 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] 764 // [1] [ @CallerSensitive API.method ] 765 // [.] [ (skipped intermediate frames) ] 766 // [n] [ caller ] 767 vframeStream vfst(thread); 768 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass 769 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { 770 Method* m = vfst.method(); 771 assert(m != NULL, "sanity"); 772 switch (n) { 773 case 0: 774 // This must only be called from Reflection.getCallerClass 775 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { 846 // into the constant pool. 847 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); 848 } 849 850 TempNewSymbol h_name = SymbolTable::new_symbol(name); 851 852 oop loader_oop = JNIHandles::resolve(loader); 853 oop from_class = JNIHandles::resolve(caller); 854 oop protection_domain = NULL; 855 // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get 856 // NPE. Put it in another way, the bootstrap class loader has all permission and 857 // thus no checkPackageAccess equivalence in the VM class loader. 858 // The caller is also passed as NULL by the java code if there is no security 859 // manager to avoid the performance cost of getting the calling class. 860 if (from_class != NULL && loader_oop != NULL) { 861 protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain(); 862 } 863 864 Handle h_loader(THREAD, loader_oop); 865 Handle h_prot(THREAD, protection_domain); 866 867 jboolean link = !ClassForNameDeferLinking; 868 jclass result = find_class_from_class_loader(env, h_name, init, link, h_loader, 869 h_prot, false, THREAD); 870 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 871 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 872 } 873 return result; 874 JVM_END 875 876 // Currently only called from the old verifier. 877 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, 878 jboolean init, jclass from)) 879 JVMWrapper("JVM_FindClassFromClass"); 880 if (name == NULL) { 881 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), "No class name given"); 882 } 883 if ((int)strlen(name) > Symbol::max_length()) { 884 // It's impossible to create this class; the name cannot fit 885 // into the constant pool. 886 Exceptions::fthrow(THREAD_AND_LOCATION, 887 vmSymbols::java_lang_NoClassDefFoundError(), 888 "Class name exceeds maximum length of %d: %s", 889 Symbol::max_length(), 890 name); 891 return 0; 892 } 893 TempNewSymbol h_name = SymbolTable::new_symbol(name); 894 oop from_class_oop = JNIHandles::resolve(from); 895 Klass* from_class = (from_class_oop == NULL) 896 ? (Klass*)NULL 897 : java_lang_Class::as_Klass(from_class_oop); 898 oop class_loader = NULL; 899 oop protection_domain = NULL; 900 if (from_class != NULL) { 901 class_loader = from_class->class_loader(); 902 protection_domain = from_class->protection_domain(); 903 } 904 Handle h_loader(THREAD, class_loader); 905 Handle h_prot (THREAD, protection_domain); 906 jclass result = find_class_from_class_loader(env, h_name, init, false, h_loader, 907 h_prot, true, thread); 908 909 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 910 // this function is generally only used for class loading during verification. 911 ResourceMark rm; 912 oop from_mirror = JNIHandles::resolve_non_null(from); 913 Klass* from_class = java_lang_Class::as_Klass(from_mirror); 914 const char * from_name = from_class->external_name(); 915 916 oop mirror = JNIHandles::resolve_non_null(result); 917 Klass* to_class = java_lang_Class::as_Klass(mirror); 918 const char * to = to_class->external_name(); 919 log_debug(class, resolve)("%s %s (verification)", from_name, to); 920 } 921 922 return result; 923 JVM_END 924 925 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) { 926 if (loader.is_null()) { 3452 } 3453 3454 3455 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) { 3456 VM_Exit::block_if_vm_exited(); 3457 JVMWrapper("JVM_RawMonitorEnter"); 3458 ((os::PlatformMutex*) mon)->lock(); 3459 return 0; 3460 } 3461 3462 3463 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) { 3464 VM_Exit::block_if_vm_exited(); 3465 JVMWrapper("JVM_RawMonitorExit"); 3466 ((os::PlatformMutex*) mon)->unlock(); 3467 } 3468 3469 3470 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 3471 3472 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, jboolean link, 3473 Handle loader, Handle protection_domain, 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 3478 // Security Note: 3479 // The Java level wrapper will perform the necessary security check allowing 3480 // us to pass the NULL as the initiating class loader. The VM is responsible for 3481 // the checkPackageAccess relative to the initiating class loader via the 3482 // protection_domain. The protection_domain is passed as NULL by the java code 3483 // if there is no security manager in 3-arg Class.forName(). 3484 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 3485 3486 // Check if we should initialize the class (which implies linking), or just link it 3487 if (init && klass->is_instance_klass()) { 3488 klass->initialize(CHECK_NULL); 3489 } else if (link && klass->is_instance_klass()) { 3490 InstanceKlass::cast(klass)->link_class(CHECK_NULL); 3491 } 3492 return (jclass) JNIHandles::make_local(env, klass->java_mirror()); 3493 } 3494 3495 3496 // Method /////////////////////////////////////////////////////////////////////////////////////////// 3497 3498 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)) 3499 JVMWrapper("JVM_InvokeMethod"); 3500 Handle method_handle; 3501 if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) { 3502 method_handle = Handle(THREAD, JNIHandles::resolve(method)); 3503 Handle receiver(THREAD, JNIHandles::resolve(obj)); 3504 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 3505 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL); 3506 jobject res = JNIHandles::make_local(env, result); 3507 if (JvmtiExport::should_post_vm_object_alloc()) { 3508 oop ret_type = java_lang_reflect_Method::return_type(method_handle()); 3509 assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!"); 3510 if (java_lang_Class::is_primitive(ret_type)) { | 725 if (klass->has_finalizer()) { 726 assert(obj->is_instance(), "should be instanceOop"); 727 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL); 728 new_obj = Handle(THREAD, new_obj_oop); 729 } 730 731 return JNIHandles::make_local(env, new_obj()); 732 JVM_END 733 734 // java.io.File /////////////////////////////////////////////////////////////// 735 736 JVM_LEAF(char*, JVM_NativePath(char* path)) 737 JVMWrapper("JVM_NativePath"); 738 return os::native_path(path); 739 JVM_END 740 741 742 // Misc. class handling /////////////////////////////////////////////////////////// 743 744 745 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env)) 746 JVMWrapper("JVM_GetCallerClass"); 747 748 // Getting the class of the caller frame. 749 // 750 // The call stack at this point looks something like this: 751 // 752 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] 753 // [1] [ @CallerSensitive API.method ] 754 // [.] [ (skipped intermediate frames) ] 755 // [n] [ caller ] 756 vframeStream vfst(thread); 757 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass 758 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { 759 Method* m = vfst.method(); 760 assert(m != NULL, "sanity"); 761 switch (n) { 762 case 0: 763 // This must only be called from Reflection.getCallerClass 764 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { 835 // into the constant pool. 836 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name); 837 } 838 839 TempNewSymbol h_name = SymbolTable::new_symbol(name); 840 841 oop loader_oop = JNIHandles::resolve(loader); 842 oop from_class = JNIHandles::resolve(caller); 843 oop protection_domain = NULL; 844 // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get 845 // NPE. Put it in another way, the bootstrap class loader has all permission and 846 // thus no checkPackageAccess equivalence in the VM class loader. 847 // The caller is also passed as NULL by the java code if there is no security 848 // manager to avoid the performance cost of getting the calling class. 849 if (from_class != NULL && loader_oop != NULL) { 850 protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain(); 851 } 852 853 Handle h_loader(THREAD, loader_oop); 854 Handle h_prot(THREAD, protection_domain); 855 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 856 h_prot, false, THREAD); 857 858 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 859 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); 860 } 861 return result; 862 JVM_END 863 864 // Currently only called from the old verifier. 865 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, 866 jboolean init, jclass from)) 867 JVMWrapper("JVM_FindClassFromClass"); 868 if (name == NULL) { 869 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), "No class name given"); 870 } 871 if ((int)strlen(name) > Symbol::max_length()) { 872 // It's impossible to create this class; the name cannot fit 873 // into the constant pool. 874 Exceptions::fthrow(THREAD_AND_LOCATION, 875 vmSymbols::java_lang_NoClassDefFoundError(), 876 "Class name exceeds maximum length of %d: %s", 877 Symbol::max_length(), 878 name); 879 return 0; 880 } 881 TempNewSymbol h_name = SymbolTable::new_symbol(name); 882 oop from_class_oop = JNIHandles::resolve(from); 883 Klass* from_class = (from_class_oop == NULL) 884 ? (Klass*)NULL 885 : java_lang_Class::as_Klass(from_class_oop); 886 oop class_loader = NULL; 887 oop protection_domain = NULL; 888 if (from_class != NULL) { 889 class_loader = from_class->class_loader(); 890 protection_domain = from_class->protection_domain(); 891 } 892 Handle h_loader(THREAD, class_loader); 893 Handle h_prot (THREAD, protection_domain); 894 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 895 h_prot, true, thread); 896 897 if (log_is_enabled(Debug, class, resolve) && result != NULL) { 898 // this function is generally only used for class loading during verification. 899 ResourceMark rm; 900 oop from_mirror = JNIHandles::resolve_non_null(from); 901 Klass* from_class = java_lang_Class::as_Klass(from_mirror); 902 const char * from_name = from_class->external_name(); 903 904 oop mirror = JNIHandles::resolve_non_null(result); 905 Klass* to_class = java_lang_Class::as_Klass(mirror); 906 const char * to = to_class->external_name(); 907 log_debug(class, resolve)("%s %s (verification)", from_name, to); 908 } 909 910 return result; 911 JVM_END 912 913 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) { 914 if (loader.is_null()) { 3440 } 3441 3442 3443 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) { 3444 VM_Exit::block_if_vm_exited(); 3445 JVMWrapper("JVM_RawMonitorEnter"); 3446 ((os::PlatformMutex*) mon)->lock(); 3447 return 0; 3448 } 3449 3450 3451 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) { 3452 VM_Exit::block_if_vm_exited(); 3453 JVMWrapper("JVM_RawMonitorExit"); 3454 ((os::PlatformMutex*) mon)->unlock(); 3455 } 3456 3457 3458 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 3459 3460 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, 3461 Handle loader, Handle protection_domain, 3462 jboolean throwError, TRAPS) { 3463 // Security Note: 3464 // The Java level wrapper will perform the necessary security check allowing 3465 // us to pass the NULL as the initiating class loader. The VM is responsible for 3466 // the checkPackageAccess relative to the initiating class loader via the 3467 // protection_domain. The protection_domain is passed as NULL by the java code 3468 // if there is no security manager in 3-arg Class.forName(). 3469 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 3470 3471 // Check if we should initialize the class 3472 if (init && klass->is_instance_klass()) { 3473 klass->initialize(CHECK_NULL); 3474 } 3475 return (jclass) JNIHandles::make_local(env, klass->java_mirror()); 3476 } 3477 3478 3479 // Method /////////////////////////////////////////////////////////////////////////////////////////// 3480 3481 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)) 3482 JVMWrapper("JVM_InvokeMethod"); 3483 Handle method_handle; 3484 if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) { 3485 method_handle = Handle(THREAD, JNIHandles::resolve(method)); 3486 Handle receiver(THREAD, JNIHandles::resolve(obj)); 3487 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0))); 3488 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL); 3489 jobject res = JNIHandles::make_local(env, result); 3490 if (JvmtiExport::should_post_vm_object_alloc()) { 3491 oop ret_type = java_lang_reflect_Method::return_type(method_handle()); 3492 assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!"); 3493 if (java_lang_Class::is_primitive(ret_type)) { |