< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page
*** 1676,12 ***
    }
    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) {
      return;
    }
  
    if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
      JvmtiEnvThreadStateIterator it(state);
--- 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));
  
!   // On preemption JVMTI state rebinding has already happened so get it always direclty 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 ***
  
          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());
          }
        }
      }
    }
  }
--- 1697,11 ---
  
          JvmtiVirtualThreadEventMark jem(thread);
          JvmtiJavaThreadEventTransition jet(thread);
          jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadUnmount;
          if (callback != nullptr) {
!           (*callback)(env->jvmti_external(), jem.jni_env(), vthread);
          }
        }
      }
    }
  }

*** 2860,10 ***
--- 2861,34 ---
        }
      }
    }
  }
  
+ 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());
+   {
+     MutexLocker mu(JvmtiThreadState_lock);
+     JvmtiThreadState* state = current->jvmti_thread_state();
+     if (state != NULL && state->is_pending_interp_only_mode()) {
+       JvmtiEventController::enter_interp_only_mode(state);
+     }
+   }
+   assert(current->is_in_VTMS_transition(), "sanity check");
+   assert(!current->is_in_tmp_VTMS_transition(), "sanity check");
+   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 >