< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

  48 #include "interpreter/bytecode.hpp"
  49 #include "interpreter/bytecodeUtils.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "logging/log.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/referenceType.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/constantPool.hpp"
  58 #include "oops/fieldStreams.inline.hpp"
  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.hpp"
  62 #include "oops/recordComponent.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "prims/jvm_misc.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/jvmtiThreadState.hpp"
  69 #include "prims/stackwalk.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"

  72 #include "runtime/globals_extension.hpp"
  73 #include "runtime/handles.inline.hpp"
  74 #include "runtime/init.hpp"
  75 #include "runtime/interfaceSupport.inline.hpp"
  76 #include "runtime/deoptimization.hpp"
  77 #include "runtime/handshake.hpp"
  78 #include "runtime/java.hpp"
  79 #include "runtime/javaCalls.hpp"
  80 #include "runtime/jfieldIDWorkaround.hpp"
  81 #include "runtime/jniHandles.inline.hpp"
  82 #include "runtime/os.inline.hpp"
  83 #include "runtime/osThread.hpp"
  84 #include "runtime/perfData.hpp"
  85 #include "runtime/reflection.hpp"
  86 #include "runtime/synchronizer.hpp"
  87 #include "runtime/thread.inline.hpp"
  88 #include "runtime/threadSMR.hpp"
  89 #include "runtime/vframe.inline.hpp"
  90 #include "runtime/vmOperations.hpp"
  91 #include "runtime/vm_version.hpp"

 515   if (!java_lang_Throwable::get_top_method_and_bci(exc, &method, &bci)) {
 516     return NULL;
 517   }
 518   if (method->is_native()) {
 519     return NULL;
 520   }
 521 
 522   stringStream ss;
 523   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
 524   if (ok) {
 525     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_NULL);
 526     return (jstring) JNIHandles::make_local(THREAD, result);
 527   } else {
 528     return NULL;
 529   }
 530 JVM_END
 531 
 532 // java.lang.StackTraceElement //////////////////////////////////////////////
 533 
 534 
 535 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
 536   Handle exception(THREAD, JNIHandles::resolve(throwable));
 537   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 538   objArrayHandle stack_trace(THREAD, st);
 539   // Fill in the allocated stack trace
 540   java_lang_Throwable::get_stack_trace_elements(exception, stack_trace, CHECK);
 541 JVM_END
 542 
 543 
 544 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 545   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 546   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 547   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 548 JVM_END
 549 
 550 
 551 // java.lang.StackWalker //////////////////////////////////////////////////////
 552 
 553 
 554 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 555                                      jint skip_frames, jint frame_count, jint start_index,
 556                                      jobjectArray frames))
 557   if (!thread->has_last_Java_frame()) {
 558     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL);
 559   }
 560 
 561   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 562 

 563   // frames array is a Class<?>[] array when only getting caller reference,
 564   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 565   // be null.
 566   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 567   objArrayHandle frames_array_h(THREAD, fa);
 568 
 569   int limit = start_index + frame_count;
 570   if (frames_array_h->length() < limit) {
 571     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
 572   }
 573 
 574   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
 575                                start_index, frames_array_h, CHECK_NULL);
 576   return JNIHandles::make_local(THREAD, result);
 577 JVM_END
 578 
 579 
 580 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 581                                   jint frame_count, jint start_index,
 582                                   jobjectArray frames))
 583   // frames array is a Class<?>[] array when only getting caller reference,
 584   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 585   // be null.
 586   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 587   objArrayHandle frames_array_h(THREAD, fa);
 588 
 589   int limit = start_index+frame_count;
 590   if (frames_array_h->length() < limit) {
 591     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 592   }
 593 
 594   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 595   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 596                                    start_index, frames_array_h, THREAD);









 597 JVM_END
 598 
 599 // java.lang.Object ///////////////////////////////////////////////
 600 
 601 
 602 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 603   // as implemented in the classic virtual machine; return 0 if object is NULL
 604   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 605 JVM_END
 606 
 607 
 608 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 609   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 610   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 611   if (JvmtiExport::should_post_monitor_wait()) {
 612     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 613 
 614     // The current thread already owns the monitor and it has not yet
 615     // been added to the wait queue so the current thread cannot be
 616     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT

 677   // "gc-robust" by this stage.
 678   if (klass->has_finalizer()) {
 679     assert(obj->is_instance(), "should be instanceOop");
 680     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 681     new_obj = Handle(THREAD, new_obj_oop);
 682   }
 683 
 684   return JNIHandles::make_local(THREAD, new_obj());
 685 JVM_END
 686 
 687 // java.lang.ref.Finalizer ////////////////////////////////////////////////////
 688 
 689 JVM_ENTRY(void, JVM_ReportFinalizationComplete(JNIEnv * env, jobject finalizee))
 690   MANAGEMENT_ONLY(FinalizerService::on_complete(JNIHandles::resolve_non_null(finalizee), THREAD);)
 691 JVM_END
 692 
 693 JVM_ENTRY(jboolean, JVM_IsFinalizationEnabled(JNIEnv * env))
 694   return InstanceKlass::is_finalization_enabled();
 695 JVM_END
 696 






 697 // java.io.File ///////////////////////////////////////////////////////////////
 698 
 699 JVM_LEAF(char*, JVM_NativePath(char* path))
 700   return os::native_path(path);
 701 JVM_END
 702 
 703 
 704 // Misc. class handling ///////////////////////////////////////////////////////////
 705 
 706 
 707 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
 708   // Getting the class of the caller frame.
 709   //
 710   // The call stack at this point looks something like this:
 711   //
 712   // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
 713   // [1] [ @CallerSensitive API.method                                   ]
 714   // [.] [ (skipped intermediate frames)                                 ]
 715   // [n] [ caller                                                        ]
 716   vframeStream vfst(thread);

3024   JavaThread* receiver = NULL;
3025   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, &java_thread);
3026   java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
3027 
3028   if (is_alive) {
3029     // jthread refers to a live JavaThread.
3030     Thread::set_priority(receiver, (ThreadPriority)prio);
3031   }
3032   // Implied else: If the JavaThread hasn't started yet, then the
3033   // priority set in the java.lang.Thread object above will be pushed
3034   // down when it does start.
3035 JVM_END
3036 
3037 
3038 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3039   if (os::dont_yield()) return;
3040   HOTSPOT_THREAD_YIELD();
3041   os::naked_yield();
3042 JVM_END
3043 
3044 static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) {
3045   assert(event != NULL, "invariant");
3046   assert(event->should_commit(), "invariant");
3047   event->set_time(millis);
3048   event->commit();
3049 }
3050 
3051 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3052   if (millis < 0) {
3053     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3054   }
3055 
3056   if (thread->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
3057     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3058   }
3059 
3060   // Save current thread state and restore it at the end of this block.
3061   // And set new thread state to SLEEPING.
3062   JavaThreadSleepState jtss(thread);
3063 
3064   HOTSPOT_THREAD_SLEEP_BEGIN(millis);
3065   EventThreadSleep event;
3066 
3067   if (millis == 0) {
3068     os::naked_yield();
3069   } else {
3070     ThreadState old_state = thread->osthread()->get_state();
3071     thread->osthread()->set_state(SLEEPING);
3072     if (!thread->sleep(millis)) { // interrupted
3073       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3074       // us while we were sleeping. We do not overwrite those.
3075       if (!HAS_PENDING_EXCEPTION) {
3076         if (event.should_commit()) {
3077           post_thread_sleep_event(&event, millis);
3078         }
3079         HOTSPOT_THREAD_SLEEP_END(1);
3080 
3081         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3082         // to properly restore the thread state.  That's likely wrong.
3083         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3084       }
3085     }
3086     thread->osthread()->set_state(old_state);
3087   }
3088   if (event.should_commit()) {
3089     post_thread_sleep_event(&event, millis);
3090   }
3091   HOTSPOT_THREAD_SLEEP_END(0);
3092 JVM_END
3093 
3094 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3095   oop jthread = thread->threadObj();
3096   assert(jthread != NULL, "no current thread!");
3097   return JNIHandles::make_local(THREAD, jthread);
3098 JVM_END
3099 
3100 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3101   ThreadsListHandle tlh(thread);
3102   JavaThread* receiver = NULL;
3103   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
3104   if (is_alive) {
3105     // jthread refers to a live JavaThread.
3106     receiver->interrupt();
3107   }
3108 JVM_END
3109 




























