Skip to content

Commit 01fc333

Browse files
committed
Add support for JEP491 on JDK24+
- Add missing setThreadState - Fix thread state on notified blocked threads Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
1 parent 15e11f3 commit 01fc333

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

runtime/oti/VMHelpers.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,6 @@ class VM_VMHelpers
22782278
indicateAsyncMessagePending(targetThread);
22792279
}
22802280

2281-
22822281
static U_32
22832282
setThreadState(J9VMThread *currentThread, U_32 state)
22842283
{
@@ -2289,14 +2288,14 @@ class VM_VMHelpers
22892288
/* Platform threads must have a non-null FieldHolder object. */
22902289
j9object_t threadHolder = J9VMJAVALANGTHREAD_HOLDER(currentThread, receiverObject);
22912290
if (NULL != threadHolder) {
2292-
oldState = (U_32)J9VMJAVALANGTHREADFIELDHOLDER_THREADSTATUS(currentThread, threadHolder);
2291+
oldState = J9VMJAVALANGTHREADFIELDHOLDER_THREADSTATUS(currentThread, threadHolder);
22932292
J9VMJAVALANGTHREADFIELDHOLDER_SET_THREADSTATUS(currentThread, threadHolder, state);
22942293
}
22952294
}
22962295
#else /* JAVA_SPEC_VERSION >= 19 */
22972296
j9object_t receiverObject = currentThread->threadObject;
22982297
if (NULL != receiverObject) {
2299-
oldState = (U_32)J9VMJAVALANGTHREAD_THREADSTATUS(currentThread, receiverObject);
2298+
oldState = J9VMJAVALANGTHREAD_THREADSTATUS(currentThread, receiverObject);
23002299
J9VMJAVALANGTHREAD_SET_THREADSTATUS(currentThread, receiverObject, state);
23012300
}
23022301
#endif /* JAVA_SPEC_VERSION >= 19 */

runtime/vm/ObjectMonitor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ objectMonitorEnterBlocking(J9VMThread *currentThread)
290290
J9_STORE_LOCKWORD(currentThread, lwEA, lock);
291291
goto done;
292292
}
293+
/* Set j.l.Thread status to BLOCKED. */
294+
VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_BLOCKED);
293295
internalReleaseVMAccessSetStatus(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED);
294296
SET_IGNORE_ENTER(monitor);
295297
omrthread_monitor_wait_timed(monitor, (I_64)waitTime, 0);

runtime/vm/threadhelp.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ monitorWaitImpl(J9VMThread *vmThread, j9object_t object, I_64 millis, I_32 nanos
121121
#if JAVA_SPEC_VERSION >= 24
122122
J9VM_SEND_VIRTUAL_UNBLOCKER_THREAD_SIGNAL(javaVM);
123123
#endif /* JAVA_SPEC_VERSION >= 24 */
124-
/* Set j.l.Thread status to WAITING. */
125-
U_32 oldState = J9_ARE_ANY_BITS_SET(thrstate, J9_PUBLIC_FLAGS_THREAD_TIMED)
126-
? VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING_TIMED)
127-
: VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING);
124+
/* Set j.l.Thread status to UNKNOWN since the wait can be notified/interrupted
125+
* but blocked on re-acquiring the monitor.
126+
* In this case, the thread state will have to be determined by looking at
127+
* the vmThread->publicFlags field.
128+
*/
129+
U_32 oldState = VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_UNKNOWN);
128130
internalReleaseVMAccessSetStatus(vmThread, thrstate);
129131
rc = timeCompensationHelper(vmThread,
130132
interruptable ? HELPER_TYPE_MONITOR_WAIT_INTERRUPTABLE : HELPER_TYPE_MONITOR_WAIT_TIMED, monitor, millis, nanos);

runtime/vm/threadpark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ threadParkImpl(J9VMThread *vmThread, BOOLEAN timeoutIsEpochRelative, I_64 timeou
100100
TRIGGER_J9HOOK_VM_PARK(vm->hookInterface, vmThread, millis, nanos);
101101
/* Set j.l.Thread status to WAITING. */
102102
U_32 oldState = J9_ARE_ANY_BITS_SET(thrstate, J9_PUBLIC_FLAGS_THREAD_TIMED)
103-
? VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING_TIMED)
104-
: VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_WAITING);
103+
? VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_PARKED_TIMED)
104+
: VM_VMHelpers::setThreadState(vmThread, J9VMTHREAD_STATE_PARKED);
105105
internalReleaseVMAccessSetStatus(vmThread, thrstate);
106106

107107
while (1) {

0 commit comments

Comments
 (0)