< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page
@@ -3112,10 +3112,14 @@
  
  JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
                                       jobject theThread))
    oop threadObj = JNIHandles::resolve(theThread);
    thread->set_vthread(threadObj);
+ 
+   // Set lock id of new current Thread
+   thread->set_lock_id(java_lang_Thread::thread_id(threadObj));
+ 
    JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
  JVM_END
  
  JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
    return ThreadIdentifier::unsafe_offset();

@@ -3998,10 +4002,40 @@
           "nested or unbalanced monitor enter/exit is not allowed");
    thread->toggle_is_disable_suspend();
  #endif
  JVM_END
  
+ JVM_ENTRY_NO_ENV(void, JVM_VirtualThreadPinnedEvent(jint reason))
+   EventVirtualThreadPinned event;
+   if (event.should_commit()) {
+     event.commit();
+   }
+ JVM_END
+ 
+ JVM_ENTRY_NO_ENV(void, JVM_SetLockId(JNIEnv* env, jclass clazz, jlong tid))
+   thread->set_lock_id(tid);
+ JVM_END
+ 
+ JVM_ENTRY(jobject, JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored))
+   ParkEvent* parkEvent = ObjectMonitor::vthread_unparker_ParkEvent();
+   assert(parkEvent != nullptr, "not initialized");
+ 
+   OopHandle& list_head = ObjectMonitor::vthread_cxq_head();
+   oop vthread_head = nullptr;
+   while (true) {
+     if (list_head.peek() != nullptr) {
+       for (;;) {
+         oop head = list_head.resolve();
+         if (list_head.cmpxchg(head, nullptr) == head) {
+           return JNIHandles::make_local(THREAD, head);
+         }
+       }
+     }
+     ThreadBlockInVM tbivm(THREAD);
+     parkEvent->park();
+   }
+ JVM_END
  /*
   * Return the current class's class file version.  The low order 16 bits of the
   * returned jint contain the class's major version.  The high order 16 bits
   * contain the class's minor version.
   */
< prev index next >