diff --git a/src/hotspot/share/prims/jvmtiExport.cpp b/src/hotspot/share/prims/jvmtiExport.cpp index a82ad2db6b69c..757d8f16eeb52 100644 --- a/src/hotspot/share/prims/jvmtiExport.cpp +++ b/src/hotspot/share/prims/jvmtiExport.cpp @@ -420,6 +420,7 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { JvmtiThreadState* JvmtiExport::get_jvmti_thread_state(JavaThread *thread, bool allow_suspend) { assert(thread == JavaThread::current(), "must be current thread"); + assert(thread->thread_state() == _thread_in_vm, "thread should be in vm"); if (thread->is_vthread_mounted() && thread->jvmti_thread_state() == nullptr) { JvmtiEventController::thread_started(thread); if (allow_suspend && thread->is_suspended()) { @@ -1831,8 +1832,11 @@ void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame cur HandleMark hm(thread); methodHandle mh(thread, method); - JvmtiThreadState *state = get_jvmti_thread_state(thread); - + JvmtiThreadState *state = nullptr; + { + ThreadInVMfromJava tiv(thread); + state = get_jvmti_thread_state(thread); + } if (state == nullptr || !state->is_interp_only_mode()) { // for any thread that actually wants method exit, interp_only_mode is set return;