Top Description Inners Fields Constructors Methods
com.google.common.cache

pack-priv abstract Class Striped64

extends Number
Class Inheritance
Known Direct Subclasses
com.google.common.cache.LongAdder
Annotations
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtIncompatible, java.util.Random, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

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 long
pack-priv transient volatile int
busy

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

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

Table of cells.

pack-priv static final int
NCPU

Number of CPUS, to place bound on table size

pack-priv static final Random
rng

Generator of new random hash codes

pack-priv static final ThreadLocal<@Nullable int[]>
threadHashCode

ThreadLocal holding a single-slot int array holding hash code.

private static final Unsafe

Constructor Summary

AccessConstructor and Description
pack-priv
Striped64()

Package-private default constructor

Method Summary

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

CASes the base field.

pack-priv final boolean
casBusy()

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

pack-priv abstract long

Returns:

result of the update function
fn
(long
the current value (of either base or a cell)
currentValue
,
long
the argument from a user update call
newValue
)

Computes the function of current and new value.

private static Unsafe

Returns:

a sun.misc.Unsafe
getUnsafe
()

Returns a sun.misc.Unsafe.

pack-priv final void
internalReset(long initialValue)

Sets base and all cells to the given value.

pack-priv final void
retryUpdate(long
the value
x
,
int[]
the hash code holder
hc
,
boolean
false if CAS failed before call
wasUncontended
)

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.

baseOffsetback to summary
private static final long baseOffset
busyback to summary
pack-priv transient volatile int busy

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

busyOffsetback to summary
private static final long busyOffset
cellsback to summary
pack-priv transient volatile Striped64.Cell[] cells

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

Annotations
@CheckForNull
NCPUback to summary
pack-priv static final int NCPU

Number of CPUS, to place bound on table size

rngback to summary
pack-priv static final Random rng

Generator of new random hash codes

threadHashCodeback to summary
pack-priv static final ThreadLocal<@Nullable 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.

UNSAFEback to summary
private static final Unsafe UNSAFE

Constructor Detail

Striped64back to summary
pack-priv Striped64()

Package-private default constructor

Method Detail

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

CASes the base field.

casBusyback to summary
pack-priv final boolean casBusy()

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

fnback to summary
pack-priv 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:long

the current value (of either base or a cell)

newValue:long

the argument from a user update call

Returns:long

result of the update function

getUnsafeback to summary
private static Unsafe getUnsafe()

Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call to Unsafe.getUnsafe when integrating into a jdk.

Returns:Unsafe

a sun.misc.Unsafe

Annotations
@SuppressWarnings:removal
internalResetback to summary
pack-priv final void internalReset(long initialValue)

Sets base and all cells to the given value.

retryUpdateback to summary
pack-priv 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:long

the value

hc:int[]

the hash code holder

wasUncontended:boolean

false if CAS failed before call

com.google.common.cache back to summary

pack-priv final Class Striped64.Cell

extends Object
Class Inheritance

Padded variant of AtomicLong supporting only raw accesses plus CAS. The value field is placed between pads, hoping that the JVM doesn't reorder them.

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
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
pack-priv volatile long
private static final Unsafe
pack-priv volatile long
private static final long

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)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

p0back to summary
pack-priv volatile long p0
p1back to summary
pack-priv volatile long p1
p2back to summary
pack-priv volatile long p2
p3back to summary
pack-priv volatile long p3
p4back to summary
pack-priv volatile long p4
p5back to summary
pack-priv volatile long p5
p6back to summary
pack-priv volatile long p6
q0back to summary
pack-priv volatile long q0
q1back to summary
pack-priv volatile long q1
q2back to summary
pack-priv volatile long q2
q3back to summary
pack-priv volatile long q3
q4back to summary
pack-priv volatile long q4
q5back to summary
pack-priv volatile long q5
q6back to summary
pack-priv volatile long q6
UNSAFEback to summary
private static final Unsafe UNSAFE
valueback to summary
pack-priv volatile long value
valueOffsetback to summary
private static final long valueOffset

Constructor Detail

Cellback to summary
pack-priv Cell(long x)

Method Detail

casback to summary
pack-priv final boolean cas(long cmp, long val)