Skip to content

Commit cf021b8

Browse files
committed
Fix field store ordering to match JCL getter
Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
1 parent 841464e commit cf021b8

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

runtime/vm/callin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ initializeAttachedThreadImpl(J9VMThread *currentThread, const char *name, j9obje
589589
currentThread->returnValue = J9_BCLOOP_RUN_METHOD;
590590
currentThread->returnValue2 = (UDATA)J9VMJAVALANGTHREAD_INIT_METHOD(vm);
591591
c_cInterpreter(currentThread);
592-
J9VMJAVALANGTHREAD_SET_STARTED(currentThread, initializee->threadObject, JNI_TRUE);
593592
#if JAVA_SPEC_VERSION >= 19
594593
j9object_t threadHolder = J9VMJAVALANGTHREAD_HOLDER(currentThread, initializee->threadObject);
595594
if (NULL != threadHolder) {
@@ -598,6 +597,8 @@ initializeAttachedThreadImpl(J9VMThread *currentThread, const char *name, j9obje
598597
#else /* JAVA_SPEC_VERSION >= 19 */
599598
J9VMJAVALANGTHREAD_SET_THREADSTATUS(currentThread, initializee->threadObject, J9VMTHREAD_STATE_RUNNING);
600599
#endif /* JAVA_SPEC_VERSION >= 19 */
600+
/* Thread.started must be set after Thread.threadStatus to avoid timing issue in Thread.getState(). */
601+
J9VMJAVALANGTHREAD_SET_STARTED(currentThread, initializee->threadObject, JNI_TRUE);
601602
}
602603
}
603604
done:

runtime/vm/threadhelp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ monitorWaitImpl(J9VMThread *vmThread, j9object_t object, I_64 millis, I_32 nanos
118118
#endif
119119
J9VMTHREAD_SET_BLOCKINGENTEROBJECT(vmThread, vmThread, object);
120120
object = NULL;
121+
#if JAVA_SPEC_VERSION >= 24
122+
J9VM_SEND_VIRTUAL_UNBLOCKER_THREAD_SIGNAL(javaVM);
123+
#endif /* JAVA_SPEC_VERSION >= 24 */
121124
/* Set j.l.Thread status to WAITING. */
122125
U_32 oldState = J9_ARE_ANY_BITS_SET(thrstate, J9_PUBLIC_FLAGS_THREAD_TIMED)
123126
? VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING_TIMED)
124127
: VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING);
125-
#if JAVA_SPEC_VERSION >= 24
126-
J9VM_SEND_VIRTUAL_UNBLOCKER_THREAD_SIGNAL(javaVM);
127-
#endif /* JAVA_SPEC_VERSION >= 24 */
128128
internalReleaseVMAccessSetStatus(vmThread, thrstate);
129129
rc = timeCompensationHelper(vmThread,
130130
interruptable ? HELPER_TYPE_MONITOR_WAIT_INTERRUPTABLE : HELPER_TYPE_MONITOR_WAIT_TIMED, monitor, millis, nanos);

runtime/vm/vmthread.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,19 @@ startJavaThread(J9VMThread * currentThread, j9object_t threadObject, UDATA priva
18681868
privateFlags &= ~J9_PRIVATE_FLAGS_NO_EXCEPTION_IN_START_JAVA_THREAD;
18691869

18701870
#ifndef J9VM_IVE_RAW_BUILD /* J9VM_IVE_RAW_BUILD is not enabled by default */
1871+
#if JAVA_SPEC_VERSION >= 19
1872+
j9object_t threadHolder = J9VMJAVALANGTHREAD_HOLDER(currentThread, threadObject);
1873+
if (NULL != threadHolder) {
1874+
J9VMJAVALANGTHREADFIELDHOLDER_SET_THREADSTATUS(currentThread, threadHolder, J9VMTHREAD_STATE_RUNNING);
1875+
}
1876+
#else /* JAVA_SPEC_VERSION >= 19 */
1877+
J9VMJAVALANGTHREAD_SET_THREADSTATUS(currentThread, threadObject, J9VMTHREAD_STATE_RUNNING);
1878+
#endif /* JAVA_SPEC_VERSION >= 19 */
18711879
/* Any attempt to start a Thread makes it illegal to attempt to start it again.
1872-
* Oracle class libraries don't have the 'started' field */
1880+
* Oracle class libraries don't have the 'started' field.
1881+
*
1882+
* Thread.started must be set after Thread.threadStatus to avoid timing issue in Thread.getState().
1883+
*/
18731884
J9VMJAVALANGTHREAD_SET_STARTED(currentThread, threadObject, TRUE);
18741885
#endif /* !J9VM_IVE_RAW_BUILD */
18751886

@@ -2033,9 +2044,6 @@ startJavaThreadInternal(J9VMThread * currentThread, UDATA privateFlags, UDATA os
20332044
}
20342045
J9VMJAVALANGTHREAD_SET_THREADREF(currentThread, threadObject, newThread);
20352046

2036-
/* Set j.l.Thread status to RUNNABLE. */
2037-
VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_RUNNING);
2038-
20392047
#if (JAVA_SPEC_VERSION >= 14)
20402048
/* If thread was interrupted before start, make sure interrupt flag is set for running thread. */
20412049
if (J9VMJAVALANGTHREAD_DEADINTERRUPT(currentThread, threadObject)) {

0 commit comments

Comments
 (0)