Class ConcurrentCircularArrayQueue<E>

  • Type Parameters:
    E - the element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Queue<E>, MessagePassingQueue<E>
    Direct Known Subclasses:
    ConcurrentSequencedCircularArrayQueue, SpmcArrayQueueL1Pad, SpscArrayQueueColdField

    @SuppressAnimalSniffer
    public abstract class ConcurrentCircularArrayQueue<E>
    extends ConcurrentCircularArrayQueueL0Pad<E>
    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 prevention. It is expected that 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 Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected long calcElementOffset​(long index)  
      protected long calcElementOffset​(long index, long mask)  
      void clear()  
      java.util.Iterator<E> iterator()  
      protected E lpElement​(long offset)
      A plain load (no ordering/fences) of an element from a given offset.
      protected E lpElement​(E[] buffer, long offset)
      A plain load (no ordering/fences) of an element from a given offset.
      protected E lvElement​(long offset)
      A volatile load (load + LoadLoad barrier) of an element from a given offset.
      protected E lvElement​(E[] buffer, long offset)
      A volatile load (load + LoadLoad barrier) of an element from a given offset.
      protected void soElement​(long offset, E e)
      An ordered store(store + StoreStore barrier) of an element to a given offset
      protected void soElement​(E[] buffer, long offset, E e)
      An ordered store(store + StoreStore barrier) of an element to a given offset
      protected void spElement​(long offset, E e)
      A plain store (no ordering/fences) of an element to a given offset
      protected 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.util.AbstractQueue

        add, addAll, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Queue

        offer, peek, poll
    • Field Detail

      • SPARSE_SHIFT

        protected static final int SPARSE_SHIFT
      • REF_ARRAY_BASE

        private static final long REF_ARRAY_BASE
      • REF_ELEMENT_SHIFT

        private static final int REF_ELEMENT_SHIFT
      • mask

        protected final long mask
      • buffer

        protected final E[] buffer
    • Constructor Detail

      • ConcurrentCircularArrayQueue

        public ConcurrentCircularArrayQueue​(int capacity)
    • Method Detail

      • calcElementOffset

        protected final long calcElementOffset​(long index)
        Parameters:
        index - desirable element index
        Returns:
        the offset in bytes within the array for a given index.
      • calcElementOffset

        protected final long calcElementOffset​(long index,
                                               long mask)
        Parameters:
        index - desirable element index
        mask -
        Returns:
        the offset in bytes within the array for a given index.
      • spElement

        protected final void spElement​(long offset,
                                       E e)
        A plain store (no ordering/fences) of an element to a given offset
        Parameters:
        offset - computed via calcElementOffset(long)
        e - a kitty
      • spElement

        protected final 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

        protected final void soElement​(long offset,
                                       E e)
        An ordered store(store + StoreStore barrier) of an element to a given offset
        Parameters:
        offset - computed via calcElementOffset(long)
        e - an orderly kitty
      • soElement

        protected final 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

        protected final E lpElement​(long offset)
        A plain load (no ordering/fences) of an element from a given offset.
        Parameters:
        offset - computed via calcElementOffset(long)
        Returns:
        the element at the offset
      • lpElement

        protected final 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

        protected final E lvElement​(long offset)
        A volatile load (load + LoadLoad barrier) of an element from a given offset.
        Parameters:
        offset - computed via calcElementOffset(long)
        Returns:
        the element at the offset
      • lvElement

        protected final 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
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractQueue<E>