abstract class Striped64
extends java.lang.Number
Modifier and Type | Class and Description |
---|---|
(package private) static class |
Striped64.Cell
Padded variant of AtomicLong supporting only raw accesses plus CAS.
|
Modifier and Type | Field and Description |
---|---|
(package private) long |
base
Base value, used mainly when there is no contention, but also as
a fallback during table initialization races.
|
private static long |
baseOffset |
(package private) int |
busy
Spinlock (locked via CAS) used when resizing and/or creating Cells.
|
private static long |
busyOffset |
(package private) Striped64.Cell[] |
cells
Table of cells.
|
(package private) static int |
NCPU
Number of CPUS, to place bound on table size
|
(package private) static java.util.Random |
rng
Generator of new random hash codes
|
(package private) static java.lang.ThreadLocal<int[]> |
threadHashCode
ThreadLocal holding a single-slot int array holding hash code.
|
private static sun.misc.Unsafe |
UNSAFE |
Constructor and Description |
---|
Striped64()
Package-private default constructor
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
casBase(long cmp,
long val)
CASes the base field.
|
(package private) boolean |
casBusy()
CASes the busy field from 0 to 1 to acquire lock.
|
(package private) abstract long |
fn(long currentValue,
long newValue)
Computes the function of current and new value.
|
private static sun.misc.Unsafe |
getUnsafe()
Returns a sun.misc.Unsafe.
|
(package private) void |
internalReset(long initialValue)
Sets base and all cells to the given value.
|
(package private) void |
retryUpdate(long x,
int[] hc,
boolean wasUncontended)
Handles cases of updates involving initialization, resizing,
creating new Cells, and/or contention.
|
static final java.lang.ThreadLocal<int[]> threadHashCode
static final java.util.Random rng
static final int NCPU
transient volatile Striped64.Cell[] cells
transient volatile long base
transient volatile int busy
private static final sun.misc.Unsafe UNSAFE
private static final long baseOffset
private static final long busyOffset
final boolean casBase(long cmp, long val)
final boolean casBusy()
abstract long fn(long currentValue, long newValue)
currentValue
- the current value (of either base or a cell)newValue
- the argument from a user update callfinal void retryUpdate(long x, int[] hc, boolean wasUncontended)
x
- the valuehc
- the hash code holderwasUncontended
- false if CAS failed before callfinal void internalReset(long initialValue)
private static sun.misc.Unsafe getUnsafe()