From cf7e46fdfa943d7a13531384479b1993bb8069c8 Mon Sep 17 00:00:00 2001 From: Jack Lu Date: Thu, 16 Mar 2023 17:16:27 -0400 Subject: [PATCH] Fix vthread suspend order to avoid dispatching mount hook for suspended thread Signed-off-by: Jack Lu --- runtime/j9vm/javanextvmi.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime/j9vm/javanextvmi.cpp b/runtime/j9vm/javanextvmi.cpp index 229e6279e48..9ca94ae54c3 100644 --- a/runtime/j9vm/javanextvmi.cpp +++ b/runtime/j9vm/javanextvmi.cpp @@ -334,23 +334,23 @@ JVM_VirtualThreadMountEnd(JNIEnv *env, jobject thread, jboolean firstMount) J9VMJDKINTERNALVMCONTINUATION_VMREF(currentThread, continuationObj)); } - /* Allow thread to be inspected again. */ - exitVThreadTransitionCritical(currentThread, threadObj); - - if (firstMount) { - TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_STARTED(vm->hookInterface, currentThread); - } - TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_MOUNT(vm->hookInterface, currentThread); - /* If isSuspendedByJVMTI is non-zero, J9_PUBLIC_FLAGS_HALT_THREAD_JAVA_SUSPEND is set * in currentThread->publicFlags while resetting isSuspendedByJVMTI to zero. During * mount, this suspends the thread if the thread was unmounted when JVMTI suspended it. */ if (0 != J9OBJECT_U32_LOAD(currentThread, threadObj, vm->isSuspendedByJVMTIOffset)) { - J9OBJECT_U32_STORE(currentThread, threadObj, vm->isSuspendedByJVMTIOffset, 0); vmFuncs->setHaltFlag(currentThread, J9_PUBLIC_FLAGS_HALT_THREAD_JAVA_SUSPEND); + J9OBJECT_U32_STORE(currentThread, threadObj, vm->isSuspendedByJVMTIOffset, 0); } + /* Allow thread to be inspected again. */ + exitVThreadTransitionCritical(currentThread, threadObj); + + if (firstMount) { + TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_STARTED(vm->hookInterface, currentThread); + } + TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_MOUNT(vm->hookInterface, currentThread); + vmFuncs->internalExitVMToJNI(currentThread); Trc_SC_VirtualThreadMountEnd_Exit(currentThread, thread, firstMount);