Skip to content

Commit 9c02182

Browse files
committed
Add assertions for incompatible vthread states
Adding assertions to verify virtual thread behaviour is valid. The expectation is that instead of hangs we will see assertion failures which will aid in the investigation of issues. Signed-off-by: Tobi Ajila <[email protected]>
1 parent 65e169a commit 9c02182

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

runtime/vm/ContinuationHelpers.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ void
798798
updateMonitorInfo(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor)
799799
{
800800
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor *)objectMonitor->monitor;
801+
Assert_VM_true(1 == (UDATA)monitor->owner);
801802
monitor->owner = currentThread->osThread;
802803
objectMonitor->ownerContinuation = NULL;
803804
}
@@ -937,6 +938,8 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
937938
syncObjectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
938939
} else {
939940
if (isObjectWait) {
941+
/* Current thread must own at least one monitor if wait was called. */
942+
Assert_VM_true(currentThread->ownedMonitorCount > 0);
940943
syncObjectMonitor = objectMonitorInflate(currentThread, syncObj, lock);
941944
if (NULL == syncObjectMonitor) {
942945
result = J9_OBJECT_MONITOR_OOM;
@@ -1074,11 +1077,11 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
10741077

10751078
if (NULL != syncObj) {
10761079
j9object_t continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, currentThread->threadObject);
1080+
omrthread_monitor_t monitor = syncObjectMonitor->monitor;
10771081
J9VMJDKINTERNALVMCONTINUATION_SET_BLOCKER(currentThread, continuationObj, syncObj);
10781082

10791083
if (isObjectWait) {
10801084
J9VMContinuation *continuation = currentThread->currentContinuation;
1081-
omrthread_monitor_t monitor = syncObjectMonitor->monitor;
10821085

10831086
/* Record wait monitor state. */
10841087
continuation->waitingMonitorEnterCount = monitor->count;
@@ -1100,6 +1103,11 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
11001103
/* Increment the wait count on inflated monitor. */
11011104
VM_AtomicSupport::addU32(&syncObjectMonitor->virtualThreadWaitCount, 1);
11021105
currentThread->currentContinuation->objectWaitMonitor = syncObjectMonitor;
1106+
1107+
if (NULL != monitor) {
1108+
/* If we are blocking to wait on a contended monitor then we can't be the owner. */
1109+
//Assert_VM_false(monitor->owner == currentThread->osThread);
1110+
}
11031111
}
11041112
}
11051113

runtime/vm/ObjectMonitor.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ objectMonitorEnterNonBlocking(J9VMThread *currentThread, j9object_t object)
493493
} else {
494494
/* the monitor is already inflated */
495495
objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
496+
497+
/* Monitor must be owned by valid thread */
498+
Assert_VM_true(1 != objectMonitor->monitor->owner);
496499
}
497500
if (!spinOnTryEnter(currentThread, objectMonitor, lwEA, object)) {
498501
goto wouldBlock;

0 commit comments

Comments
 (0)