< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

3071   }
3072   HOTSPOT_THREAD_SLEEP_END(0);
3073 JVM_END
3074 
3075 JVM_ENTRY(jobject, JVM_CurrentCarrierThread(JNIEnv* env, jclass threadClass))
3076   oop jthread = thread->threadObj();
3077   assert(jthread != nullptr, "no current carrier thread!");
3078   return JNIHandles::make_local(THREAD, jthread);
3079 JVM_END
3080 
3081 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3082   oop theThread = thread->vthread();
3083   assert(theThread != (oop)nullptr, "no current thread!");
3084   return JNIHandles::make_local(THREAD, theThread);
3085 JVM_END
3086 
3087 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
3088                                      jobject theThread))
3089   oop threadObj = JNIHandles::resolve(theThread);
3090   thread->set_vthread(threadObj);




3091   JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
3092 JVM_END
3093 




3094 JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
3095   return ThreadIdentifier::unsafe_offset();
3096 JVM_END
3097 
3098 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3099   ThreadsListHandle tlh(thread);
3100   JavaThread* receiver = nullptr;
3101   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, nullptr);
3102   if (is_alive) {
3103     // jthread refers to a live JavaThread.
3104     receiver->interrupt();
3105   }
3106 JVM_END
3107 
3108 // Return true iff the current thread has locked the object passed in
3109 
3110 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3111   if (obj == nullptr) {
3112     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3113   }

3953   assert(!thread->is_in_VTMS_transition(), "sanity check");
3954   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
3955   thread->toggle_is_in_tmp_VTMS_transition();
3956 #endif
3957 JVM_END
3958 
3959 // Notification from VirtualThread about disabling JVMTI Suspend in a sync critical section.
3960 // Needed to avoid deadlocks with JVMTI suspend mechanism.
3961 JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter))
3962 #if INCLUDE_JVMTI
3963   if (!DoJVMTIVirtualThreadTransitions) {
3964     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3965     return;
3966   }
3967   assert(thread->is_disable_suspend() != (bool)enter,
3968          "nested or unbalanced monitor enter/exit is not allowed");
3969   thread->toggle_is_disable_suspend();
3970 #endif
3971 JVM_END
3972 

































