From ed6fe39ef19b5814444a4be2f8aff987aa8b8856 Mon Sep 17 00:00:00 2001 From: Tobi Ajila Date: Thu, 19 Oct 2023 13:08:34 -0400 Subject: [PATCH] Set thread.started after running Current we set `thread.started = true` for system threads before running the constructor. This causes a race condition where the thread object may be made visible while it is being constructed potentially causing NPEs. Signed-off-by: Tobi Ajila --- runtime/vm/callin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/vm/callin.cpp b/runtime/vm/callin.cpp index ce6f460c7f9..46abc36d19b 100644 --- a/runtime/vm/callin.cpp +++ b/runtime/vm/callin.cpp @@ -581,7 +581,6 @@ initializeAttachedThreadImpl(J9VMThread *currentThread, const char *name, j9obje *--currentThread->sp = (UDATA)threadName; #else /* J9VM_IVE_RAW_BUILD */ /* J9 constructor takes thread name, thread group, priority and isDaemon */ - J9VMJAVALANGTHREAD_SET_STARTED(currentThread, threadObject, JNI_TRUE); *--currentThread->sp = (UDATA)threadName; *--currentThread->sp = (UDATA)threadGroup; *(I_32*)--currentThread->sp = priority; @@ -590,6 +589,7 @@ initializeAttachedThreadImpl(J9VMThread *currentThread, const char *name, j9obje currentThread->returnValue = J9_BCLOOP_RUN_METHOD; currentThread->returnValue2 = (UDATA)J9VMJAVALANGTHREAD_INIT_METHOD(vm); c_cInterpreter(currentThread); + J9VMJAVALANGTHREAD_SET_STARTED(currentThread, initializee->threadObject, JNI_TRUE); } } done: