534 oop exception = JNIHandles::resolve(throwable);
535 return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
536 JVM_END
537
538
539 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
540 JVMWrapper("JVM_GetStackTraceElement");
541 JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
542 oop exception = JNIHandles::resolve(throwable);
543 oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
544 return JNIHandles::make_local(env, element);
545 JVM_END
546
547
548 // java.lang.Object ///////////////////////////////////////////////
549
550
551 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
552 JVMWrapper("JVM_IHashCode");
553 // as implemented in the classic virtual machine; return 0 if object is NULL
554 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
555 JVM_END
556
557
558 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
559 JVMWrapper("JVM_MonitorWait");
560 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
561 JavaThreadInObjectWaitState jtiows(thread, ms != 0);
562 if (JvmtiExport::should_post_monitor_wait()) {
563 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
564
565 // The current thread already owns the monitor and it has not yet
566 // been added to the wait queue so the current thread cannot be
567 // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
568 // event handler cannot accidentally consume an unpark() meant for
569 // the ParkEvent associated with this ObjectMonitor.
570 }
571 ObjectSynchronizer::wait(obj, ms, CHECK);
572 JVM_END
573
574
575 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
576 JVMWrapper("JVM_MonitorNotify");
577 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
578 ObjectSynchronizer::notify(obj, CHECK);
579 JVM_END
580
581
582 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
583 JVMWrapper("JVM_MonitorNotifyAll");
584 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
585 ObjectSynchronizer::notifyall(obj, CHECK);
586 JVM_END
587
588
589 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
590 JVMWrapper("JVM_Clone");
591 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
592 const KlassHandle klass (THREAD, obj->klass());
593 JvmtiVMObjectAllocEventCollector oam;
594
595 #ifdef ASSERT
596 // Just checking that the cloneable flag is set correct
597 if (obj->is_array()) {
598 guarantee(klass->is_cloneable(), "all arrays are cloneable");
599 } else {
600 guarantee(obj->is_instance(), "should be instanceOop");
601 bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
602 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
603 }
604 #endif
605
606 // Check if class of obj supports the Cloneable interface.
607 // All arrays are considered to be cloneable (See JLS 20.1.5)
608 if (!klass->is_cloneable()) {
609 ResourceMark rm(THREAD);
610 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
611 }
880 ClassLoader::perf_app_classfile_bytes_read()->inc(len);
881 }
882
883 // Since exceptions can be thrown, class initialization can take place
884 // if name is NULL no check for class name in .class stream has to be made.
885 TempNewSymbol class_name = NULL;
886 if (name != NULL) {
887 const int str_len = (int)strlen(name);
888 if (str_len > Symbol::max_length()) {
889 // It's impossible to create this class; the name cannot fit
890 // into the constant pool.
891 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
892 }
893 class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
894 }
895
896 ResourceMark rm(THREAD);
897 ClassFileStream st((u1*) buf, len, (char *)source);
898 Handle class_loader (THREAD, JNIHandles::resolve(loader));
899 if (UsePerfData) {
900 is_lock_held_by_thread(class_loader,
901 ClassLoader::sync_JVMDefineClassLockFreeCounter(),
902 THREAD);
903 }
904 Handle protection_domain (THREAD, JNIHandles::resolve(pd));
905 Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
906 protection_domain, &st,
907 verify != 0,
908 CHECK_NULL);
909
910 if (TraceClassResolution && k != NULL) {
911 trace_class_resolution(k);
912 }
913
914 return (jclass) JNIHandles::make_local(env, k->java_mirror());
915 }
916
917
918 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
919 JVMWrapper2("JVM_DefineClass %s", name);
920
944 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
945 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
946
947 const char* str = java_lang_String::as_utf8_string(string());
948 // Sanity check, don't expect null
949 if (str == NULL) return NULL;
950
951 const int str_len = (int)strlen(str);
952 if (str_len > Symbol::max_length()) {
953 // It's impossible to create this class; the name cannot fit
954 // into the constant pool.
955 return NULL;
956 }
957 TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
958
959 // Security Note:
960 // The Java level wrapper will perform the necessary security check allowing
961 // us to pass the NULL as the initiating class loader.
962 Handle h_loader(THREAD, JNIHandles::resolve(loader));
963 if (UsePerfData) {
964 is_lock_held_by_thread(h_loader,
965 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
966 THREAD);
967 }
968
969 Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
970 h_loader,
971 Handle(),
972 CHECK_NULL);
973 #if INCLUDE_CDS
974 if (k == NULL) {
975 // If the class is not already loaded, try to see if it's in the shared
976 // archive for the current classloader (h_loader).
977 instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
978 klass_name, h_loader, CHECK_NULL);
979 k = ik();
980 }
981 #endif
982 return (k == NULL) ? NULL :
983 (jclass) JNIHandles::make_local(env, k->java_mirror());
3011 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
3012 // We need to re-resolve the java_thread, since a GC might have happened during the
3013 // acquire of the lock
3014 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
3015 if (thr == NULL) {
3016 return JNI_FALSE;
3017 } else {
3018 return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
3019 }
3020 JVM_END
3021
3022
3023 // Return true iff the current thread has locked the object passed in
3024
3025 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3026 JVMWrapper("JVM_HoldsLock");
3027 assert(THREAD->is_Java_thread(), "sanity check");
3028 if (obj == NULL) {
3029 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3030 }
3031 Handle h_obj(THREAD, JNIHandles::resolve(obj));
3032 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
3033 JVM_END
3034
3035
3036 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3037 JVMWrapper("JVM_DumpAllStacks");
3038 VM_PrintThreads op;
3039 VMThread::execute(&op);
3040 if (JvmtiExport::should_post_data_dump()) {
3041 JvmtiExport::post_data_dump();
3042 }
3043 JVM_END
3044
3045 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3046 JVMWrapper("JVM_SetNativeThreadName");
3047 ResourceMark rm(THREAD);
3048 oop java_thread = JNIHandles::resolve_non_null(jthread);
3049 JavaThread* thr = java_lang_Thread::thread(java_thread);
3050 // Thread naming only supported for the current thread, doesn't work for
3051 // target threads.
|
534 oop exception = JNIHandles::resolve(throwable);
535 return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
536 JVM_END
537
538
539 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
540 JVMWrapper("JVM_GetStackTraceElement");
541 JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
542 oop exception = JNIHandles::resolve(throwable);
543 oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
544 return JNIHandles::make_local(env, element);
545 JVM_END
546
547
548 // java.lang.Object ///////////////////////////////////////////////
549
550
551 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
552 JVMWrapper("JVM_IHashCode");
553 // as implemented in the classic virtual machine; return 0 if object is NULL
554 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle))) ;
555 JVM_END
556
557
558 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
559 JVMWrapper("JVM_MonitorWait");
560 Handle obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle)));
561 JavaThreadInObjectWaitState jtiows(thread, ms != 0);
562 if (JvmtiExport::should_post_monitor_wait()) {
563 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
564
565 // The current thread already owns the monitor and it has not yet
566 // been added to the wait queue so the current thread cannot be
567 // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
568 // event handler cannot accidentally consume an unpark() meant for
569 // the ParkEvent associated with this ObjectMonitor.
570 }
571 ObjectSynchronizer::wait(obj, ms, CHECK);
572 JVM_END
573
574
575 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
576 JVMWrapper("JVM_MonitorNotify");
577 Handle obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle)));
578 ObjectSynchronizer::notify(obj, CHECK);
579 JVM_END
580
581
582 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
583 JVMWrapper("JVM_MonitorNotifyAll");
584 Handle obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle)));
585 ObjectSynchronizer::notifyall(obj, CHECK);
586 JVM_END
587
588
589 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
590 JVMWrapper("JVM_Clone");
591 Handle obj(THREAD, oopDesc::bs()->read_barrier(JNIHandles::resolve_non_null(handle)));
592 const KlassHandle klass (THREAD, obj->klass());
593 JvmtiVMObjectAllocEventCollector oam;
594
595 #ifdef ASSERT
596 // Just checking that the cloneable flag is set correct
597 if (obj->is_array()) {
598 guarantee(klass->is_cloneable(), "all arrays are cloneable");
599 } else {
600 guarantee(obj->is_instance(), "should be instanceOop");
601 bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
602 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
603 }
604 #endif
605
606 // Check if class of obj supports the Cloneable interface.
607 // All arrays are considered to be cloneable (See JLS 20.1.5)
608 if (!klass->is_cloneable()) {
609 ResourceMark rm(THREAD);
610 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
611 }
880 ClassLoader::perf_app_classfile_bytes_read()->inc(len);
881 }
882
883 // Since exceptions can be thrown, class initialization can take place
884 // if name is NULL no check for class name in .class stream has to be made.
885 TempNewSymbol class_name = NULL;
886 if (name != NULL) {
887 const int str_len = (int)strlen(name);
888 if (str_len > Symbol::max_length()) {
889 // It's impossible to create this class; the name cannot fit
890 // into the constant pool.
891 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
892 }
893 class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
894 }
895
896 ResourceMark rm(THREAD);
897 ClassFileStream st((u1*) buf, len, (char *)source);
898 Handle class_loader (THREAD, JNIHandles::resolve(loader));
899 if (UsePerfData) {
900 Handle class_loader1 (THREAD, oopDesc::bs()->write_barrier(class_loader()));
901 is_lock_held_by_thread(class_loader1,
902 ClassLoader::sync_JVMDefineClassLockFreeCounter(),
903 THREAD);
904 }
905 Handle protection_domain (THREAD, JNIHandles::resolve(pd));
906 Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
907 protection_domain, &st,
908 verify != 0,
909 CHECK_NULL);
910
911 if (TraceClassResolution && k != NULL) {
912 trace_class_resolution(k);
913 }
914
915 return (jclass) JNIHandles::make_local(env, k->java_mirror());
916 }
917
918
919 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
920 JVMWrapper2("JVM_DefineClass %s", name);
921
945 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
946 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
947
948 const char* str = java_lang_String::as_utf8_string(string());
949 // Sanity check, don't expect null
950 if (str == NULL) return NULL;
951
952 const int str_len = (int)strlen(str);
953 if (str_len > Symbol::max_length()) {
954 // It's impossible to create this class; the name cannot fit
955 // into the constant pool.
956 return NULL;
957 }
958 TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
959
960 // Security Note:
961 // The Java level wrapper will perform the necessary security check allowing
962 // us to pass the NULL as the initiating class loader.
963 Handle h_loader(THREAD, JNIHandles::resolve(loader));
964 if (UsePerfData) {
965 Handle h_loader1(THREAD, oopDesc::bs()->write_barrier(h_loader()));
966 is_lock_held_by_thread(h_loader,
967 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
968 THREAD);
969 }
970
971 Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
972 h_loader,
973 Handle(),
974 CHECK_NULL);
975 #if INCLUDE_CDS
976 if (k == NULL) {
977 // If the class is not already loaded, try to see if it's in the shared
978 // archive for the current classloader (h_loader).
979 instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
980 klass_name, h_loader, CHECK_NULL);
981 k = ik();
982 }
983 #endif
984 return (k == NULL) ? NULL :
985 (jclass) JNIHandles::make_local(env, k->java_mirror());
3013 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
3014 // We need to re-resolve the java_thread, since a GC might have happened during the
3015 // acquire of the lock
3016 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
3017 if (thr == NULL) {
3018 return JNI_FALSE;
3019 } else {
3020 return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
3021 }
3022 JVM_END
3023
3024
3025 // Return true iff the current thread has locked the object passed in
3026
3027 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3028 JVMWrapper("JVM_HoldsLock");
3029 assert(THREAD->is_Java_thread(), "sanity check");
3030 if (obj == NULL) {
3031 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3032 }
3033 Handle h_obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve(obj)));
3034 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
3035 JVM_END
3036
3037
3038 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3039 JVMWrapper("JVM_DumpAllStacks");
3040 VM_PrintThreads op;
3041 VMThread::execute(&op);
3042 if (JvmtiExport::should_post_data_dump()) {
3043 JvmtiExport::post_data_dump();
3044 }
3045 JVM_END
3046
3047 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3048 JVMWrapper("JVM_SetNativeThreadName");
3049 ResourceMark rm(THREAD);
3050 oop java_thread = JNIHandles::resolve_non_null(jthread);
3051 JavaThread* thr = java_lang_Thread::thread(java_thread);
3052 // Thread naming only supported for the current thread, doesn't work for
3053 // target threads.
|