@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); }
public static int getRequiredBufferSize(final int capacity, final int messageSize) { int alignedMessageSize = (int) Pow2.align(messageSize + MESSAGE_INDICATOR_SIZE, MESSAGE_INDICATOR_SIZE); return HEADER_SIZE + (Pow2.roundToPowerOfTwo(capacity) * alignedMessageSize); }
@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]; } }
/** * Align a value to the next multiple up of alignment. If the value equals an alignment multiple then it * is returned unchanged. * * @param value to be aligned up. * @param alignment to be used, must be a power of 2. * @return the value aligned to the next boundary. */ public static long align(final long value, final int alignment) { if (!isPowerOfTwo(alignment)) { throw new IllegalArgumentException("alignment must be a power of 2:" + alignment); } return (value + (alignment - 1)) & ~(alignment - 1); } }
/** * Align a value to the next multiple up of alignment. If the value equals an alignment multiple then it * is returned unchanged. * * @param value to be aligned up. * @param alignment to be used, must be a power of 2. * @return the value aligned to the next boundary. */ public static long align(final long value, final int alignment) { if (!isPowerOfTwo(alignment)) { throw new IllegalArgumentException("alignment must be a power of 2:" + alignment); } return (value + (alignment - 1)) & ~(alignment - 1); } }
@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]; }
@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]; }
int actualCapacity = Pow2.roundToPowerOfTwo(capacity); this.messageSize = (int) Pow2.align(primitiveMessageSize + MESSAGE_INDICATOR_SIZE, MESSAGE_INDICATOR_SIZE); this.buffy = alignedSlice(HEADER_SIZE + (actualCapacity * (this.messageSize)), CACHE_LINE_SIZE, buff);
@SuppressWarnings("unchecked") public SingleWriterHashSet(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") 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") public OpenHashSet(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") 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 static int getRequiredBufferSize(final int capacity) { return 4 * PortableJvmInfo.CACHE_LINE_SIZE + (Pow2.roundToPowerOfTwo(capacity) << INT_ELEMENT_SCALE); }
@SuppressWarnings("unchecked") MpscCompoundQueueColdFields(int capacity, int queueParallelism) { parallelQueues = isPowerOfTwo(queueParallelism) ? queueParallelism : roundToPowerOfTwo(queueParallelism) / 2; parallelQueuesMask = parallelQueues - 1; queues = new MpscArrayQueue[parallelQueues]; int fullCapacity = roundToPowerOfTwo(capacity); RangeUtil.checkGreaterThanOrEqual(fullCapacity, parallelQueues, "fullCapacity"); for (int i = 0; i < parallelQueues; i++) { queues[i] = new MpscArrayQueue<E>(fullCapacity / parallelQueues); } } }
public static int getRequiredArraySize(final int capacity, final int primitiveMessageSize) { return Pow2.roundToPowerOfTwo(capacity) * primitiveMessageSize; }
@SuppressWarnings("unchecked") MpscCompoundQueueColdFields(int capacity, int queueParallelism) { parallelQueues = isPowerOfTwo(queueParallelism) ? queueParallelism : roundToPowerOfTwo(queueParallelism) / 2; parallelQueuesMask = parallelQueues - 1; queues = new MpscArrayQueue[parallelQueues]; int fullCapacity = roundToPowerOfTwo(capacity); RangeUtil.checkGreaterThanOrEqual(fullCapacity, parallelQueues, "fullCapacity"); for (int i = 0; i < parallelQueues; i++) { queues[i] = new MpscArrayQueue<E>(fullCapacity / parallelQueues); } } }
private int getMaximumCapacity(int requestedCapacity) { return Pow2.roundToPowerOfTwo(requestedCapacity); }
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); } }
public MpscGrowableArrayQueue(int maxCapacity) { super(Math.max(2, Pow2.roundToPowerOfTwo(maxCapacity / 8)), maxCapacity); }