org.jikesrvm.scheduler
Class ThinLock

java.lang.Object
  extended by org.jikesrvm.scheduler.ThinLock
All Implemented Interfaces:
ThinLockConstants, SizeConstants

public final class ThinLock
extends Object
implements ThinLockConstants

Implementation of thin locks.


Field Summary
private static boolean ENABLE_BIASED_LOCKING
           
(package private) static int fastLocks
           
private static int retryLimit
          Number of times a thread yields before inflating the lock on a object to a heavy-weight lock.
(package private) static int slowLocks
           
(package private) static boolean STATS
           
(package private) static boolean trace
           
 
Fields inherited from interface org.jikesrvm.objectmodel.ThinLockConstants
TL_DEDICATED_U16_OFFSET, TL_DEDICATED_U16_SHIFT, TL_LOCK_COUNT_MASK, TL_LOCK_COUNT_SHIFT, TL_LOCK_COUNT_UNIT, TL_LOCK_ID_MASK, TL_LOCK_ID_SHIFT, TL_NUM_BITS_RC, TL_NUM_BITS_STAT, TL_NUM_BITS_TID, TL_STAT_BIASABLE, TL_STAT_FAT, TL_STAT_MASK, TL_STAT_SHIFT, TL_STAT_THIN, TL_THREAD_ID_MASK, TL_THREAD_ID_SHIFT, TL_UNLOCK_MASK
 
Fields inherited from interface org.jikesrvm.SizeConstants
BITS_IN_ADDRESS, BITS_IN_BOOLEAN, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_DOUBLE, BITS_IN_EXTENT, BITS_IN_FLOAT, BITS_IN_INT, BITS_IN_LONG, BITS_IN_OFFSET, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_EXTENT, BYTES_IN_FLOAT, BYTES_IN_INT, BYTES_IN_LONG, BYTES_IN_OFFSET, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BOOLEAN, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_DOUBLE, LOG_BITS_IN_EXTENT, LOG_BITS_IN_FLOAT, LOG_BITS_IN_INT, LOG_BITS_IN_LONG, LOG_BITS_IN_OFFSET, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_BOOLEAN, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_DOUBLE, LOG_BYTES_IN_EXTENT, LOG_BYTES_IN_FLOAT, LOG_BYTES_IN_INT, LOG_BYTES_IN_LONG, LOG_BYTES_IN_OFFSET, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD
 
Constructor Summary
ThinLock()
           
 
Method Summary
protected static Lock attemptToInflate(Object o, Offset lockOffset, Lock l)
          Promotes a light-weight lock to a heavy-weight lock.
static boolean attemptToMarkDeflated(Object o, Offset lockOffset, Word oldLockWord)
           
static boolean attemptToMarkInflated(Object o, Offset lockOffset, Word oldLockWord, int lockId, int cnt)
           
private static Word biasBitsToThinBits(Word bits)
           
static boolean casFromBiased(Object o, Offset lockOffset, Word oldLockWord, Word changed, int cnt)
           
static Lock getHeavyLock(Object o, Offset lockOffset, boolean create)
          Obtains the heavy-weight lock, if there is one, associated with the indicated object.
static int getLockIndex(Word lockWord)
          Return the lock index for a given lock word.
static int getLockOwner(Word lockWord)
           
static int getRecCount(Word lockWord)
           
static boolean holdsLock(Object o, Offset lockOffset, RVMThread thread)
           
private static Lock inflate(Object o, Offset lockOffset)
          Promotes a light-weight lock to a heavy-weight lock.
private static boolean inflateAndLock(Object o, Offset lockOffset)
          Promotes a light-weight lock to a heavy-weight lock and locks it.
static void inlineLock(Object o, Offset lockOffset)
           
static void inlineUnlock(Object o, Offset lockOffset)
           
static boolean isFat(Word lockWord)
           
static void lock(Object o, Offset lockOffset)
           
static void markDeflated(Object o, Offset lockOffset, int id)
           
(package private) static void notifyAppRunStart(String app, int value)
           
(package private) static void notifyExit(int value)
           
private static void setDedicatedU16(Object o, Offset lockOffset, Word value)
          Set only the dedicated locking 16-bit part of the given value.
