< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page
@@ -1676,12 +1676,13 @@
    }
    JavaThread *thread = JavaThread::current();
    HandleMark hm(thread);
    EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Trg Virtual Thread Unmount event triggered", vthread));
  
-   JvmtiThreadState *state = get_jvmti_thread_state(thread);
-   if (state == nullptr) {
+   // On preemption JVMTI state rebinding has already happened so get it always directly from the oop.
+   JvmtiThreadState *state = java_lang_Thread::jvmti_thread_state(JNIHandles::resolve(vthread));
+   if (state == NULL) {
      return;
    }
  
    if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
      JvmtiEnvThreadStateIterator it(state);

@@ -1696,11 +1697,11 @@
  
          JvmtiVirtualThreadEventMark jem(thread);
          JvmtiJavaThreadEventTransition jet(thread);
          jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadUnmount;
          if (callback != nullptr) {
-           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
+           (*callback)(env->jvmti_external(), jem.jni_env(), vthread);
          }
        }
      }
    }
  }

@@ -2860,10 +2861,25 @@
        }
      }
    }
  }
  
+ void JvmtiExport::vthread_post_monitor_waited(JavaThread *current, ObjectMonitor *obj_mntr, jboolean timed_out) {
+   Handle vthread(current, current->vthread());
+ 
+   // Finish the VTMS transition temporarily to post the event.
+   current->rebind_to_jvmti_thread_state_of(vthread());
+   JvmtiVTMSTransitionDisabler::finish_VTMS_transition((jthread)vthread.raw_value(), /* is_mount */ true);
+ 
+   // Post event.
+   JvmtiExport::post_monitor_waited(current, obj_mntr, timed_out);
+ 
+   // Go back to VTMS transition state.
+   JvmtiVTMSTransitionDisabler::start_VTMS_transition((jthread)vthread.raw_value(), /* is_mount */ true);
+   current->rebind_to_jvmti_thread_state_of(current->threadObj());
+ }
+ 
  void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
    if (object == nullptr) {
      return;
    }
    if (thread->is_in_any_VTMS_transition()) {
< prev index next >