Top Description Inners Fields Constructors Methods
net.sf.ehcache.util.concurrent

pack-priv abstract Class Striped64

extends Number
Class Inheritance
Known Direct Subclasses
net.sf.ehcache.util.concurrent.LongAdder
Annotations
@SuppressWarnings:restriction
Imports
java.util.Random, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicLongFieldUpdater

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.

pack-priv static class
Striped64.HashCode

Holder for the thread-local hash code.

pack-priv static class
Striped64.ThreadHashCode

The corresponding ThreadLocal class

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.

pack-priv static final AtomicLongFieldUpdater<Striped64>
pack-priv transient volatile int
busy

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

pack-priv static final AtomicIntegerFieldUpdater<Striped64>
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 Striped64.ThreadHashCode
threadHashCode

Static per-thread hash codes.

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.

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
,
Striped64.HashCode
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.

BASE_UPDATERback to summary
pack-priv static final AtomicLongFieldUpdater<Striped64> BASE_UPDATER
busyback to summary
pack-priv transient volatile int busy

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

BUSY_UPDATERback to summary
pack-priv static final AtomicIntegerFieldUpdater<Striped64> BUSY_UPDATER
cellsback to summary
pack-priv transient volatile Striped64.Cell[] cells

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

NCPUback to summary
pack-priv static final int NCPU

Number of CPUS, to place bound on table size

threadHashCodeback to summary
pack-priv static final Striped64.ThreadHashCode threadHashCode

Static per-thread hash codes. Shared across all instances to reduce ThreadLocal pollution and because adjustments due to collisions in one table are likely to be appropriate for others.

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

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, Striped64.HashCode 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:Striped64.HashCode

the hash code holder

wasUncontended:boolean

false if CAS failed before call

net.sf.ehcache.util.concurrent 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
pack-priv volatile long
private static final AtomicLongFieldUpdater<Striped64.Cell>

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
valueback to summary
pack-priv volatile long value
VALUE_UPDATERback to summary
private static final AtomicLongFieldUpdater<Striped64.Cell> VALUE_UPDATER

Constructor Detail

Cellback to summary
pack-priv Cell(long x)

Method Detail

casback to summary
pack-priv final boolean cas(long cmp, long val)
net.sf.ehcache.util.concurrent back to summary

pack-priv final Class Striped64.HashCode

extends Object
Class Inheritance

Holder for the thread-local hash code. The code is initially random, but may be set to a different value upon collisions.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv static final Random

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codeback to summary
pack-priv int code
rngback to summary
pack-priv static final Random rng

Constructor Detail

HashCodeback to summary
pack-priv HashCode()
net.sf.ehcache.util.concurrent back to summary

pack-priv final Class Striped64.ThreadHashCode

extends ThreadLocal<Striped64.HashCode>
Class Inheritance

The corresponding ThreadLocal class

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Striped64.HashCode
initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable.
Inherited from java.lang.ThreadLocal:
getremovesetwithInitial

Constructor Detail

ThreadHashCodeback to summary
pack-priv ThreadHashCode()

Method Detail

initialValueback to summary
public Striped64.HashCode initialValue()

Overrides java.lang.ThreadLocal.initialValue.

Doc from java.lang.ThreadLocal.initialValue.

Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the get method, unless the thread previously invoked the set method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of remove followed by get.

Returns:Striped64.HashCode

the initial value for this thread-local