< 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))

3983   assert(!thread->is_in_VTMS_transition(), "sanity check");
3984   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
3985   thread->toggle_is_in_tmp_VTMS_transition();
3986 #endif
3987 JVM_END
3988 
3989 // Notification from VirtualThread about disabling JVMTI Suspend in a sync critical section.
3990 // Needed to avoid deadlocks with JVMTI suspend mechanism.
3991 JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter))
3992 #if INCLUDE_JVMTI
3993   if (!DoJVMTIVirtualThreadTransitions) {
3994     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3995     return;
3996   }
3997   assert(thread->is_disable_suspend() != (bool)enter,
3998          "nested or unbalanced monitor enter/exit is not allowed");
3999   thread->toggle_is_disable_suspend();
4000 #endif
4001 JVM_END
4002 






























4003 /*
4004  * Return the current class's class file version.  The low order 16 bits of the
4005  * returned jint contain the class's major version.  The high order 16 bits
4006  * contain the class's minor version.
4007  */
4008 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4009   oop mirror = JNIHandles::resolve_non_null(current);
4010   if (java_lang_Class::is_primitive(mirror)) {
4011     // return latest major version and minor version of 0.
4012     return JVM_CLASSFILE_MAJOR_VERSION;
4013   }
4014   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4015 
4016   Klass* c = java_lang_Class::as_Klass(mirror);
4017   assert(c->is_instance_klass(), "must be");
4018   InstanceKlass* ik = InstanceKlass::cast(c);
4019   return (ik->minor_version() << 16) | ik->major_version();
4020 JVM_END
4021 
4022 /*

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))

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