Skip to content

Commit

Permalink
Merge pull request #15487 from babsingh/loom_pin_support_v1
Browse files Browse the repository at this point in the history
Loom Pinning: Manage J9VMThread->ownedMonitorCount
  • Loading branch information
gacholio committed Jul 15, 2022
2 parents 8ead00a + 4f2e184 commit 96dca6c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
8 changes: 7 additions & 1 deletion runtime/oti/ObjectMonitor.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -262,6 +262,9 @@ class VM_ObjectMonitor
if (lock == compareAndSwapLockword(currentThread, lockEA, lock, mine, readBeforeCAS)) {
VM_AtomicSupport::readBarrier();
locked = true;
#if JAVA_SPEC_VERSION >= 19
currentThread->ownedMonitorCount += 1;
#endif /* JAVA_SPEC_VERSION >= 19 */
}
return locked;
}
Expand Down Expand Up @@ -307,6 +310,9 @@ class VM_ObjectMonitor
VM_AtomicSupport::writeBarrier();
J9_STORE_LOCKWORD(currentThread, lockEA, 0);
unlocked = true;
#if JAVA_SPEC_VERSION >= 19
currentThread->ownedMonitorCount -= 1;
#endif /* JAVA_SPEC_VERSION >= 19 */
}
}
return unlocked;
Expand Down
9 changes: 9 additions & 0 deletions runtime/vm/ObjectMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ objectMonitorEnterBlocking(J9VMThread *currentThread)
if (J9_ARE_ANY_BITS_SET(((J9ThreadMonitor*)monitor)->flags, J9THREAD_MONITOR_INFLATED)) {
Trc_VM_objectMonitorEnterBlocking_alreadyInflated(currentThread);
internalAcquireVMAccess(currentThread);
#if JAVA_SPEC_VERSION >= 19
currentThread->ownedMonitorCount += 1;
#endif /* JAVA_SPEC_VERSION >= 19 */
goto done;
}
if (0 != internalTryAcquireVMAccess(currentThread)) {
Expand Down Expand Up @@ -404,6 +407,9 @@ objectMonitorEnterNonBlocking(J9VMThread *currentThread, j9object_t object)
goto restart;
}
}
#if JAVA_SPEC_VERSION >= 19
currentThread->ownedMonitorCount += 1;
#endif /* JAVA_SPEC_VERSION >= 19 */
/* no barrier is required in the recursive case */
} else {
/* check to see if object is unlocked (JIT did not do initial inline sequence due to insufficient static type info) */
Expand Down Expand Up @@ -704,6 +710,9 @@ spinOnTryEnter(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor, j9obje
if (J9_LOCK_IS_INFLATED(J9_LOAD_LOCKWORD(currentThread, lwEA))) {
/* try_enter succeeded - monitor is inflated */
rc = true;
#if JAVA_SPEC_VERSION >= 19
currentThread->ownedMonitorCount += 1;
#endif /* JAVA_SPEC_VERSION >= 19 */
} else {
/* try_enter succeeded - monitor is not inflated - would block */
SET_IGNORE_ENTER(monitor);
Expand Down
32 changes: 20 additions & 12 deletions runtime/vm/monhelpers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2020 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,21 +33,22 @@
IDATA
objectMonitorExit(J9VMThread* vmStruct, j9object_t object)
{
IDATA rc = J9THREAD_ILLEGAL_MONITOR_STATE;
j9objectmonitor_t *lockEA = NULL;
j9objectmonitor_t lock = 0;

Assert_VM_true(vmStruct != NULL);
Assert_VM_true(0 == ((UDATA)vmStruct & OBJECT_HEADER_LOCK_BITS_MASK));

Trc_VM_objectMonitorExit_Entry(vmStruct,object);
Trc_VM_objectMonitorExit_Entry(vmStruct, object);

if (!LN_HAS_LOCKWORD(vmStruct,object)) {
if (!LN_HAS_LOCKWORD(vmStruct, object)) {
J9ObjectMonitor *objectMonitor = NULL;

objectMonitor = monitorTableAt(vmStruct, object);
if (objectMonitor == NULL) {
Trc_VM_objectMonitorExit_Exit_IllegalNullMonitor(vmStruct, object);
return J9THREAD_ILLEGAL_MONITOR_STATE;
goto done;
}

lockEA = &(objectMonitor->alternateLockword);
Expand Down Expand Up @@ -114,7 +115,7 @@ objectMonitorExit(J9VMThread* vmStruct, j9object_t object)
}
} else if (count & OBJECT_HEADER_LOCK_LEARNING) {
/* Lock is in Learning state but unowned (if it were owned it would have been caught by the first Learning state check) */
return J9THREAD_ILLEGAL_MONITOR_STATE;
goto done;
} else if (count >= OBJECT_HEADER_LOCK_FIRST_RECURSION_BIT) {
/* just decrement the flatlock recursion count */
lock -= OBJECT_HEADER_LOCK_FIRST_RECURSION_BIT;
Expand All @@ -123,7 +124,7 @@ objectMonitorExit(J9VMThread* vmStruct, j9object_t object)
} else if (count & OBJECT_HEADER_LOCK_RESERVED) {
/* lock is reserved but unowned (if it were owned the count would be >= OBJECT_HEADER_LOCK_FIRST_RECURSION_BIT) */
Trc_VM_objectMonitorExit_Exit_ReservedButUnownedFlatLock(vmStruct, lock, object);
return J9THREAD_ILLEGAL_MONITOR_STATE;
goto done;
#endif
} else {
/* FLC set, non-recursive */
Expand All @@ -142,12 +143,12 @@ objectMonitorExit(J9VMThread* vmStruct, j9object_t object)
}
}
Trc_VM_objectMonitorExit_Exit_FCBSet(vmStruct);
return 0;
rc = 0;
goto done;
} else if (J9_LOCK_IS_INFLATED(lock)) {
/* Dealing with an inflated monitor */
J9ObjectMonitor *objectMonitor = NULL;
J9ThreadAbstractMonitor *monitor = NULL;
IDATA rc = 0;
IDATA deflate = 1;

objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
Expand All @@ -164,7 +165,7 @@ objectMonitorExit(J9VMThread* vmStruct, j9object_t object)

if (monitor->owner != vmStruct->osThread) {
Trc_VM_objectMonitorExit_Exit_IllegalInflatedLock(vmStruct, monitor->owner, vmStruct->osThread);
return J9THREAD_ILLEGAL_MONITOR_STATE;
goto done;
}

/*
Expand Down Expand Up @@ -218,18 +219,25 @@ objectMonitorExit(J9VMThread* vmStruct, j9object_t object)
}
}
}
rc = omrthread_monitor_exit((omrthread_monitor_t)monitor);
rc = omrthread_monitor_exit((omrthread_monitor_t)monitor);
Trc_VM_objectMonitorExit_Exit_InflatedLock(vmStruct, rc);
return rc;
goto done;
} else {
/* flat lock, but wrong thread */
Assert_VM_true( (lock == 0) || (lock == OBJECT_HEADER_LOCK_LEARNING) || (lock == OBJECT_HEADER_LOCK_RESERVED) || ((UDATA)lock & ~(UDATA)OBJECT_HEADER_LOCK_BITS_MASK) );
Trc_VM_objectMonitorExit_Exit_IllegalFlatLock(vmStruct, lock, object);
return J9THREAD_ILLEGAL_MONITOR_STATE;
goto done;
}

Assert_VM_unreachable();

done:
#if JAVA_SPEC_VERSION >= 19
if (0 == rc) {
vmStruct->ownedMonitorCount -= 1;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
return rc;
}


Expand Down

0 comments on commit 96dca6c

Please sign in to comment.