3973 /*
3974  * Return the current class's class file version.  The low order 16 bits of the
3975  * returned jint contain the class's major version.  The high order 16 bits
3976  * contain the class's minor version.
3977  */
3978 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
3979   oop mirror = JNIHandles::resolve_non_null(current);
3980   if (java_lang_Class::is_primitive(mirror)) {
3981     // return latest major version and minor version of 0.
3982     return JVM_CLASSFILE_MAJOR_VERSION;
3983   }
3984   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
3985 
3986   Klass* c = java_lang_Class::as_Klass(mirror);
3987   assert(c->is_instance_klass(), "must be");
3988   InstanceKlass* ik = InstanceKlass::cast(c);
3989   return (ik->minor_version() << 16) | ik->major_version();
3990 JVM_END
3991 
3992 /*

3071   }
3072   HOTSPOT_THREAD_SLEEP_END(0);
3073 JVM_END
3074 
3075 JVM_ENTRY(jobject, JVM_CurrentCarrierThread(JNIEnv* env, jclass threadClass))
3076   oop jthread = thread->threadObj();
3077   assert(jthread != nullptr, "no current carrier thread!");
3078   return JNIHandles::make_local(THREAD, jthread);
3079 JVM_END
3080 
3081 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3082   oop theThread = thread->vthread();
3083   assert(theThread != (oop)nullptr, "no current thread!");
3084   return JNIHandles::make_local(THREAD, theThread);
3085 JVM_END
3086 
3087 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
3088                                      jobject theThread))
3089   oop threadObj = JNIHandles::resolve(theThread);
3090   thread->set_vthread(threadObj);
3091 
3092   // Set lock id of new current Thread
3093   thread->set_lock_id(java_lang_Thread::thread_id(threadObj));
3094 
3095   JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
3096 JVM_END
3097 
3098 JVM_ENTRY_NO_ENV(void, JVM_SetCurrentLockId(JNIEnv* env, jclass threadClass, jlong tid))
3099   thread->set_lock_id(tid);
3100 JVM_END
3101 
3102 JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
3103   return ThreadIdentifier::unsafe_offset();
3104 JVM_END
3105 
3106 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3107   ThreadsListHandle tlh(thread);
3108   JavaThread* receiver = nullptr;
3109   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, nullptr);
3110   if (is_alive) {
3111     // jthread refers to a live JavaThread.
3112     receiver->interrupt();
3113   }
3114 JVM_END
3115 
3116 // Return true iff the current thread has locked the object passed in
3117 
3118 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3119   if (obj == nullptr) {
3120     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3121   }

3961   assert(!thread->is_in_VTMS_transition(), "sanity check");
3962   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
3963   thread->toggle_is_in_tmp_VTMS_transition();
3964 #endif
3965 JVM_END
3966 
3967 // Notification from VirtualThread about disabling JVMTI Suspend in a sync critical section.
3968 // Needed to avoid deadlocks with JVMTI suspend mechanism.
3969 JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter))
3970 #if INCLUDE_JVMTI
3971   if (!DoJVMTIVirtualThreadTransitions) {
3972     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3973     return;
3974   }
3975   assert(thread->is_disable_suspend() != (bool)enter,
3976          "nested or unbalanced monitor enter/exit is not allowed");
3977   thread->toggle_is_disable_suspend();
3978 #endif
3979 JVM_END
3980 
3981 JVM_ENTRY_NO_ENV(void, JVM_VirtualThreadPinnedEvent(jint reasonCode, jstring reasonString))
3982 #if INCLUDE_JFR
3983   EventVirtualThreadPinned e;
3984   if (e.should_commit()) {
3985     ResourceMark rm(THREAD);
3986     // ignore reason code for now
3987     const char *reason = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(reasonString));
3988     e.set_pinnedReason(reason);
3989     e.set_carrierThread(JFR_JVM_THREAD_ID(THREAD));
3990     e.commit();
3991   }
3992 #endif
3993 JVM_END
3994 
3995 JVM_ENTRY(jobject, JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored))
3996   ParkEvent* parkEvent = ObjectMonitor::vthread_unparker_ParkEvent();
3997   assert(parkEvent != nullptr, "not initialized");
3998 
3999   OopHandle& list_head = ObjectMonitor::vthread_cxq_head();
4000   oop vthread_head = nullptr;
4001   while (true) {
4002     if (list_head.peek() != nullptr) {
4003       for (;;) {
4004         oop head = list_head.resolve();
4005         if (list_head.cmpxchg(head, nullptr) == head) {
4006           return JNIHandles::make_local(THREAD, head);
4007         }
4008       }
4009     }
4010     ThreadBlockInVM tbivm(THREAD);
4011     parkEvent->park();
4012   }
4013 JVM_END
4014 /*
4015  * Return the current class's class file version.  The low order 16 bits of the
4016  * returned jint contain the class's major version.  The high order 16 bits
4017  * contain the class's minor version.
4018  */
4019 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4020   oop mirror = JNIHandles::resolve_non_null(current);
4021   if (java_lang_Class::is_primitive(mirror)) {
4022     // return latest major version and minor version of 0.
4023     return JVM_CLASSFILE_MAJOR_VERSION;
4024   }
4025   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4026 
4027   Klass* c = java_lang_Class::as_Klass(mirror);
4028   assert(c->is_instance_klass(), "must be");
4029   InstanceKlass* ik = InstanceKlass::cast(c);
4030   return (ik->minor_version() << 16) | ik->major_version();
4031 JVM_END
4032 
4033 /*
< prev index next >