Skip to content

Commit

Permalink
Enable Global Lock Reservation by default on Power
Browse files Browse the repository at this point in the history
Global Lock Reservation is now enabled by default on Power. This is the same
behavior as if the -XX:+GlobalLockReservation option was used. To use the
previous form of lock reservation, Global Lock Reservation can be disabled
with the option -XX:-GlobalLockReservation.

Global Lock Reservation is not supported on other platforms so this change
only affects Power.

Updated documentation and comments to reflect Global Lock Reservation now
being on by default on Power.

Issue: #11424
Signed-off-by: jimmyk <jimmyk@ca.ibm.com>
  • Loading branch information
IBMJimmyk committed May 13, 2021
1 parent a6bf623 commit 1092a92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doc/compiler/ObjectLockword.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2019, 2020 IBM Corp. and others
Copyright (c) 2019, 2021 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 @@ -275,7 +275,7 @@ The Inflated state is also the same as before. It is used to handle cases where
## Current Lock Reservation <a name="current-reservation"></a>
x86 and z have not been fully updated to use all the features of the new lockword format. As such, they effectively use the original system with a lockword that has a 4 bit RC instead of 5 bits. The Learning bit is always set to 0.

Under Power, lock reservation is now controlled by the `-XX:+GlobalLockReservation` option. Without the option, lockwords are always initialized to Flat-Unlocked and never reach any of the Reserved or Learning states. With the option set, lockwords may be initialized to New-PreLearning, New-AutoReserve or Flat-Unlocked. `-XX:-GlobalLockReservation` (note the minus sign) can be used to disable lock reservation. Lock reservation is disabled by default so this is only useful to override an enable option that occurs earlier in command line processing.
Under Power, Global Lock Reservation is enabled by default. Lockwords may be initialized to New-PreLearning, New-AutoReserve or Flat-Unlocked. To disable Global Lock Reservation, the `-XX:-GlobalLockReservation` option must be set. when the option is set, lockwords are always initialized to Flat-Unlocked and the original lock reservation scheme is used. `-XX:+GlobalLockReservation` (note the plus sign) can be used to enable lock reservation (if it was disabled by an option that occurs earlier in command line processing) or to modify some of the lock reservation related suboptions that are described later in this document.

### Reservation Process
The purpose of the new Learning state is to try and reduce the number of lock reservation cancellations by acting as a halfway step towards reservation. If the same object is locked by the same thread enough times without another thread attempting to lock the object, then a prediction is made that it will be safe to reserve the object. The object will transition to a Reserved state. This information is tracked in the Learning state exclusive LC field. The first time a new object is locked it transitions from New-PreLearning to Learning-Locked but the LC will remain at 0. If the same thread locks the object again, even if it is a nested locking action, the LC is incremented. When the LC is equal to `reservedTransitionThreshold` (default value of 1), the next time the object is locked by the same thread it will go to Reserved-Locked instead of Learning-Locked. `reservedTransitionThreshold` can be set via the option `-XX:+GlobalLockReservation:reservedTransitionThreshold=#`. Due to the LC field only having 2 bits, values of `reservedTransitionThreshold` of 4 or higher will prevent transition from Learning to Reserved.
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/p/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4980,7 +4980,7 @@ TR::Register *J9::Power::TreeEvaluator::VMmonexitEvaluator(TR::Node *node, TR::C
baseReg = objectClassReg;
}

/* If the -XX:+GlobalLockReservation option is NOT set, try to use the original aggressive reserved locking code path. */
/* If the -XX:-GlobalLockReservation option is set, try to use the original aggressive reserved locking code path. */
if (!fej9->isEnableGlobalLockReservationSet())
{
bool reserveLocking = false, normalLockWithReservationPreserving = false;
Expand Down Expand Up @@ -7405,7 +7405,7 @@ TR::Register *J9::Power::TreeEvaluator::VMmonentEvaluator(TR::Node *node, TR::Co
baseReg = objectClassReg;
}

/* If the -XX:+GlobalLockReservation option is NOT set, try to use the original aggressive reserved locking code path. */
/* If the -XX:-GlobalLockReservation option is set, try to use the original aggressive reserved locking code path. */
if (!fej9->isEnableGlobalLockReservationSet())
{
bool reserveLocking = false, normalLockWithReservationPreserving = false;
Expand Down
21 changes: 12 additions & 9 deletions runtime/vm/jvminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2424,8 +2424,14 @@ IDATA VMInitStages(J9JavaVM *vm, IDATA stage, void* reserved) {
printLockwordWhat(vm);
}

/* Global Lock Reservation is off by default. */
/* Global Lock Reservation is currently only supported on Power. */
#if defined(AIXPPC) || defined(LINUXPPC)
/* Global Lock Reservation is ON by default on Power. */
vm->enableGlobalLockReservation = 1;
#else
/* Global Lock Reservation is OFF by default on other platforms. */
vm->enableGlobalLockReservation = 0;
#endif /* defined(AIXPPC) || defined(LINUXPPC) */

/* Set default parameters for Global Lock Reservation. */
vm->reservedTransitionThreshold = 1;
Expand All @@ -2437,22 +2443,19 @@ IDATA VMInitStages(J9JavaVM *vm, IDATA stage, void* reserved) {
argIndex = FIND_AND_CONSUME_ARG(EXACT_MATCH, VMOPT_XXNOGLOBALLOCKRESERVATION, NULL);
argIndex2 = FIND_AND_CONSUME_ARG(EXACT_MATCH, VMOPT_XXGLOBALLOCKRESERVATION, NULL);

if ((argIndex2 >= 0) && (argIndex2 > argIndex)) {
/* Global Lock Reservation is currently only supported on Power. */
#if defined(AIXPPC) || defined(LINUXPPC)
vm->enableGlobalLockReservation = 1;
#endif /* defined(AIXPPC) || defined(LINUXPPC) */
if ((argIndex >= 0) && (argIndex > argIndex2)) {
vm->enableGlobalLockReservation = 0;
}

argIndex2 = FIND_AND_CONSUME_ARG_FORWARD(STARTSWITH_MATCH, VMOPT_XXGLOBALLOCKRESERVATIONCOLON, NULL);

while (argIndex2 >= 0) {
if (argIndex2 > argIndex) {
/* Global Lock Reservation is currently only supported on Power. */
/* Global Lock Reservation is currently only supported on Power. */
#if defined(AIXPPC) || defined(LINUXPPC)
if (argIndex2 > argIndex) {
vm->enableGlobalLockReservation = 1;
#endif /* defined(AIXPPC) || defined(LINUXPPC) */
}
#endif /* defined(AIXPPC) || defined(LINUXPPC) */

optionValue = NULL;
GET_OPTION_OPTION(argIndex2, ':', ':', &optionValue);
Expand Down

0 comments on commit 1092a92

Please sign in to comment.