3110 
3111 // Return true iff the current thread has locked the object passed in
3112 
3113 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3114   if (obj == NULL) {
3115     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3116   }
3117   Handle h_obj(THREAD, JNIHandles::resolve(obj));
3118   return ObjectSynchronizer::current_thread_holds_lock(thread, h_obj);
3119 JVM_END
3120 




3121 
3122 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3123   VM_PrintThreads op;
3124   VMThread::execute(&op);
3125   if (JvmtiExport::should_post_data_dump()) {
3126     JvmtiExport::post_data_dump();
3127   }
3128 JVM_END
3129 
3130 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3131   // We don't use a ThreadsListHandle here because the current thread
3132   // must be alive.
3133   oop java_thread = JNIHandles::resolve_non_null(jthread);
3134   JavaThread* thr = java_lang_Thread::thread(java_thread);
3135   if (thread == thr && !thr->has_attached_via_jni()) {
3136     // Thread naming is only supported for the current thread and
3137     // we don't set the name of an attached thread to avoid stepping
3138     // on other programs.
3139     ResourceMark rm(thread);
3140     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));

3853   InstanceKlass* ik = vmClasses::String_klass();
3854   objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
3855   objArrayHandle result_h(THREAD, r);
3856 
3857   int index = 0;
3858   for (int j = 0; j < num_flags; j++, index++) {
3859     Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
3860     result_h->obj_at_put(index, h());
3861   }
3862   for (int i = 0; i < num_args; i++, index++) {
3863     Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
3864     result_h->obj_at_put(index, h());
3865   }
3866   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
3867 JVM_END
3868 
3869 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
3870   return os::get_signal_number(name);
3871 JVM_END
3872 

















































































  48 #include "interpreter/bytecode.hpp"
  49 #include "interpreter/bytecodeUtils.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "logging/log.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/referenceType.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/constantPool.hpp"
  58 #include "oops/fieldStreams.inline.hpp"
  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.hpp"
  62 #include "oops/recordComponent.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "prims/jvm_misc.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/jvmtiThreadState.inline.hpp"
  69 #include "prims/stackwalk.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/continuation.hpp"
  73 #include "runtime/globals_extension.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/init.hpp"
  76 #include "runtime/interfaceSupport.inline.hpp"
  77 #include "runtime/deoptimization.hpp"
  78 #include "runtime/handshake.hpp"
  79 #include "runtime/java.hpp"
  80 #include "runtime/javaCalls.hpp"
  81 #include "runtime/jfieldIDWorkaround.hpp"
  82 #include "runtime/jniHandles.inline.hpp"
  83 #include "runtime/os.inline.hpp"
  84 #include "runtime/osThread.hpp"
  85 #include "runtime/perfData.hpp"
  86 #include "runtime/reflection.hpp"
  87 #include "runtime/synchronizer.hpp"
  88 #include "runtime/thread.inline.hpp"
  89 #include "runtime/threadSMR.hpp"
  90 #include "runtime/vframe.inline.hpp"
  91 #include "runtime/vmOperations.hpp"
  92 #include "runtime/vm_version.hpp"

 516   if (!java_lang_Throwable::get_top_method_and_bci(exc, &method, &bci)) {
 517     return NULL;
 518   }
 519   if (method->is_native()) {
 520     return NULL;
 521   }
 522 
 523   stringStream ss;
 524   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
 525   if (ok) {
 526     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_NULL);
 527     return (jstring) JNIHandles::make_local(THREAD, result);
 528   } else {
 529     return NULL;
 530   }
 531 JVM_END
 532 
 533 // java.lang.StackTraceElement //////////////////////////////////////////////
 534 
 535 
 536 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject backtrace, jint depth))
 537   Handle backtraceh(THREAD, JNIHandles::resolve(backtrace));
 538   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 539   objArrayHandle stack_trace(THREAD, st);
 540   // Fill in the allocated stack trace
 541   java_lang_Throwable::get_stack_trace_elements(depth, backtraceh, stack_trace, CHECK);
 542 JVM_END
 543 
 544 
 545 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 546   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 547   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 548   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 549 JVM_END
 550 
 551 
 552 // java.lang.StackWalker //////////////////////////////////////////////////////
 553 
 554 
 555 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 556                                      jint skip_frames, jobject contScope, jobject cont,
 557                                      jint frame_count, jint start_index, jobjectArray frames))
 558   if (!thread->has_last_Java_frame()) {
 559     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL);
 560   }
 561 
 562   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 563   Handle contScope_h(THREAD, JNIHandles::resolve(contScope));
 564   Handle cont_h(THREAD, JNIHandles::resolve(cont));
 565   // frames array is a Class<?>[] array when only getting caller reference,
 566   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 567   // be null.
 568   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 569   objArrayHandle frames_array_h(THREAD, fa);
 570 
 571   int limit = start_index + frame_count;
 572   if (frames_array_h->length() < limit) {
 573     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
 574   }
 575 
 576   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, contScope_h, cont_h,
 577                                frame_count, start_index, frames_array_h, CHECK_NULL);
 578   return JNIHandles::make_local(THREAD, result);
 579 JVM_END
 580 
 581 
 582 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 583                                   jint frame_count, jint start_index,
 584                                   jobjectArray frames))
 585   // frames array is a Class<?>[] array when only getting caller reference,
 586   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 587   // be null.
 588   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 589   objArrayHandle frames_array_h(THREAD, fa);
 590 
 591   int limit = start_index+frame_count;
 592   if (frames_array_h->length() < limit) {
 593     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 594   }
 595 
 596   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 597   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 598                                   start_index, frames_array_h, THREAD);
 599 JVM_END
 600 
 601 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 602     objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 603     objArrayHandle frames_array_h(THREAD, fa);
 604     Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 605     Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 606 
 607     StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 608 JVM_END
 609 
 610 // java.lang.Object ///////////////////////////////////////////////
 611 
 612 
 613 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 614   // as implemented in the classic virtual machine; return 0 if object is NULL
 615   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 616 JVM_END
 617 
 618 
 619 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 620   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 621   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 622   if (JvmtiExport::should_post_monitor_wait()) {
 623     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 624 
 625     // The current thread already owns the monitor and it has not yet
 626     // been added to the wait queue so the current thread cannot be
 627     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT

 688   // "gc-robust" by this stage.
 689   if (klass->has_finalizer()) {
 690     assert(obj->is_instance(), "should be instanceOop");
 691     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 692     new_obj = Handle(THREAD, new_obj_oop);
 693   }
 694 
 695   return JNIHandles::make_local(THREAD, new_obj());
 696 JVM_END
 697 
 698 // java.lang.ref.Finalizer ////////////////////////////////////////////////////
 699 
 700 JVM_ENTRY(void, JVM_ReportFinalizationComplete(JNIEnv * env, jobject finalizee))
 701   MANAGEMENT_ONLY(FinalizerService::on_complete(JNIHandles::resolve_non_null(finalizee), THREAD);)
 702 JVM_END
 703 
 704 JVM_ENTRY(jboolean, JVM_IsFinalizationEnabled(JNIEnv * env))
 705   return InstanceKlass::is_finalization_enabled();
 706 JVM_END
 707 
 708 // jdk.internal.vm.Continuation /////////////////////////////////////////////////////
 709 
 710 JVM_ENTRY(void, JVM_RegisterContinuationMethods(JNIEnv *env, jclass cls))
 711   CONT_RegisterNativeMethods(env, cls);
 712 JVM_END
 713 
 714 // java.io.File ///////////////////////////////////////////////////////////////
 715 
 716 JVM_LEAF(char*, JVM_NativePath(char* path))
 717   return os::native_path(path);
 718 JVM_END
 719 
 720 
 721 // Misc. class handling ///////////////////////////////////////////////////////////
 722 
 723 
 724 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
 725   // Getting the class of the caller frame.
 726   //
 727   // The call stack at this point looks something like this:
 728   //
 729   // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
 730   // [1] [ @CallerSensitive API.method                                   ]
 731   // [.] [ (skipped intermediate frames)                                 ]
 732   // [n] [ caller                                                        ]
 733   vframeStream vfst(thread);

3041   JavaThread* receiver = NULL;
3042   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, &java_thread);
3043   java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
3044 
3045   if (is_alive) {
3046     // jthread refers to a live JavaThread.
3047     Thread::set_priority(receiver, (ThreadPriority)prio);
3048   }
3049   // Implied else: If the JavaThread hasn't started yet, then the
3050   // priority set in the java.lang.Thread object above will be pushed
3051   // down when it does start.
3052 JVM_END
3053 
3054 
3055 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3056   if (os::dont_yield()) return;
3057   HOTSPOT_THREAD_YIELD();
3058   os::naked_yield();
3059 JVM_END
3060 







