Class 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.

    • 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 offset
      static <E> void spElement​(E[] buffer, long offset, E e)
      A plain store (no ordering/fences) of an element to a given offset
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • REF_ARRAY_BASE

        public static final long REF_ARRAY_BASE
      • REF_ELEMENT_SHIFT

        public static final int REF_ELEMENT_SHIFT
    • Constructor Detail

      • UnsafeRefArrayAccess

        private UnsafeRefArrayAccess()
    • 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.buffer
        offset - computed via calcElementOffset(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.buffer
        offset - computed via calcElementOffset(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.buffer
        offset - computed via calcElementOffset(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.buffer
        offset - computed via calcElementOffset(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.