Class UnsafeRefArrayAccess
java.lang.Object
com.github.benmanes.caffeine.cache.UnsafeRefArrayAccess
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
FieldsModifier and TypeFieldDescriptionstatic final long
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
-
Field Details
-
REF_ARRAY_BASE
public static final long REF_ARRAY_BASE -
REF_ELEMENT_SHIFT
public static final int REF_ELEMENT_SHIFT
-
-
Constructor Details
-
UnsafeRefArrayAccess
private UnsafeRefArrayAccess()
-
-
Method Details
-
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.
-