3061 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3062   if (millis < 0) {
3063     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3064   }
3065 
3066   if (thread->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
3067     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3068   }
3069 
3070   // Save current thread state and restore it at the end of this block.
3071   // And set new thread state to SLEEPING.
3072   JavaThreadSleepState jtss(thread);
3073 
3074   HOTSPOT_THREAD_SLEEP_BEGIN(millis);

3075 
3076   if (millis == 0) {
3077     os::naked_yield();
3078   } else {
3079     ThreadState old_state = thread->osthread()->get_state();
3080     thread->osthread()->set_state(SLEEPING);
3081     if (!thread->sleep(millis)) { // interrupted
3082       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3083       // us while we were sleeping. We do not overwrite those.
3084       if (!HAS_PENDING_EXCEPTION) {



3085         HOTSPOT_THREAD_SLEEP_END(1);
3086 
3087         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3088         // to properly restore the thread state.  That's likely wrong.
3089         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3090       }
3091     }
3092     thread->osthread()->set_state(old_state);
3093   }



3094   HOTSPOT_THREAD_SLEEP_END(0);
3095 JVM_END
3096 
3097 JVM_ENTRY(jobject, JVM_CurrentThread0(JNIEnv* env, jclass threadClass))
3098   oop jthread = thread->threadObj();
3099   assert(jthread != NULL, "no current thread!");
3100   return JNIHandles::make_local(THREAD, jthread);
3101 JVM_END
3102 
3103 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3104   ThreadsListHandle tlh(thread);
3105   JavaThread* receiver = NULL;
3106   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
3107   if (is_alive) {
3108     // jthread refers to a live JavaThread.
3109     receiver->interrupt();
3110   }
3111 JVM_END
3112 
3113 JVM_ENTRY(jobject, JVM_ScopeLocalCache(JNIEnv* env, jclass threadClass))
3114   oop theCache = thread->scopeLocalCache();
3115   if (theCache) {
3116     arrayOop objs = arrayOop(theCache);
3117     assert(objs->length() == ScopeLocalCacheSize * 2, "wrong length");
3118   }
3119   return JNIHandles::make_local(THREAD, theCache);
3120 JVM_END
3121 
3122 JVM_ENTRY(void, JVM_SetScopeLocalCache(JNIEnv* env, jclass threadClass,
3123                                    jobject theCache))
3124   arrayOop objs = arrayOop(JNIHandles::resolve(theCache));
3125   if (objs != NULL) {
3126     assert(objs->length() == ScopeLocalCacheSize * 2, "wrong length");
3127   }
3128   thread->set_scopeLocalCache(objs);
3129 JVM_END
3130 
3131 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3132   oop theThread = thread->vthread();
3133   assert (theThread != (oop)NULL, "no current thread!");
3134   return JNIHandles::make_local(THREAD, theThread);
3135 JVM_END
3136 
3137 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jclass threadClass,
3138                                      jobject theThread))
3139   thread->set_vthread(JNIHandles::resolve(theThread));
3140 JVM_END
3141 
3142 // Return true iff the current thread has locked the object passed in
3143 
3144 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3145   if (obj == NULL) {
3146     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3147   }
3148   Handle h_obj(THREAD, JNIHandles::resolve(obj));
3149   return ObjectSynchronizer::current_thread_holds_lock(thread, h_obj);
3150 JVM_END
3151 
3152 JVM_ENTRY(jobject, JVM_GetStackTrace(JNIEnv *env, jobject jthread))
3153   oop trace = java_lang_Thread::async_get_stack_trace(JNIHandles::resolve(jthread), THREAD);
3154   return JNIHandles::make_local(THREAD, trace);
3155 JVM_END
3156 
3157 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3158   VM_PrintThreads op;
3159   VMThread::execute(&op);
3160   if (JvmtiExport::should_post_data_dump()) {
3161     JvmtiExport::post_data_dump();
3162   }
3163 JVM_END
3164 
3165 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3166   // We don't use a ThreadsListHandle here because the current thread
3167   // must be alive.
3168   oop java_thread = JNIHandles::resolve_non_null(jthread);
3169   JavaThread* thr = java_lang_Thread::thread(java_thread);
3170   if (thread == thr && !thr->has_attached_via_jni()) {
3171     // Thread naming is only supported for the current thread and
3172     // we don't set the name of an attached thread to avoid stepping
3173     // on other programs.
3174     ResourceMark rm(thread);
3175     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));

