@SuppressWarnings("unchecked") public IdentityOpenHashSet(int capacity) { int actualCapacity = Pow2.roundToPowerOfTwo(capacity); // pad data on either end with some empty slots? buffer = (E[]) new Object[actualCapacity]; resizeThreshold = (int) (0.75 * buffer.length); }
@SuppressWarnings("unchecked") public ConcurrentCircularArray(int capacity) { int actualCapacity = Pow2.roundToPowerOfTwo(capacity); mask = actualCapacity - 1; // pad data on either end with some empty slots. buffer = (E[]) new Object[(actualCapacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; }
protected FixedSizeStripedLongCounterFields(int stripesCount) { if (stripesCount <= 0) { throw new IllegalArgumentException("Expecting a stripesCount that is larger than 0"); } int size = Pow2.roundToPowerOfTwo(stripesCount); cells = new long[CACHE_LINE_IN_LONGS * size]; mask = (size - 1); } }
MpscChunkedAtomicArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }
ConcurrentCircularArrayQueue(int capacity) { int actualCapacity = Pow2.roundToPowerOfTwo(capacity); mask = actualCapacity - 1; buffer = CircularArrayOffsetCalculator.allocate(actualCapacity); }
@SuppressWarnings("unchecked") protected BQueueColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[this.capacity + BUFFER_PAD * 2]; } }
public SpscUnboundedAtomicArrayQueue(int chunkSize) { int chunkCapacity = Math.max(Pow2.roundToPowerOfTwo(chunkSize), 16); long mask = chunkCapacity - 1; AtomicReferenceArray<E> buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with producerBufferLimit = mask - 1; }
public MpscBlockingConsumerArrayQueue(final int capacity) { // leave lower bit of mask clear super((long) ((Pow2.roundToPowerOfTwo(capacity) - 1) << 1), (E[])allocate(Pow2.roundToPowerOfTwo(capacity))); RangeUtil.checkGreaterThanOrEqual(capacity, 1, "capacity"); soProducerLimit((long) ((Pow2.roundToPowerOfTwo(capacity) - 1) << 1)); // we know it's all empty to start with }
@SuppressWarnings("unchecked") public MpmcConcurrentQueueSMBuffer(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; // pad data on either end with some empty slots. buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; }
@SuppressWarnings("unchecked") InlinedRingBufferColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; } }
@SuppressWarnings("unchecked") FloatingCaqColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; } }
public SpscUnboundedArrayQueue(int chunkSize) { int chunkCapacity = Math.max(Pow2.roundToPowerOfTwo(chunkSize), 16); long mask = chunkCapacity - 1; E[] buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; producerBufferLimit = mask - 1; // we know it's all empty to start with }
public SpscOffHeapIntQueue(final int capacity) { this(allocateAlignedByteBuffer( getRequiredBufferSize(capacity), PortableJvmInfo.CACHE_LINE_SIZE), Pow2.roundToPowerOfTwo(capacity),(byte)(PRODUCER | CONSUMER)); }
public OffHeapFixedMessageSizeRingBuffer(final int capacity, final int primitiveMessageSize, int referenceMessageSize) { this(allocateAlignedByteBuffer(getRequiredBufferSize(capacity, primitiveMessageSize), CACHE_LINE_SIZE), Pow2.roundToPowerOfTwo(capacity), true, true, true, primitiveMessageSize, createReferenceArray(capacity, referenceMessageSize), referenceMessageSize); }
public MpscOffHeapFixedSizeRingBuffer(final int capacity, final int messageSize, int referenceMessageSize) { this(allocateAlignedByteBuffer(getRequiredBufferSize(capacity, messageSize), PortableJvmInfo.CACHE_LINE_SIZE), Pow2.roundToPowerOfTwo(capacity), true, true, true, messageSize, createReferenceArray(capacity, referenceMessageSize), referenceMessageSize); }
@Parameterized.Parameters public static Collection<Object[]> parameters() { ArrayList<Object[]> list = new ArrayList<Object[]>(); list.add(makeAtomic(0, 1, Pow2.roundToPowerOfTwo(CPUs), Ordering.NONE, null));// MPSC size 1 list.add(makeAtomic(0, 1, SIZE, Ordering.NONE, null));// MPSC size SIZE return list; } }
@Parameterized.Parameters public static Collection<Object[]> parameters() { ArrayList<Object[]> list = new ArrayList<Object[]>(); list.add(makeMpq(0, 1, Pow2.roundToPowerOfTwo(CPUs), Ordering.NONE, null));// MPSC size 1 list.add(makeMpq(0, 1, SIZE, Ordering.NONE, null));// MPSC size SIZE return list; } }
@Test(expected = IllegalArgumentException.class) public void testMaxRoundException() { Pow2.roundToPowerOfTwo(MAX_POSITIVE_POW2 + 1); fail(); }
@Test public void testPowerOf2Capacity() { assumeThat(spec.isBounded(), is(true)); int n = Pow2.roundToPowerOfTwo(spec.capacity); for (int i = 0; i < n; i++) { assertTrue("Failed to insert:" + i, queue.offer(i)); } assertFalse(queue.offer(n)); }
@Test public void testPowerOf2Capacity() { assumeThat(spec.isBounded(), is(true)); int n = Pow2.roundToPowerOfTwo(spec.capacity); for (int i = 0; i < n; i++) { assertTrue("Failed to insert:" + i, queue.relaxedOffer(i)); } assertFalse(queue.relaxedOffer(n)); }