static void unlock(Object o, Offset lockOffset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_BIASED_LOCKING

private static final boolean ENABLE_BIASED_LOCKING
See Also:
Constant Field Values

retryLimit

private static final int retryLimit
Number of times a thread yields before inflating the lock on a object to a heavy-weight lock. The current value was for the portBOB benchmark on a 12-way SMP (AIX) in the Fall of '99. FP confirmed that it's still optimal for JBB and DaCapo on 4-, 8-, and 16-way SMPs (Linux/ia32) in Spring '09.

See Also:
Constant Field Values

STATS

static final boolean STATS
See Also:
Constant Field Values

trace

static final boolean trace
See Also:
Constant Field Values

fastLocks

static int fastLocks

slowLocks

static int slowLocks
Constructor Detail

ThinLock

public ThinLock()
Method Detail

inlineLock

public static void inlineLock(Object o,
                              Offset lockOffset)

inlineUnlock

public static void inlineUnlock(Object o,
                                Offset lockOffset)

lock

public static void lock(Object o,
                        Offset lockOffset)

unlock

public static void unlock(Object o,
                          Offset lockOffset)

holdsLock

public static boolean holdsLock(Object o,
                                Offset lockOffset,
                                RVMThread thread)

isFat

public static boolean isFat(Word lockWord)

getLockIndex

public static int getLockIndex(Word lockWord)
Return the lock index for a given lock word. Assert valid index ranges, that the fat lock bit is set, and that the lock entry exists.

Parameters:
lockWord - The lock word whose lock index is being established
Returns:
the lock index corresponding to the lock workd.

getLockOwner

public static int getLockOwner(Word lockWord)

getRecCount

public static int getRecCount(Word lockWord)

setDedicatedU16

private static void setDedicatedU16(Object o,
                                    Offset lockOffset,
                                    Word value)
Set only the dedicated locking 16-bit part of the given value. This is the only part that is allowed to be written without a CAS. This takes care of the shifting and storing of the value.

Parameters:
o - The object whose header is to be changed
lockOffset - The lock offset
value - The value which contains the 16-bit portion to be written.

casFromBiased

public static boolean casFromBiased(Object o,
                                    Offset lockOffset,
                                    Word oldLockWord,
                                    Word changed,
                                    int cnt)

attemptToMarkInflated

public static boolean attemptToMarkInflated(Object o,
                                            Offset lockOffset,
                                            Word oldLockWord,
                                            int lockId,
                                            int cnt)

attemptToInflate

protected static Lock attemptToInflate(Object o,
                                       Offset lockOffset,
                                       Lock l)
Promotes a light-weight lock to a heavy-weight lock. If this returns the lock that you gave it, its mutex will be locked; otherwise, its mutex will be unlocked. Hence, calls to this method should always be followed by a condition lock() or unlock() call.

Parameters:
o - the object to get a heavy-weight lock
lockOffset - the offset of the thin lock word in the object.
Returns:
the inflated lock; either the one you gave, or another one, if the lock was inflated by some other thread.

biasBitsToThinBits

private static Word biasBitsToThinBits(Word bits)

attemptToMarkDeflated

public static boolean attemptToMarkDeflated(Object o,
                                            Offset lockOffset,
                                            Word oldLockWord)

markDeflated

public static void markDeflated(Object o,
                                Offset lockOffset,
                                int id)

inflate

private static Lock inflate(Object o,
                            Offset lockOffset)
Promotes a light-weight lock to a heavy-weight lock. Note: the object is question will normally be locked by another thread, or it may be unlocked. If there is already a heavy-weight lock on this object, that lock is returned.

Parameters:
o - the object to get a heavy-weight lock
lockOffset - the offset of the thin lock word in the object.
Returns:
the heavy-weight lock on this object

inflateAndLock

private static boolean inflateAndLock(Object o,
                                      Offset lockOffset)
Promotes a light-weight lock to a heavy-weight lock and locks it. Note: the object in question will normally be locked by another thread, or it may be unlocked. If there is already a heavy-weight lock on this object, that lock is returned.

Parameters:
o - the object to get a heavy-weight lock
lockOffset - the offset of the thin lock word in the object.
Returns:
whether the object was successfully locked

getHeavyLock

public static Lock getHeavyLock(Object o,
                                Offset lockOffset,
                                boolean create)
Obtains the heavy-weight lock, if there is one, associated with the indicated object. Returns null, if there is no heavy-weight lock associated with the object.

Parameters:
o - the object from which a lock is desired
lockOffset - the offset of the thin lock word in the object.
create - if true, create heavy lock if none found
Returns:
the heavy-weight lock on the object (if any)

notifyAppRunStart

static void notifyAppRunStart(String app,
                              int value)

notifyExit

static void notifyExit(int value)