Package org.multiverse.stms.gamma.transactionalobjects

## Class AbstractGammaObject

- java.lang.Object
- - org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject

- All Implemented Interfaces:
    `Lock`, `MultiverseConstants`, `GammaConstants`, `GammaObject`
  Direct Known Subclasses:
    `BaseGammaTxnRef`

      public abstract class AbstractGammaObject
      extends Object
      implements GammaObject, Lock

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected static sun.misc.Unsafe` | `___unsafe` |
    `protected int` | `identityHashCode` |
    `Listeners` | `listeners` |
    `protected static long` | `listenersOffset` |
    `static long` | `MASK_OREC_EXCLUSIVELOCK` |
    `static long` | `MASK_OREC_READBIASED` |
    `static long` | `MASK_OREC_READLOCKS` |
    `static long` | `MASK_OREC_READONLY_COUNT` |
    `static long` | `MASK_OREC_SURPLUS` |
    `static long` | `MASK_OREC_UPDATELOCK` |
    `long` | `orec` |
    `GammaStm` | `stm` |
    `protected static long` | `valueOffset` |
    `long` | `version` |

    - ### Fields inherited from interface org.multiverse.stms.gamma.GammaConstants

      `FAILURE, MASK_CONFLICT, MASK_SUCCESS, MASK_UNREGISTERED, REGISTRATION_DONE, REGISTRATION_NONE, REGISTRATION_NOT_NEEDED, TRANLOCAL_COMMUTING, TRANLOCAL_CONSTRUCTING, TRANLOCAL_READ, TRANLOCAL_WRITE, TRANSACTIONTYPE_FAT_FIXED_LENGTH, TRANSACTIONTYPE_FAT_MONO, TRANSACTIONTYPE_FAT_VARIABLE_LENGTH, TRANSACTIONTYPE_LEAN_FIXED_LENGTH, TRANSACTIONTYPE_LEAN_MONO, TX_ABORTED, TX_ACTIVE, TX_COMMITTED, TX_PREPARED, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_INT, TYPE_LONG, TYPE_REF, VERSION_UNCOMMITTED`

    - ### Fields inherited from interface org.multiverse.MultiverseConstants

      `LOCKMODE_EXCLUSIVE, LOCKMODE_NONE, LOCKMODE_READ, LOCKMODE_WRITE, SHAKE_BUGS, SPIN_YIELD, TRACING_ENABLED`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AbstractGammaObject​(GammaStm stm)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Listeners` | `___removeListenersAfterWrite()` |
    `String` | `___toOrecString()` |
    `int` | `arrive​(int spinCount)` | Arrives.
    `int` | `arriveAndExclusiveLock​(int spinCount)` | Tries to acquire the exclusive lock and arrive.
    `int` | `arriveAndLock​(int spinCount, int lockMode)` | Arrives and tries to acquire the lock.
    `LockMode` | `atomicGetLockMode()` | Returns the current LockMode.
    `int` | `atomicGetLockModeAsInt()` |
    `void` | `departAfterFailure()` | Departs after failure.
    `void` | `departAfterFailureAndUnlock()` | Departs after a transaction fails and has an arrive on this Orec.
    `void` | `departAfterReading()` | Departs after a successful read is done and no lock was acquired.
    `void` | `departAfterReadingAndUnlock()` | Departs after a successful read is done and release the lock (it doesn't matter which lock is acquired as long is it is a read/write/exclusive lock.
    `void` | `departAfterUpdateAndUnlock()` |
    `Lock` | `getLock()` |
    `LockMode` | `getLockMode()` | Gets the LockMode the transaction stored in the the `TxnThreadLocal` has on this Lock.
    `LockMode` | `getLockMode​(Txn tx)` | Gets the LockMode the transaction has on the Lock.
    `LockMode` | `getLockMode​(GammaTxn tx)` |
    `int` | `getReadBiasedThreshold()` |
    `int` | `getReadLockCount()` |
    `static int` | `getReadLockCount​(long value)` |
    `int` | `getReadonlyCount()` |
    `static int` | `getReadonlyCount​(long value)` |
    `GammaStm` | `getStm()` |
    `long` | `getSurplus()` |
    `static long` | `getSurplus​(long value)` |
    `long` | `getVersion()` |
    `static boolean` | `hasAnyLock​(long value)` |
    `boolean` | `hasExclusiveLock()` |
    `static boolean` | `hasExclusiveLock​(long value)` |
    `boolean` | `hasWriteLock()` |
    `static boolean` | `hasWriteLock​(long value)` |
    `static boolean` | `hasWriteOrExclusiveLock​(long value)` |
    `int` | `identityHashCode()` |
    `boolean` | `isReadBiased()` |
    `static boolean` | `isReadBiased​(long value)` |
    `int` | `lockAfterArrive​(int spinCount, int lockMode)` | Arrives and tries to acquire the lock.
    `static long` | `setExclusiveLock​(long value, boolean exclusiveLock)` |
    `static long` | `setIsReadBiased​(long value, boolean isReadBiased)` |
    `static long` | `setReadLockCount​(long value, long readLockCount)` |
    `static long` | `setReadonlyCount​(long value, int readonlyCount)` |
    `static long` | `setSurplus​(long value, long surplus)` |
    `static long` | `setWriteLock​(long value, boolean updateLock)` |
    `void` | `unlockByUnregistered()` |
    `int` | `upgradeReadLock​(int spinCount, boolean exclusiveLock)` |
    `boolean` | `upgradeWriteLock()` | Upgrades the writeLock to an exclusive lock.
    `boolean` | `waitForExclusiveLockToBecomeFree​(int spinCount)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.multiverse.api.Lock

      `acquire, acquire`

- - ### Field Detail

    - #### MASK_OREC_EXCLUSIVELOCK

          public static final long MASK_OREC_EXCLUSIVELOCK

      See Also:
        Constant Field Values

    - #### MASK_OREC_UPDATELOCK

          public static final long MASK_OREC_UPDATELOCK

      See Also:
        Constant Field Values

    - #### MASK_OREC_READBIASED

          public static final long MASK_OREC_READBIASED

      See Also:
        Constant Field Values

    - #### MASK_OREC_READLOCKS

          public static final long MASK_OREC_READLOCKS

      See Also:
        Constant Field Values

    - #### MASK_OREC_SURPLUS

          public static final long MASK_OREC_SURPLUS

      See Also:
        Constant Field Values

    - #### MASK_OREC_READONLY_COUNT

          public static final long MASK_OREC_READONLY_COUNT

      See Also:
        Constant Field Values

    - #### ___unsafe

          protected static final sun.misc.Unsafe ___unsafe

    - #### listenersOffset

          protected static final long listenersOffset

    - #### valueOffset

          protected static final long valueOffset

    - #### stm

          public final GammaStm stm

    - #### listeners

          public volatile Listeners listeners

    - #### version

          public volatile long version

    - #### orec

          public volatile long orec

    - #### identityHashCode

          protected int identityHashCode

  - ### Constructor Detail

    - #### AbstractGammaObject

          public AbstractGammaObject​(GammaStm stm)

  - ### Method Detail

    - #### getVersion

          public final long getVersion()

      Specified by:
        `getVersion` in interface `GammaObject`

    - #### getStm

          public final GammaStm getStm()

      Specified by:
        `getStm` in interface `GammaObject`

    - #### getLock

          public final Lock getLock()

      Specified by:
        `getLock` in interface `GammaObject`

    - #### ___removeListenersAfterWrite

          public final Listeners ___removeListenersAfterWrite()

    - #### identityHashCode

          public final int identityHashCode()

      Specified by:
        `identityHashCode` in interface `GammaObject`

    - #### atomicGetLockModeAsInt

          public final int atomicGetLockModeAsInt()

    - #### atomicGetLockMode

          public final LockMode atomicGetLockMode()

      Description copied from interface: `Lock`
      Returns the current LockMode. This call doesn't look at any running transaction, it shows the actual state of the Lock. The value could be stale as soon as it is received. To retrieve the LockMode a a Txn has on a Lock, the `Lock.getLockMode()` or `Lock.getLockMode(Txn)` need to be used.
      Specified by:
        `atomicGetLockMode` in interface `Lock`
      Returns:
        the current LockMode.

    - #### getLockMode

          public final LockMode getLockMode()

      Description copied from interface: `Lock`
      Gets the LockMode the transaction stored in the the `TxnThreadLocal` has on this Lock. To retrieve the actual LockMode of the Lock, you need to use the `Lock.atomicGetLockMode()`.
      Specified by:
        `getLockMode` in interface `Lock`
      Returns:
        the LockMode.
      See Also:
        `Lock.atomicGetLockMode()`, `Lock.getLockMode(Txn)`

    - #### getLockMode

          public final LockMode getLockMode​(Txn tx)

      Description copied from interface: `Lock`
      Gets the LockMode the transaction has on the Lock. This call makes use of the tx. To retrieve the actual LockMode of the Lock, you need to use the `Lock.atomicGetLockMode()`
      Specified by:
        `getLockMode` in interface `Lock`
      Parameters:
        `tx` - the Lock
      Returns:
        the LockMode the transaction has on the Lock.
      See Also:
        `Lock.atomicGetLockMode()`, `Lock.getLockMode(Txn)`

    - #### getLockMode

          public final LockMode getLockMode​(GammaTxn tx)

    - #### waitForExclusiveLockToBecomeFree

          public final boolean waitForExclusiveLockToBecomeFree​(int spinCount)

    - #### hasWriteLock

          public final boolean hasWriteLock()

    - #### hasExclusiveLock

          public final boolean hasExclusiveLock()

    - #### getReadBiasedThreshold

          public final int getReadBiasedThreshold()

    - #### getSurplus

          public final long getSurplus()

    - #### isReadBiased

          public final boolean isReadBiased()

    - #### getReadonlyCount

          public final int getReadonlyCount()

    - #### getReadLockCount

          public final int getReadLockCount()

    - #### arrive

          public final int arrive​(int spinCount)

      Arrives. The Arrive is needed for the fast conflict detection (rich mans conflict).
      Parameters:
        `spinCount` - the maximum number of times to spin if the exclusive lock is acquired.
      Returns:
        the arrive status.

    - #### upgradeReadLock

          public final int upgradeReadLock​(int spinCount,
                                           boolean exclusiveLock)

    - #### upgradeWriteLock

          public final boolean upgradeWriteLock()

      Upgrades the writeLock to an exclusive lock.
      Returns:
        true if there was at least one conflict write.

    - #### arriveAndLock

          public final int arriveAndLock​(int spinCount,
                                         int lockMode)

      Arrives and tries to acquire the lock. If one of them fails, there will not be any state change.
      Parameters:
        `spinCount` - the maximum number of times to spin to wait for the lock to come available.
        `lockMode` - the desired lockmode. It isn't allowed to be LOCKMODE_NONE.
      Returns:
        the result of this operation.

    - #### arriveAndExclusiveLock

          public final int arriveAndExclusiveLock​(int spinCount)

      Tries to acquire the exclusive lock and arrive.
      Parameters:
        `spinCount` - the maximum number of spins when it is locked.
      Returns:
        the arrive-status.

    - #### lockAfterArrive

          public final int lockAfterArrive​(int spinCount,
                                           int lockMode)

      Arrives and tries to acquire the lock. If one of them fails, there will not be any state change.
      Parameters:
        `spinCount` - the maximum number of times to spin if a lock is acquired.
        `lockMode` - the desired lockMode. This is not allowed to be LOCKMODE_NONE.
      Returns:
        the status of the operation.

    - #### departAfterReading

          public final void departAfterReading()

      Departs after a successful read is done and no lock was acquired.

      This call increased the readonly count. If the readonly count threshold is reached, the orec is made readbiased and the readonly count is set to 0.

    - #### departAfterReadingAndUnlock

          public final void departAfterReadingAndUnlock()

      Departs after a successful read is done and release the lock (it doesn't matter which lock is acquired as long is it is a read/write/exclusive lock.

      This method increases the readonly count of the orec and upgraded from update-biased to readbiased if the READBIASED_THRESHOLD is reached (also the readonly count is set to zero if that happens).

    - #### departAfterUpdateAndUnlock

          public final void departAfterUpdateAndUnlock()

    - #### departAfterFailureAndUnlock

          public final void departAfterFailureAndUnlock()

      Departs after a transaction fails and has an arrive on this Orec. It doesn't matter what the lock level is, as long as it is higher than LOCKMODE_NONE. This call can safely be made on a read or update biased ref.

    - #### departAfterFailure

          public final void departAfterFailure()

      Departs after failure.

    - #### unlockByUnregistered

          public final void unlockByUnregistered()

    - #### ___toOrecString

          public final String ___toOrecString()

    - #### setReadLockCount

          public static long setReadLockCount​(long value,
                                              long readLockCount)

    - #### getReadLockCount

          public static int getReadLockCount​(long value)

    - #### setExclusiveLock

          public static long setExclusiveLock​(long value,
                                              boolean exclusiveLock)

    - #### hasWriteOrExclusiveLock

          public static boolean hasWriteOrExclusiveLock​(long value)

    - #### hasAnyLock

          public static boolean hasAnyLock​(long value)

    - #### hasExclusiveLock

          public static boolean hasExclusiveLock​(long value)

    - #### isReadBiased

          public static boolean isReadBiased​(long value)

    - #### setIsReadBiased

          public static long setIsReadBiased​(long value,
                                             boolean isReadBiased)

    - #### hasWriteLock

          public static boolean hasWriteLock​(long value)

    - #### setWriteLock

          public static long setWriteLock​(long value,
                                          boolean updateLock)

    - #### getReadonlyCount

          public static int getReadonlyCount​(long value)

    - #### setReadonlyCount

          public static long setReadonlyCount​(long value,
                                              int readonlyCount)

    - #### setSurplus

          public static long setSurplus​(long value,
                                        long surplus)

    - #### getSurplus

          public static long getSurplus​(long value)