Top Description Inners Fields Constructors Methods
java.util.concurrent.atomic

pack-priv abstract Class Striped64

extends Number
Class Inheritance
Known Direct Subclasses
java.util.concurrent.atomic.DoubleAccumulator, java.util.concurrent.atomic.DoubleAdder, java.util.concurrent.atomic.LongAccumulator, java.util.concurrent.atomic.LongAdder
Annotations
@SuppressWarnings:serial
Imports
java.lang.invoke.MethodHandles, .VarHandle, java.util.Arrays, java.util.concurrent.ThreadLocalRandom, java.util.function.DoubleBinaryOperator, .LongBinaryOperator

A 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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Striped64.Cell

Padded variant of AtomicLong supporting only raw accesses plus CAS.

Field Summary

Modifier and TypeField and Description
pack-priv transient volatile long
base

Base value, used mainly when there is no contention, but also as a fallback during table initialization races.

private static final VarHandle
pack-priv transient volatile Striped64.Cell[]
cells

Table of cells.

pack-priv transient volatile int
cellsBusy

Spinlock (locked via CAS) used when resizing and/or creating Cells.

private static final VarHandle
pack-priv static final int
NCPU

Number of CPUS, to place bound on table size

private static final VarHandle

Constructor Summary

AccessConstructor and Description
pack-priv
Striped64()

Package-private default constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv static final int
advanceProbe(int probe)

Pseudo-randomly advances and records the given probe value for the given thread.

private static long
apply(DoubleBinaryOperator fn, long v, double x)

pack-priv final boolean
casBase(long cmp, long val)

CASes the base field.

pack-priv final boolean
casCellsBusy()

CASes the cellsBusy field from 0 to 1 to acquire lock.

pack-priv final void
doubleAccumulate(double x, DoubleBinaryOperator fn, boolean wasUncontended, int index)

Same as longAccumulate, but injecting long/double conversions in too many places to sensibly merge with long version, given the low-overhead requirements of this class.

pack-priv final long
getAndSetBase(long val)

pack-priv static final int
getProbe()

Returns the probe value for the current thread.

pack-priv final void
longAccumulate(long
the value
x
,
LongBinaryOperator
the update function, or null for add (this convention avoids the need for an extra field or function in LongAdder).
fn
,
boolean
false if CAS failed before call
wasUncontended
,
int
thread index from getProbe
index
)

Handles cases of updates involving initialization, resizing, creating new Cells, and/or contention.

Inherited from java.lang.Number:
byteValuedoubleValuefloatValueintValuelongValueshortValue

Field Detail

baseback to summary
pack-priv 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.

BASEback to summary
private static final VarHandle BASE
cellsback to summary
pack-priv transient volatile Striped64.Cell[] cells

Table of cells. When non-null, size is a power of 2.

cellsBusyback to summary
pack-priv transient volatile int cellsBusy

Spinlock (locked via CAS) used when resizing and/or creating Cells.

CELLSBUSYback to summary
private static final VarHandle CELLSBUSY
NCPUback to summary
pack-priv static final int NCPU

Number of CPUS, to place bound on table size

THREAD_PROBEback to summary
private static final VarHandle THREAD_PROBE

Constructor Detail

Striped64back to summary
pack-priv Striped64()

Package-private default constructor.

Method Detail

advanceProbeback to summary
pack-priv static final int advanceProbe(int probe)

Pseudo-randomly advances and records the given probe value for the given thread. Duplicated from ThreadLocalRandom because of packaging restrictions.

applyback to summary
private static long apply(DoubleBinaryOperator fn, long v, double x)
casBaseback to summary
pack-priv final boolean casBase(long cmp, long val)

CASes the base field.

casCellsBusyback to summary
pack-priv final boolean casCellsBusy()

CASes the cellsBusy field from 0 to 1 to acquire lock.

doubleAccumulateback to summary
pack-priv final void doubleAccumulate(double x, DoubleBinaryOperator fn, boolean wasUncontended, int index)

Same as longAccumulate, but injecting long/double conversions in too many places to sensibly merge with long version, given the low-overhead requirements of this class. So must instead be maintained by copy/paste/adapt.

getAndSetBaseback to summary
pack-priv final long getAndSetBase(long val)
getProbeback to summary
pack-priv static final int getProbe()

Returns the probe value for the current thread. Duplicated from ThreadLocalRandom because of packaging restrictions.

longAccumulateback to summary
pack-priv final void longAccumulate(long x, LongBinaryOperator fn, boolean wasUncontended, int index)

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:long

the value

fn:LongBinaryOperator

the update function, or null for add (this convention avoids the need for an extra field or function in LongAdder).

wasUncontended:boolean

false if CAS failed before call

index:int

thread index from getProbe

java.util.concurrent.atomic back to summary

pack-priv final Class Striped64.Cell

extends Object
Class Inheritance
Annotations
@Contended

Padded variant of AtomicLong supporting only raw accesses plus CAS. JVM intrinsics note: It would be possible to use a release-only form of CAS here, if it were provided.

Field Summary

Modifier and TypeField and Description
pack-priv volatile long
private static final VarHandle

Constructor Summary

AccessConstructor and Description
pack-priv
Cell(long x)

Method Summary

Modifier and TypeMethod and Description
pack-priv final boolean
cas(long cmp, long val)

pack-priv final long
getAndSet(long val)

pack-priv final void
pack-priv final void
reset(long identity)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
pack-priv volatile long value
VALUEback to summary
private static final VarHandle VALUE

Constructor Detail

Cellback to summary
pack-priv Cell(long x)

Method Detail

casback to summary
pack-priv final boolean cas(long cmp, long val)
getAndSetback to summary
pack-priv final long getAndSet(long val)
resetback to summary
pack-priv final void reset()
resetback to summary
pack-priv final void reset(long identity)