Class UnsafeRefArrayAccess
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.UnsafeRefArrayAccess
-
final class UnsafeRefArrayAccess extends java.lang.Object
A concurrent access enabling class used by circular array based queues this class exposes an offset computation method along with differently memory fenced load/store methods into the underlying array. The class is pre-padded and the array is padded on either side to help with False sharing prvention. It is expected theat subclasses handle post padding.Offset calculation is separate from access to enable the reuse of a give compute offset.
Load/Store methods using a buffer parameter are provided to allow the prevention of final field reload after a LoadLoad barrier.
-
-
Field Summary
Fields Modifier and Type Field Description static long
REF_ARRAY_BASE
static int
REF_ELEMENT_SHIFT
-
Constructor Summary
Constructors Modifier Constructor Description private
UnsafeRefArrayAccess()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
calcElementOffset(long index)
static <E> E
lpElement(E[] buffer, long offset)
A plain load (no ordering/fences) of an element from a given offset.static <E> E
lvElement(E[] buffer, long offset)
A volatile load (load + LoadLoad barrier) of an element from a given offset.static <E> void
soElement(E[] buffer, long offset, E e)
An ordered store(store + StoreStore barrier) of an element to a given offsetstatic <E> void
spElement(E[] buffer, long offset, E e)
A plain store (no ordering/fences) of an element to a given offset
-
-
-
Method Detail
-
spElement
public static <E> void spElement(E[] buffer, long offset, E e)
A plain store (no ordering/fences) of an element to a given offset- Parameters:
buffer
- this.bufferoffset
- computed viacalcElementOffset(long)
e
- an orderly kitty
-
soElement
public static <E> void soElement(E[] buffer, long offset, E e)
An ordered store(store + StoreStore barrier) of an element to a given offset- Parameters:
buffer
- this.bufferoffset
- computed viacalcElementOffset(long)
e
- an orderly kitty
-
lpElement
public static <E> E lpElement(E[] buffer, long offset)
A plain load (no ordering/fences) of an element from a given offset.- Parameters:
buffer
- this.bufferoffset
- computed viacalcElementOffset(long)
- Returns:
- the element at the offset
-
lvElement
public static <E> E lvElement(E[] buffer, long offset)
A volatile load (load + LoadLoad barrier) of an element from a given offset.- Parameters:
buffer
- this.bufferoffset
- computed viacalcElementOffset(long)
- Returns:
- the element at the offset
-
calcElementOffset
public static long calcElementOffset(long index)
- Parameters:
index
- desirable element index- Returns:
- the offset in bytes within the array for a given index.
-
-