From 55cb62f10f3b46abd0ea1263d4e38a3c30118931 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Fri, 4 Oct 2024 19:06:19 -0400 Subject: [PATCH] Return NULL from getStackTraceForThread for unsteady virtual threads If inspectorCount is -1, then the virtual thread is in an unsteady state (mounting or unmounting). In such cases, NULL should be returned and the JCL code should retry in order to avoid unexpected behavior. Related: #18910 Signed-off-by: Babneet Singh --- runtime/jcl/common/getstacktrace.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/jcl/common/getstacktrace.c b/runtime/jcl/common/getstacktrace.c index 19b098fb3e1..27ffbb0976b 100644 --- a/runtime/jcl/common/getstacktrace.c +++ b/runtime/jcl/common/getstacktrace.c @@ -80,9 +80,16 @@ getStackTraceForThread(J9VMThread *currentThread, J9VMThread *targetThread, UDAT */ walkState.skipCount = 0; rc = vmfns->walkContinuationStackFrames(currentThread, targetThread->currentContinuation, threadObject, &walkState); - } else if (isVirtual && (threadObject != targetThread->threadObject)) { + } else if (isVirtual + && ((threadObject != targetThread->threadObject) + || (-1 == J9OBJECT_I64_LOAD(currentThread, threadObject, vm->virtualThreadInspectorCountOffset))) + ) { /* If the virtual thread object doesn't match the current thread object, it must have unmounted * from this carrier thread, return NULL and the JCL code will handle the retry. + * + * If inspectorCount is -1, then the virtual thread is in an unsteady state (mounting or unmounting). + * In such cases, NULL should be returned and the JCL code should retry in order to avoid unexpected + * behavior. */ vmfns->resumeThreadForInspection(currentThread, targetThread); goto done;