Package io.prometheus.client
Class Striped64
- java.lang.Object
-
- java.lang.Number
-
- io.prometheus.client.Striped64
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
DoubleAdder
abstract class Striped64 extends java.lang.NumberA package-local class holding common representation and mechanics for classes supporting dynamic striping on 64bit values. The class extends Number so that concrete subclasses must publicly do so.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classStriped64.CellPadded variant of AtomicLong supporting only raw accesses plus CAS.
-
Field Summary
Fields Modifier and Type Field Description (package private) longbaseBase value, used mainly when there is no contention, but also as a fallback during table initialization races.(package private) intbusySpinlock (locked via CAS) used when resizing and/or creating Cells.private static java.util.concurrent.atomic.AtomicLongFieldUpdater<Striped64>CAS_BASEprivate static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<Striped64>CAS_BUSY(package private) Striped64.Cell[]cellsTable of cells.(package private) static intNCPUNumber of CPUS, to place bound on table size(package private) static java.util.RandomrngGenerator of new random hash codes(package private) static java.lang.ThreadLocal<int[]>threadHashCodeThreadLocal holding a single-slot int array holding hash code.
-
Constructor Summary
Constructors Constructor Description Striped64()Package-private default constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) booleancasBase(long cmp, long val)CASes the base field.(package private) booleancasBusy()CASes the busy field from 0 to 1 to acquire lock.(package private) abstract longfn(long currentValue, long newValue)Computes the function of current and new value.(package private) voidinternalReset(long initialValue)Sets base and all cells to the given value.(package private) voidretryUpdate(long x, int[] hc, boolean wasUncontended)Handles cases of updates involving initialization, resizing, creating new Cells, and/or contention.
-
-
-
Field Detail
-
threadHashCode
static final java.lang.ThreadLocal<int[]> threadHashCode
ThreadLocal holding a single-slot int array holding hash code. Unlike the JDK8 version of this class, we use a suboptimal int[] representation to avoid introducing a new type that can impede class-unloading when ThreadLocals are not removed.
-
rng
static final java.util.Random rng
Generator of new random hash codes
-
NCPU
static final int NCPU
Number of CPUS, to place bound on table size
-
cells
transient volatile Striped64.Cell[] cells
Table of cells. When non-null, size is a power of 2.
-
base
transient volatile long base
Base value, used mainly when there is no contention, but also as a fallback during table initialization races. Updated via CAS.
-
busy
transient volatile int busy
Spinlock (locked via CAS) used when resizing and/or creating Cells.
-
CAS_BASE
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<Striped64> CAS_BASE
-
CAS_BUSY
private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<Striped64> CAS_BUSY
-
-
Method Detail
-
casBase
final boolean casBase(long cmp, long val)CASes the base field.
-
casBusy
final boolean casBusy()
CASes the busy field from 0 to 1 to acquire lock.
-
fn
abstract long fn(long currentValue, long newValue)Computes the function of current and new value. Subclasses should open-code this update function for most uses, but the virtualized form is needed within retryUpdate.- Parameters:
currentValue- the current value (of either base or a cell)newValue- the argument from a user update call- Returns:
- result of the update function
-
retryUpdate
final void retryUpdate(long x, int[] hc, boolean wasUncontended)Handles cases of updates involving initialization, resizing, creating new Cells, and/or contention. See above for explanation. This method suffers the usual non-modularity problems of optimistic retry code, relying on rechecked sets of reads.- Parameters:
x- the valuehc- the hash code holderwasUncontended- false if CAS failed before call
-
internalReset
final void internalReset(long initialValue)
Sets base and all cells to the given value.
-
-