3888   InstanceKlass* ik = vmClasses::String_klass();
3889   objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
3890   objArrayHandle result_h(THREAD, r);
3891 
3892   int index = 0;
3893   for (int j = 0; j < num_flags; j++, index++) {
3894     Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
3895     result_h->obj_at_put(index, h());
3896   }
3897   for (int i = 0; i < num_args; i++, index++) {
3898     Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
3899     result_h->obj_at_put(index, h());
3900   }
3901   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
3902 JVM_END
3903 
3904 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
3905   return os::get_signal_number(name);
3906 JVM_END
3907 
3908 JVM_ENTRY(void, JVM_VirtualThreadMountBegin(JNIEnv* env, jobject vthread, jboolean first_mount))
3909 #if INCLUDE_JVMTI
3910   JvmtiVTMTDisabler::start_VTMT(vthread, 0);
3911 #else
3912   fatal("Should only be called with JVMTI enabled");
3913 #endif
3914 JVM_END
3915 
3916 JVM_ENTRY(void, JVM_VirtualThreadMountEnd(JNIEnv* env, jobject vthread, jboolean first_mount))
3917 #if INCLUDE_JVMTI
3918   oop vt = JNIHandles::resolve(vthread);
3919 
3920   thread->rebind_to_jvmti_thread_state_of(vt);
3921 
3922   assert(thread->is_in_VTMT(), "VTMT sanity check");
3923   JvmtiVTMTDisabler::finish_VTMT(vthread, 0);
3924 
3925   if (first_mount) {
3926     // thread start
3927     if (JvmtiExport::can_support_virtual_threads()) {
3928       JvmtiEventController::thread_started(thread);
3929       if (JvmtiExport::should_post_vthread_start()) {
3930         JvmtiExport::post_vthread_start(vthread);
3931       }
3932     } else { // compatibility for vthread unaware agents: legacy thread_start
3933       if (JvmtiExport::should_post_thread_life()) {
3934         // JvmtiEventController::thread_started is called here
3935         JvmtiExport::post_thread_start(thread);
3936       } else {
3937         JvmtiEventController::thread_started(thread);
3938       }
3939     }
3940   }
3941   if (JvmtiExport::should_post_vthread_mount()) {
3942     JvmtiExport::post_vthread_mount(vthread);
3943   }
3944 #else
3945   fatal("Should only be called with JVMTI enabled");
3946 #endif
3947 JVM_END
3948 
3949 JVM_ENTRY(void, JVM_VirtualThreadUnmountBegin(JNIEnv* env, jobject vthread, jboolean last_unmount))
3950 #if INCLUDE_JVMTI
3951   HandleMark hm(thread);
3952   Handle ct(thread, thread->threadObj());
3953 
3954   if (JvmtiExport::should_post_vthread_unmount()) {
3955     JvmtiExport::post_vthread_unmount(vthread);
3956   }
3957   if (last_unmount) {
3958     if (JvmtiExport::can_support_virtual_threads()) {
3959       if (JvmtiExport::should_post_vthread_end()) {
3960         JvmtiExport::post_vthread_end(vthread);
3961       }
3962     } else { // compatibility for vthread unaware agents: legacy thread_end
3963       if (JvmtiExport::should_post_thread_life()) {
3964         JvmtiExport::post_thread_end(thread);
3965       }
3966     }
3967     if (thread->jvmti_thread_state() != NULL) {
3968       JvmtiExport::cleanup_thread(thread);
3969     }
3970   }
3971 
3972   assert(!thread->is_in_VTMT(), "VTMT sanity check");
3973   JvmtiVTMTDisabler::start_VTMT(vthread, 1);
3974   thread->rebind_to_jvmti_thread_state_of(ct());
3975 #else
3976   fatal("Should only be called with JVMTI enabled");
3977 #endif
3978 JVM_END
3979 
3980 JVM_ENTRY(void, JVM_VirtualThreadUnmountEnd(JNIEnv* env, jobject vthread, jboolean last_unmount))
3981 #if INCLUDE_JVMTI
3982   assert(thread->is_in_VTMT(), "VTMT sanity check");
3983   JvmtiVTMTDisabler::finish_VTMT(vthread, 1);
3984 #else
3985   fatal("Should only be called with JVMTI enabled");
3986 #endif
3987 JVM_END
< prev index next >