Top Fields Constructors Methods
com.github.benmanes.caffeine.cache

pack-priv abstract Class BaseMpscLinkedArrayQueue<E>

Located in compilation unit of com.github.benmanes.caffeine.cache.MpscGrowableArrayQueue.

extends BaseMpscLinkedArrayQueueColdProducerFields<E>
Class Inheritance
Known Direct Subclasses
com.github.benmanes.caffeine.cache.MpscChunkedArrayQueueColdProducerFields
Annotations
@SuppressWarnings:NullAway, PMD

Field Summary

Modifier and TypeField and Description
pack-priv static final VarHandle
private static final Object
pack-priv static final VarHandle
pack-priv static final VarHandle
pack-priv static final VarHandle
Inherited from com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueColdProducerFields:
producerBufferproducerLimitproducerMask

Constructor Summary

AccessConstructor and Description
pack-priv
BaseMpscLinkedArrayQueue(final int
the queue initial capacity. If chunk size is fixed this will be the chunk size. Must be 2 or more.
initialCapacity
)

Method Summary

Modifier and TypeMethod and Description
public static <E> E[]
allocate(int capacity)

protected abstract long

Returns:

available elements in queue * 2
availableInQueue
(long pIndex, final long cIndex)

public abstract int
pack-priv static boolean
casProducerIndex(BaseMpscLinkedArrayQueue<?> self, long expect, long newValue)

pack-priv static boolean
casProducerLimit(BaseMpscLinkedArrayQueue<?> self, long expect, long newValue)

public long
public long
protected abstract long

Returns:

current buffer capacity for elements (excluding next pointer and jump entry) * 2
getCurrentBufferCapacity
(long mask)

private E[]
getNextBuffer(final E[] buffer, final long mask)

protected abstract int

Returns:

next buffer size(inclusive of next array pointer)
getNextBufferSize
(E[] buffer)

public final boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty.

Returns true if this collection contains no elements.
public final Iterator<E>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.
pack-priv static long
pack-priv static <E> E

Returns:

the element at the offset
lvElement
(E[]
this.buffer
buffer
,
long
computed
offset
)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

pack-priv static long
private long
pack-priv static long
modifiedCalcElementOffset(long index, long mask)

This method assumes index is actually (index << 1) because lower bit is used for resize.

private long
newBufferAndOffset(E[] nextBuffer, final long index)

private E
newBufferPeek(E[] nextBuffer, final long index)

private E
newBufferPoll(E[] nextBuffer, final long index)

private long
nextArrayOffset(final long mask)

public boolean
offer(final E
the element to add
e
)

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
private int
offerSlowPath(long mask, long pIndex, long producerLimit)

We do not inline resize into this method because we do not resize on fill.

public E
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
public E
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
public boolean
public E
public E
private void
resize(long oldMask, E[] oldBuffer, long pIndex, final E e)

public final int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Returns the number of elements in this collection.
pack-priv static void
pack-priv static <E> void
soElement(E[]
this.buffer
buffer
,
long
computed
offset
,
E
an orderly kitty
e
)

An ordered store(store + StoreStore barrier) of an element to a given offset

pack-priv static void
pack-priv static void
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.

Field Detail

C_INDEXback to summary
pack-priv static final VarHandle C_INDEX
JUMPback to summary
private static final Object JUMP
P_INDEXback to summary
pack-priv static final VarHandle P_INDEX
P_LIMITback to summary
pack-priv static final VarHandle P_LIMIT
REF_ARRAYback to summary
pack-priv static final VarHandle REF_ARRAY

Constructor Detail

BaseMpscLinkedArrayQueueback to summary
pack-priv BaseMpscLinkedArrayQueue(final int initialCapacity)
Parameters
initialCapacity:int

the queue initial capacity. If chunk size is fixed this will be the chunk size. Must be 2 or more.

Method Detail

allocateback to summary
public static <E> E[] allocate(int capacity)
Annotations
@SuppressWarnings:unchecked
availableInQueueback to summary
protected abstract long availableInQueue(long pIndex, final long cIndex)
Returns:long

