Skip to content

Commit

Permalink
Set thread.started after running <init>
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tajila committed Oct 19, 2023
1 parent 7cf716a commit ed6fe39
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/vm/callin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit ed6fe39

Please sign in to comment.