Skip to content

Commit

Permalink
Fix vthread suspend order to avoid dispatching mount hook for suspend…
Browse files Browse the repository at this point in the history
…ed thread

Signed-off-by: Jack Lu <[email protected]>
  • Loading branch information
fengxue-IS committed Mar 29, 2023
1 parent 8208c13 commit cf7e46f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cf7e46f

Please sign in to comment.