available elements in queue * 2

capacityback to summary
public abstract int capacity()
casProducerIndexback to summary
pack-priv static boolean casProducerIndex(BaseMpscLinkedArrayQueue<?> self, long expect, long newValue)
casProducerLimitback to summary
pack-priv static boolean casProducerLimit(BaseMpscLinkedArrayQueue<?> self, long expect, long newValue)
currentConsumerIndexback to summary
public long currentConsumerIndex()
currentProducerIndexback to summary
public long currentProducerIndex()
getCurrentBufferCapacityback to summary
protected abstract long getCurrentBufferCapacity(long mask)
Returns:long

current buffer capacity for elements (excluding next pointer and jump entry) * 2

getNextBufferback to summary
private E[] getNextBuffer(final E[] buffer, final long mask)
Annotations
@SuppressWarnings:unchecked
getNextBufferSizeback to summary
protected abstract int getNextBufferSize(E[] buffer)
Returns:int

next buffer size(inclusive of next array pointer)

isEmptyback to summary
public final boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty.

Doc from java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

Returns:boolean

true if this collection contains no elements

Annotations
@Override
iteratorback to summary
public final Iterator<E> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
lvConsumerIndexback to summary
pack-priv static long lvConsumerIndex(BaseMpscLinkedArrayQueue<?> self)
lvElementback to summary
pack-priv static <E> E lvElement(E[] buffer, long offset)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

Parameters
buffer:E[]

this.buffer

offset:long

computed

Returns:E

the element at the offset

Annotations
@SuppressWarnings:unchecked
lvProducerIndexback to summary
pack-priv static long lvProducerIndex(BaseMpscLinkedArrayQueue<?> self)
lvProducerLimitback to summary
private long lvProducerLimit()
modifiedCalcElementOffsetback to summary
pack-priv static long modifiedCalcElementOffset(long index, long mask)

This method assumes index is actually (index << 1) because lower bit is used for resize. This is compensated for by reducing the element shift. The computation is constant folded, so there's no cost.

newBufferAndOffsetback to summary
private long newBufferAndOffset(E[] nextBuffer, final long index)
newBufferPeekback to summary
private E newBufferPeek(E[] nextBuffer, final long index)
newBufferPollback to summary
private E newBufferPoll(E[] nextBuffer, final long index)
nextArrayOffsetback to summary
private long nextArrayOffset(final long mask)
offerback to summary
public boolean offer(final E e)

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
e:E

the element to add

Returns:boolean

true if the element was added to this queue, else false

Annotations
@Override
@SuppressWarnings:MissingDefault
offerSlowPathback to summary
private int offerSlowPath(long mask, long pIndex, long producerLimit)

We do not inline resize into this method because we do not resize on fill.

peekback to summary
public E peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

This implementation is correct for single consumer thread use only.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@SuppressWarnings:unchecked
@Override
pollback to summary
public E poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

This implementation is correct for single consumer thread use only.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
@SuppressWarnings:unchecked
relaxedOfferback to summary
public boolean relaxedOffer(E e)
relaxedPeekback to summary
public E relaxedPeek()
Annotations
@SuppressWarnings:unchecked
relaxedPollback to summary
public E relaxedPoll()
Annotations
@SuppressWarnings:unchecked
resizeback to summary
private void resize(long oldMask, E[] oldBuffer, long pIndex, final E e)
sizeback to summary
public final int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection

Annotations
@Override
soConsumerIndexback to summary
pack-priv static void soConsumerIndex(BaseMpscLinkedArrayQueue<?> self, long v)
soElementback to summary
pack-priv 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:E[]

this.buffer

offset:long

computed

e:E

an orderly kitty

soProducerIndexback to summary
pack-priv static void soProducerIndex(BaseMpscLinkedArrayQueue<?> self, long v)
soProducerLimitback to summary
pack-priv static void soProducerLimit(BaseMpscLinkedArrayQueue<?> self, long v)
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override