Skip to content

Commit baf30d9

Browse files
committed
Fix for post_vthread_unmount
1 parent 63003d3 commit baf30d9

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/hotspot/share/prims/jvmtiExport.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,17 +1670,17 @@ void JvmtiExport::post_vthread_mount(jobject vthread) {
16701670
}
16711671
}
16721672

1673-
void JvmtiExport::post_vthread_unmount(jobject vthread) {
1673+
void JvmtiExport::post_vthread_unmount(jobject vthread, JvmtiThreadState* state_to_use) {
16741674
if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
16751675
return;
16761676
}
16771677
JavaThread *thread = JavaThread::current();
16781678
HandleMark hm(thread);
16791679
EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Trg Virtual Thread Unmount event triggered", vthread));
16801680

1681-
// On preemption JVMTI state rebinding has already happened so get it always directly from the oop.
1682-
JvmtiThreadState *state = java_lang_Thread::jvmti_thread_state(JNIHandles::resolve(vthread));
1683-
if (state == NULL) {
1681+
// On preemption, JVMTI state rebinding has already happened so we use the passed one.
1682+
JvmtiThreadState *state = state_to_use == nullptr ? get_jvmti_thread_state(thread) : state_to_use;
1683+
if (state == nullptr) {
16841684
return;
16851685
}
16861686

src/hotspot/share/prims/jvmtiExport.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class JvmtiExport : public AllStatic {
358358
static void post_vthread_start (jthread vthread) NOT_JVMTI_RETURN;
359359
static void post_vthread_end (jthread vthread) NOT_JVMTI_RETURN;
360360
static void post_vthread_mount (jthread vthread) NOT_JVMTI_RETURN;
361-
static void post_vthread_unmount (jthread vthread) NOT_JVMTI_RETURN;
361+
static void post_vthread_unmount (jthread vthread, JvmtiThreadState* state_to_use = nullptr) NOT_JVMTI_RETURN;
362362

363363
static void continuation_yield_cleanup (JavaThread* thread, jint continuation_frame_count) NOT_JVMTI_RETURN;
364364

src/hotspot/share/prims/jvmtiThreadState.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,10 @@ JvmtiVTMSTransitionDisabler::VTMS_unmount_end(jobject vthread) {
667667

668668
if (thread->pending_jvmti_unmount_event()) {
669669
assert(java_lang_VirtualThread::is_preempted(JNIHandles::resolve(vthread)), "should be marked preempted");
670-
JvmtiExport::post_vthread_unmount(vthread);
670+
// State rebinding has already happened so use the correct state when posting the event.
671+
Handle vth = Handle(thread, JNIHandles::resolve_external_guard(vthread));
672+
JvmtiThreadState* state = JvmtiThreadState::state_for(nullptr, vth);
673+
JvmtiExport::post_vthread_unmount(vthread, state);
671674
thread->set_pending_jvmti_unmount_event(false);
672675
}
673676
}

0 commit comments

Comments
 (0)