@@ -118,13 +118,19 @@ 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+ /* Set j.l.Thread status to WAITING. */
122+ U_32 oldState = J9_ARE_ANY_BITS_SET (thrstate, J9_PUBLIC_FLAGS_THREAD_TIMED)
123+ ? VM_VMHelpers::setThreadState (vmThread, J9VMTHREAD_STATE_WAITING_TIMED)
124+ : VM_VMHelpers::setThreadState (vmThread, J9VMTHREAD_STATE_WAITING);
121125#if JAVA_SPEC_VERSION >= 24
122126 J9VM_SEND_VIRTUAL_UNBLOCKER_THREAD_SIGNAL (javaVM);
123127#endif /* JAVA_SPEC_VERSION >= 24 */
124128 internalReleaseVMAccessSetStatus (vmThread, thrstate);
125129 rc = timeCompensationHelper (vmThread,
126130 interruptable ? HELPER_TYPE_MONITOR_WAIT_INTERRUPTABLE : HELPER_TYPE_MONITOR_WAIT_TIMED, monitor, millis, nanos);
127131 internalAcquireVMAccessClearStatus (vmThread, thrstate);
132+ /* Set j.l.Thread status to oldState. */
133+ VM_VMHelpers::setThreadState (vmThread, oldState);
128134 J9VMTHREAD_SET_BLOCKINGENTEROBJECT (vmThread, vmThread, NULL );
129135 omrthread_monitor_unpin (monitor, vmThread->osThread );
130136#if JAVA_SPEC_VERSION >= 24
@@ -197,9 +203,13 @@ threadSleepImpl(J9VMThread *vmThread, I_64 millis, I_32 nanos)
197203#endif
198204 if (0 == rc) {
199205 TRIGGER_J9HOOK_VM_SLEEP (javaVM->hookInterface , vmThread, millis, nanos);
206+ /* Set j.l.Thread status to SLEEPING. */
207+ U_32 oldState = VM_VMHelpers::setThreadState (vmThread, J9VMTHREAD_STATE_SLEEPING);
200208 internalReleaseVMAccessSetStatus (vmThread, J9_PUBLIC_FLAGS_THREAD_SLEEPING);
201209 rc = timeCompensationHelper (vmThread, HELPER_TYPE_THREAD_SLEEP, NULL , millis, nanos);
202210 internalAcquireVMAccessClearStatus (vmThread, J9_PUBLIC_FLAGS_THREAD_SLEEPING);
211+ /* Set j.l.Thread status to oldState. */
212+ VM_VMHelpers::setThreadState (vmThread, oldState);
203213 TRIGGER_J9HOOK_VM_SLEPT (javaVM->hookInterface , vmThread, millis, nanos, startTicks);
204214 }
205215
0 commit comments