@Override public final void close() { if (closed.compareAndSet(false, true)) { try { bigArrays.adjustBreaker(-ramBytesUsed(), true); } finally { doClose(); } } }
private <T extends BigArray> T validate(T array) { boolean success = false; try { adjustBreaker(array.ramBytesUsed(), true); success = true; } finally { if (!success) { Releasables.closeWhileHandlingException(array); } } return array; }
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) { final long oldMemSize = array.ramBytesUsed(); final long oldSize = array.size(); assert oldMemSize == array.ramBytesEstimated(oldSize) : "ram bytes used should equal that which was previously estimated: ramBytesUsed=" + oldMemSize + ", ramBytesEstimated=" + array.ramBytesEstimated(oldSize); final long estimatedIncreaseInBytes = array.ramBytesEstimated(newSize) - oldMemSize; adjustBreaker(estimatedIncreaseInBytes, false); array.resize(newSize); return array; }
/** * Allocate a new {@link LongArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public LongArray newLongArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.LONG_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigLongArray.estimateRamBytes(size), false); return new BigLongArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.LONG_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<long[]> page = recycler.longPage(clearOnResize); return validate(new LongArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new LongArrayWrapper(this, new long[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link ObjectArray}. * @param size the initial length of the array */ public <T> ObjectArray<T> newObjectArray(long size) { final ObjectArray<T> array; if (size > PageCacheRecycler.OBJECT_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigObjectArray.estimateRamBytes(size), false); return new BigObjectArray<>(size, this); } else if (size >= PageCacheRecycler.OBJECT_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<Object[]> page = recycler.objectPage(); return validate(new ObjectArrayWrapper<>(this, page.v(), size, page)); } else { return validate(new ObjectArrayWrapper<>(this, new Object[(int) size], size, null)); } }
/** * Allocate a new {@link IntArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public IntArray newIntArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.INT_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigIntArray.estimateRamBytes(size), false); return new BigIntArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.INT_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<int[]> page = recycler.intPage(clearOnResize); return validate(new IntArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new IntArrayWrapper(this, new int[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link ByteArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public ByteArray newByteArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.BYTE_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigByteArray.estimateRamBytes(size), false); return new BigByteArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.BYTE_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<byte[]> page = recycler.bytePage(clearOnResize); return validate(new ByteArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new ByteArrayWrapper(this, new byte[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link DoubleArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public DoubleArray newDoubleArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.LONG_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigDoubleArray.estimateRamBytes(size), false); return new BigDoubleArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.LONG_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<long[]> page = recycler.longPage(clearOnResize); return validate(new DoubleArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new DoubleArrayWrapper(this, new long[(int) size], size, null, clearOnResize)); } }
/** * Allocate a new {@link FloatArray}. * @param size the initial length of the array * @param clearOnResize whether values should be set to 0 on initialization and resize */ public FloatArray newFloatArray(long size, boolean clearOnResize) { if (size > PageCacheRecycler.INT_PAGE_SIZE) { // when allocating big arrays, we want to first ensure we have the capacity by // checking with the circuit breaker before attempting to allocate adjustBreaker(BigFloatArray.estimateRamBytes(size), false); return new BigFloatArray(size, this, clearOnResize); } else if (size >= PageCacheRecycler.INT_PAGE_SIZE / 2 && recycler != null) { final Recycler.V<int[]> page = recycler.intPage(clearOnResize); return validate(new FloatArrayWrapper(this, page.v(), size, page, clearOnResize)); } else { return validate(new FloatArrayWrapper(this, new int[(int) size], size, null, clearOnResize)); } }
@Override public final void close() { if (closed.compareAndSet(false, true)) { try { bigArrays.adjustBreaker(-ramBytesUsed(), true); } finally { doClose(); } } }
@Override public final void close() { if (closed.compareAndSet(false, true)) { try { bigArrays.adjustBreaker(-ramBytesUsed(), true); } finally { doClose(); } } }
private <T extends BigArray> T validate(T array) { boolean success = false; try { adjustBreaker(array.ramBytesUsed(), true); success = true; } finally { if (!success) { Releasables.closeWhileHandlingException(array); } } return array; }
@Override public final void close() { if (closed.compareAndSet(false, true)) { try { bigArrays.adjustBreaker(-ramBytesUsed(), true); } finally { doClose(); } } }
private <T extends BigArray> T validate(T array) { boolean success = false; try { adjustBreaker(array.ramBytesUsed()); success = true; } finally { if (!success) { Releasables.closeWhileHandlingException(array); } } return array; }
private <T extends BigArray> T validate(T array) { boolean success = false; try { adjustBreaker(array.ramBytesUsed(), true); success = true; } finally { if (!success) { Releasables.closeWhileHandlingException(array); } } return array; }
private <T extends BigArray> T validate(T array) { boolean success = false; try { adjustBreaker(array.ramBytesUsed(), true); success = true; } finally { if (!success) { Releasables.closeWhileHandlingException(array); } } return array; }
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) { final long oldMemSize = array.ramBytesUsed(); array.resize(newSize); adjustBreaker(array.ramBytesUsed() - oldMemSize); return array; }
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) { final long oldMemSize = array.ramBytesUsed(); final long oldSize = array.size(); assert oldMemSize == array.ramBytesEstimated(oldSize) : "ram bytes used should equal that which was previously estimated: ramBytesUsed=" + oldMemSize + ", ramBytesEstimated=" + array.ramBytesEstimated(oldSize); final long estimatedIncreaseInBytes = array.ramBytesEstimated(newSize) - oldMemSize; adjustBreaker(estimatedIncreaseInBytes, false); array.resize(newSize); return array; }
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) { final long oldMemSize = array.ramBytesUsed(); final long oldSize = array.size(); assert oldMemSize == array.ramBytesEstimated(oldSize) : "ram bytes used should equal that which was previously estimated: ramBytesUsed=" + oldMemSize + ", ramBytesEstimated=" + array.ramBytesEstimated(oldSize); final long estimatedIncreaseInBytes = array.ramBytesEstimated(newSize) - oldMemSize; adjustBreaker(estimatedIncreaseInBytes, false); array.resize(newSize); return array; }
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) { final long oldMemSize = array.ramBytesUsed(); final long oldSize = array.size(); assert oldMemSize == array.ramBytesEstimated(oldSize) : "ram bytes used should equal that which was previously estimated: ramBytesUsed=" + oldMemSize + ", ramBytesEstimated=" + array.ramBytesEstimated(oldSize); final long estimatedIncreaseInBytes = array.ramBytesEstimated(newSize) - oldMemSize; adjustBreaker(estimatedIncreaseInBytes, false); array.resize(newSize); return array; }