Skip to content

Commit 05f594f

Browse files
authored
Merge pull request #22308 from tajila/vt4
Add notify to carrier thread wait path
2 parents ee0e4a4 + a0fc8ca commit 05f594f

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

runtime/oti/monhelp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444

4545
#define J9_LOCK_IS_INFLATED(lockWord) ((lockWord) & OBJECT_HEADER_LOCK_INFLATED)
4646
#define J9_INFLLOCK_OBJECT_MONITOR(lockWord) ((J9ObjectMonitor *)((UDATA)(lockWord) & (~(UDATA)OBJECT_HEADER_LOCK_INFLATED)))
47-
#define J9_INFLLOCK_MONITOR(lockWord) (J9_INFLLOCK_OBJECT_MONITOR(lockWord)->monitor)
47+
#define J9_INFLLOCK_MONITOR(lockWord) (J9_INFLLOCK_OBJECT_MONITOR((lockWord))->monitor)
4848

49-
#define J9_INFLLOCK_ABSTRACT_MONITOR(lockWord) ((J9ThreadAbstractMonitor*)J9_INFLLOCK_MONITOR(lockWord))
49+
#define J9_INFLLOCK_ABSTRACT_MONITOR(lockWord) ((J9ThreadAbstractMonitor*)J9_INFLLOCK_MONITOR((lockWord)))
5050

51-
#define J9_LOCK_IS_FLATLOCKED(lockWord) (!J9_LOCK_IS_INFLATED(lockWord) && (J9_FLATLOCK_OWNER(lockWord) != NULL))
51+
#define J9_LOCK_IS_FLATLOCKED(lockWord) (!J9_LOCK_IS_INFLATED((lockWord)) && (J9_FLATLOCK_OWNER((lockWord)) != NULL && (J9_FLATLOCK_COUNT((lockWord)) > 0)))
5252

5353
#endif /*J9_MONHELP_H_*/

runtime/vm/BytecodeInterpreter.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,8 @@ class INTERPRETER_CLASS
15811581
VM_ContinuationHelpers::sendUnblockerThreadSignal(_vm);
15821582
}
15831583
omrthread_monitor_exit(_vm->blockedVirtualThreadsMutex);
1584+
} else if ((JAVA_LANG_VIRTUALTHREAD_WAITING == newThreadState) || (JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING == newThreadState)) {
1585+
VM_ContinuationHelpers::sendUnblockerThreadSignal(_vm);
15841586
}
15851587

15861588
/* Enter critical transition after the prepare stage is complete and hooks dispatched. */

