Skip to content

Commit 0164375

Browse files
authored
Merge pull request #22355 from tajila/vt4
(0.54) Add notify to carrier thread wait path
2 parents 9c3589a + 63c1a37 commit 0164375

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

runtime/oti/monhelp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848

4949
#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) \
52+
(!J9_LOCK_IS_INFLATED(lockWord) \
53+
&& (NULL != J9_FLATLOCK_OWNER(lockWord)) \
54+
&& (J9_FLATLOCK_COUNT(lockWord) > 0))
5255

5356
#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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
944944
UDATA monitorCount = 0;
945945
J9JavaVM *vm = currentThread->javaVM;
946946
J9VMContinuation *continuation = currentThread->currentContinuation;
947+
IDATA monitorResult = 0;
947948

948949
if (NULL != syncObj) {
949950
j9objectmonitor_t volatile *lwEA = VM_ObjectMonitor::inlineGetLockAddress(currentThread, syncObj);
@@ -1009,7 +1010,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10091010
#if defined(J9VM_THR_LOCK_RESERVATION)
10101011
if (J9_ARE_ANY_BITS_SET(lock, OBJECT_HEADER_LOCK_RESERVED)) {
10111012
/* Lock is now reserved, exit the inflated monitor and restart to cancel lock reservation. */
1012-
omrthread_monitor_exit(monitor);
1013+
monitorResult = omrthread_monitor_exit(monitor);
1014+
Assert_VM_true(0 == monitorResult);
10131015
goto restart;
10141016
}
10151017
#endif /* J9VM_THR_LOCK_RESERVATION */
@@ -1020,6 +1022,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10201022
newLockword = (UDATA)J9_FLATLOCK_OWNER(lock)
10211023
| ((J9_FLATLOCK_COUNT(lock) - 1) << OBJECT_HEADER_LOCK_V2_RECURSION_OFFSET)
10221024
| OBJECT_HEADER_LOCK_FLC;
1025+
1026+
Assert_VM_true(J9_FLATLOCK_COUNT(lock) == J9_FLATLOCK_COUNT(newLockword));
10231027
} else {
10241028
/* Lock is unlocked, so try to directly acquire it as a flatlock. */
10251029
newLockword = (UDATA)currentThread;
@@ -1033,7 +1037,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10331037
/* CAS succeeded, we can proceed with using the inflated monitor. */
10341038
VM_ObjectMonitor::incrementCancelCounter(J9OBJECT_CLAZZ(currentThread, syncObj));
10351039
/* Either the lock is acquired or FLC bit set, safe to release the inflated monitor. */
1036-
omrthread_monitor_exit(monitor);
1040+
monitorResult = omrthread_monitor_exit(monitor);
1041+
Assert_VM_true(0 == monitorResult);
10371042

10381043
if (J9_FLATLOCK_OWNER(newLockword) == currentThread) {
10391044
/* Lock is acquired. */
@@ -1132,7 +1137,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
11321137
syncObjectMonitor->waitingContinuations = continuation;
11331138
omrthread_monitor_exit(vm->blockedVirtualThreadsMutex);
11341139

1135-
omrthread_monitor_exit(monitor);
1140+
monitorResult = omrthread_monitor_exit(monitor);
1141+
Assert_VM_true(0 == monitorResult);
11361142
} else {
11371143
if (NULL != monitor) {
11381144
/* 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)