< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

3097   }
3098   HOTSPOT_THREAD_SLEEP_END(0);
3099 JVM_END
3100 
3101 JVM_ENTRY(jobject, JVM_CurrentCarrierThread(JNIEnv* env, jclass threadClass))
3102   oop jthread = thread->threadObj();
3103   assert(jthread != nullptr, "no current carrier thread!");
3104   return JNIHandles::make_local(THREAD, jthread);
3105 JVM_END
3106 
3107 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3108   oop theThread = thread->vthread();
3109   assert(theThread != (oop)nullptr, "no current thread!");
3110   return JNIHandles::make_local(THREAD, theThread);
3111 JVM_END
3112 
3113 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
3114                                      jobject theThread))
3115   oop threadObj = JNIHandles::resolve(theThread);
3116   thread->set_vthread(threadObj);




3117   JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
3118 JVM_END
3119 
3120 JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
3121   return ThreadIdentifier::unsafe_offset();
3122 JVM_END
3123 
3124 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3125   ThreadsListHandle tlh(thread);
3126   JavaThread* receiver = nullptr;
3127   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, nullptr);
3128   if (is_alive) {
3129     // jthread refers to a live JavaThread.
3130     receiver->interrupt();
3131   }
3132 JVM_END
3133 
3134 // Return true iff the current thread has locked the object passed in
3135 
3136 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))

3995   assert(!thread->is_in_VTMS_transition(), "sanity check");
3996   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
3997   thread->toggle_is_in_tmp_VTMS_transition();
3998 #endif
3999 JVM_END
4000 
4001 // Notification from VirtualThread about disabling JVMTI Suspend in a sync critical section.
4002 // Needed to avoid deadlocks with JVMTI suspend mechanism.
4003 JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter))
4004 #if INCLUDE_JVMTI
4005   if (!DoJVMTIVirtualThreadTransitions) {
4006     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
4007     return;
4008   }
4009   assert(thread->is_disable_suspend() != (bool)enter,
4010          "nested or unbalanced monitor enter/exit is not allowed");
4011   thread->toggle_is_disable_suspend();
4012 #endif
4013 JVM_END
4014 






























4015 /*
4016  * Return the current class's class file version.  The low order 16 bits of the
4017  * returned jint contain the class's major version.  The high order 16 bits
4018  * contain the class's minor version.
4019  */
4020 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4021   oop mirror = JNIHandles::resolve_non_null(current);
4022   if (java_lang_Class::is_primitive(mirror)) {
4023     // return latest major version and minor version of 0.
4024     return JVM_CLASSFILE_MAJOR_VERSION;
4025   }
4026   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4027 
4028   Klass* c = java_lang_Class::as_Klass(mirror);
4029   assert(c->is_instance_klass(), "must be");
4030   InstanceKlass* ik = InstanceKlass::cast(c);
4031   return (ik->minor_version() << 16) | ik->major_version();
4032 JVM_END
4033 
4034 /*

3097   }
3098   HOTSPOT_THREAD_SLEEP_END(0);
3099 JVM_END
3100 
3101 JVM_ENTRY(jobject, JVM_CurrentCarrierThread(JNIEnv* env, jclass threadClass))
3102   oop jthread = thread->threadObj();
3103   assert(jthread != nullptr, "no current carrier thread!");
3104   return JNIHandles::make_local(THREAD, jthread);
3105 JVM_END
3106 
3107 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3108   oop theThread = thread->vthread();
3109   assert(theThread != (oop)nullptr, "no current thread!");
3110   return JNIHandles::make_local(THREAD, theThread);
3111 JVM_END
3112 
3113 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
3114                                      jobject theThread))
3115   oop threadObj = JNIHandles::resolve(theThread);
3116   thread->set_vthread(threadObj);
3117 
3118   // Set lock id of new current Thread
3119   thread->set_lock_id(java_lang_Thread::thread_id(threadObj));
3120 
3121   JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
3122 JVM_END
3123 
3124 JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
3125   return ThreadIdentifier::unsafe_offset();
3126 JVM_END
3127 
3128 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3129   ThreadsListHandle tlh(thread);
3130   JavaThread* receiver = nullptr;
3131   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, nullptr);
3132   if (is_alive) {
3133     // jthread refers to a live JavaThread.
3134     receiver->interrupt();
3135   }
3136 JVM_END
3137 
3138 // Return true iff the current thread has locked the object passed in
3139 
3140 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))

3999   assert(!thread->is_in_VTMS_transition(), "sanity check");
4000   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
4001   thread->toggle_is_in_tmp_VTMS_transition();
4002 #endif
4003 JVM_END
4004 
4005 // Notification from VirtualThread about disabling JVMTI Suspend in a sync critical section.
4006 // Needed to avoid deadlocks with JVMTI suspend mechanism.
4007 JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter))
4008 #if INCLUDE_JVMTI
4009   if (!DoJVMTIVirtualThreadTransitions) {
4010     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
4011     return;
4012   }
4013   assert(thread->is_disable_suspend() != (bool)enter,
4014          "nested or unbalanced monitor enter/exit is not allowed");
4015   thread->toggle_is_disable_suspend();
4016 #endif
4017 JVM_END
4018 
4019 JVM_ENTRY_NO_ENV(void, JVM_VirtualThreadPinnedEvent(jint reason))
4020   EventVirtualThreadPinned event;
4021   if (event.should_commit()) {
4022     event.commit();
4023   }
4024 JVM_END
4025 
4026 JVM_ENTRY_NO_ENV(void, JVM_SetLockId(JNIEnv* env, jclass clazz, jlong tid))
4027   thread->set_lock_id(tid);
4028 JVM_END
4029 
4030 JVM_ENTRY(jobject, JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored))
4031   ParkEvent* parkEvent = ObjectMonitor::vthread_unparker_ParkEvent();
4032   assert(parkEvent != nullptr, "not initialized");
4033 
4034   OopHandle& list_head = ObjectMonitor::vthread_cxq_head();
4035   oop vthread_head = nullptr;
4036   while (true) {
4037     if (list_head.peek() != nullptr) {
4038       for (;;) {
4039         oop head = list_head.resolve();
4040         if (list_head.cmpxchg(head, nullptr) == head) {
4041           return JNIHandles::make_local(THREAD, head);
4042         }
4043       }
4044     }
4045     ThreadBlockInVM tbivm(THREAD);
4046     parkEvent->park();
4047   }
4048 JVM_END
4049 /*
4050  * Return the current class's class file version.  The low order 16 bits of the
4051  * returned jint contain the class's major version.  The high order 16 bits
4052  * contain the class's minor version.
4053  */
4054 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4055   oop mirror = JNIHandles::resolve_non_null(current);
4056   if (java_lang_Class::is_primitive(mirror)) {
4057     // return latest major version and minor version of 0.
4058     return JVM_CLASSFILE_MAJOR_VERSION;
4059   }
4060   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4061 
4062   Klass* c = java_lang_Class::as_Klass(mirror);
4063   assert(c->is_instance_klass(), "must be");
4064   InstanceKlass* ik = InstanceKlass::cast(c);
4065   return (ik->minor_version() << 16) | ik->major_version();
4066 JVM_END
4067 
4068 /*
< prev index next >