runtime/vm/ContinuationHelpers.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10091009
#if defined(J9VM_THR_LOCK_RESERVATION)
10101010
if (J9_ARE_ANY_BITS_SET(lock, OBJECT_HEADER_LOCK_RESERVED)) {
10111011
/* Lock is now reserved, exit the inflated monitor and restart to cancel lock reservation. */
1012-
omrthread_monitor_exit(monitor);
1012+
Assert_VM_true(0 == omrthread_monitor_exit(monitor));
10131013
goto restart;
10141014
}
10151015
#endif /* J9VM_THR_LOCK_RESERVATION */
@@ -1020,6 +1020,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10201020
newLockword = (UDATA)J9_FLATLOCK_OWNER(lock)
10211021
| ((J9_FLATLOCK_COUNT(lock) - 1) << OBJECT_HEADER_LOCK_V2_RECURSION_OFFSET)
10221022
| OBJECT_HEADER_LOCK_FLC;
1023+
1024+
Assert_VM_true(J9_FLATLOCK_COUNT(lock) == J9_FLATLOCK_COUNT(newLockword));
10231025
} else {
10241026
/* Lock is unlocked, so try to directly acquire it as a flatlock. */
10251027
newLockword = (UDATA)currentThread;
@@ -1033,7 +1035,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10331035
/* CAS succeeded, we can proceed with using the inflated monitor. */
10341036
VM_ObjectMonitor::incrementCancelCounter(J9OBJECT_CLAZZ(currentThread, syncObj));
10351037
/* Either the lock is acquired or FLC bit set, safe to release the inflated monitor. */
1036-
omrthread_monitor_exit(monitor);
1038+
Assert_VM_true(0 == omrthread_monitor_exit(monitor));
10371039

10381040
if (J9_FLATLOCK_OWNER(newLockword) == currentThread) {
10391041
/* Lock is acquired. */
@@ -1132,7 +1134,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
11321134
syncObjectMonitor->waitingContinuations = continuation;
11331135
omrthread_monitor_exit(vm->blockedVirtualThreadsMutex);
11341136

1135-
omrthread_monitor_exit(monitor);
1137+
Assert_VM_true(0 == omrthread_monitor_exit(monitor));
11361138
} else {
11371139
if (NULL != monitor) {
11381140
/* If we are blocking to wait on a contended monitor then we can't be the owner. */

runtime/vm/montable.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ initializeMonitorTable(J9JavaVM* vm)
146146
return -1;
147147
}
148148
memset(vm->monitorTables, 0, sizeof(J9HashTable *) * tableCount);
149-
149+
150150
vm->monitorTableList = NULL;
151151

152152
for (tableIndex = 0; tableIndex < tableCount; tableIndex++) {
@@ -170,7 +170,7 @@ initializeMonitorTable(J9JavaVM* vm)
170170
}
171171

172172
vm->monitorTableCount = tableCount;
173-
173+
174174
return 0;
175175
}
176176

@@ -299,20 +299,20 @@ monitorTableAt(J9VMThread* vmStruct, j9object_t object)
299299
((J9ThreadAbstractMonitor *)monitor)->spinCount1 = j9threadOptions->customThreeTierSpinCount1;
300300
((J9ThreadAbstractMonitor *)monitor)->spinCount2 = j9threadOptions->customThreeTierSpinCount2;
301301
((J9ThreadAbstractMonitor *)monitor)->spinCount3 = j9threadOptions->customThreeTierSpinCount3;
302-
302+
303303
Trc_VM_MonitorTableAt_CustomSpinOption(option->className,
304304
object,
305305
((J9ThreadAbstractMonitor *)monitor)->spinCount1,
306306
((J9ThreadAbstractMonitor *)monitor)->spinCount2,
307307
((J9ThreadAbstractMonitor *)monitor)->spinCount3);
308308
#endif /* OMR_THR_THREE_TIER_LOCKING */
309-
#if defined(OMR_THR_ADAPTIVE_SPIN)
309+
#if defined(OMR_THR_ADAPTIVE_SPIN)
310310
Trc_VM_MonitorTableAt_CustomSpinOption2(option->className,
311-
object,
311+
object,
312312
j9threadOptions->customAdaptSpin);
313-
#endif /* OMR_THR_ADAPTIVE_SPIN */
313+
#endif /* OMR_THR_ADAPTIVE_SPIN */
314314
}
315-
#endif /* OMR_THR_CUSTOM_SPIN_OPTIONS */
315+
#endif /* OMR_THR_CUSTOM_SPIN_OPTIONS */
316316
#endif /* J9VM_INTERP_CUSTOM_SPIN_OPTIONS */
317317

318318
key_objectMonitor.monitor = monitor;
@@ -324,6 +324,7 @@ monitorTableAt(J9VMThread* vmStruct, j9object_t object)
324324

325325
#if JAVA_SPEC_VERSION >= 24
326326
key_objectMonitor.virtualThreadWaitCount = 0;
327+
key_objectMonitor.platformThreadWaitCount = 0;
327328
key_objectMonitor.ownerContinuation = NULL;
328329
key_objectMonitor.waitingContinuations = NULL;
329330
key_objectMonitor.next = NULL;

runtime/vm/threadhelp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ monitorWaitImpl(J9VMThread *vmThread, j9object_t object, I_64 millis, I_32 nanos
9696
#if JAVA_SPEC_VERSION >= 24
9797
j9objectmonitor_t volatile *lwEA = VM_ObjectMonitor::inlineGetLockAddress(vmThread, object);
9898
j9objectmonitor_t lock = J9_LOAD_LOCKWORD(vmThread, lwEA);
99+
Assert_VM_true(J9_LOCK_IS_INFLATED(lock));
99100
J9ObjectMonitor *objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
100101
VM_AtomicSupport::addU32(&objectMonitor->platformThreadWaitCount, 1);
101102
#endif /* JAVA_SPEC_VERSION >= 24 */
@@ -112,6 +113,9 @@ monitorWaitImpl(J9VMThread *vmThread, j9object_t object, I_64 millis, I_32 nanos
112113
#endif
113114
J9VMTHREAD_SET_BLOCKINGENTEROBJECT(vmThread, vmThread, object);
114115
object = NULL;
116+
#if JAVA_SPEC_VERSION >= 24
117+
J9VM_SEND_VIRTUAL_UNBLOCKER_THREAD_SIGNAL(javaVM);
118+
#endif /* JAVA_SPEC_VERSION >= 24 */
115119
internalReleaseVMAccessSetStatus(vmThread, thrstate);
116120
rc = timeCompensationHelper(vmThread,
117121
interruptable ? HELPER_TYPE_MONITOR_WAIT_INTERRUPTABLE : HELPER_TYPE_MONITOR_WAIT_TIMED, monitor, millis, nanos);

0 commit comments

Comments
 (0)