|
@@ -37,17 +37,10 @@ public class BigArrays {
|
|
|
|
|
|
public static final BigArrays NON_RECYCLING_INSTANCE = new BigArrays(null, null, CircuitBreaker.REQUEST);
|
|
|
|
|
|
- /** Page size in bytes: 16KB */
|
|
|
- public static final int PAGE_SIZE_IN_BYTES = 1 << 14;
|
|
|
- public static final int BYTE_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES;
|
|
|
- public static final int INT_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / Integer.BYTES;
|
|
|
- public static final int LONG_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / Long.BYTES;
|
|
|
- public static final int OBJECT_PAGE_SIZE = BigArrays.PAGE_SIZE_IN_BYTES / RamUsageEstimator.NUM_BYTES_OBJECT_REF;
|
|
|
-
|
|
|
/** Returns the next size to grow when working with parallel arrays that
|
|
|
* may have different page sizes or number of bytes per element. */
|
|
|
public static long overSize(long minTargetSize) {
|
|
|
- return overSize(minTargetSize, PAGE_SIZE_IN_BYTES / 8, 1);
|
|
|
+ return overSize(minTargetSize, PageCacheRecycler.PAGE_SIZE_IN_BYTES / 8, 1);
|
|
|
}
|
|
|
|
|
|
/** Return the next size to grow to that is >= <code>minTargetSize</code>.
|
|
@@ -467,12 +460,12 @@ public class BigArrays {
|
|
|
* @param clearOnResize whether values should be set to 0 on initialization and resize
|
|
|
*/
|
|
|
public ByteArray newByteArray(long size, boolean clearOnResize) {
|
|
|
- if (size > BYTE_PAGE_SIZE) {
|
|
|
+ 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 >= BYTE_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -508,7 +501,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, BYTE_PAGE_SIZE, 1);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.BYTE_PAGE_SIZE, 1);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
|
|
@@ -551,12 +544,12 @@ public class BigArrays {
|
|
|
* @param clearOnResize whether values should be set to 0 on initialization and resize
|
|
|
*/
|
|
|
public IntArray newIntArray(long size, boolean clearOnResize) {
|
|
|
- if (size > INT_PAGE_SIZE) {
|
|
|
+ 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 >= INT_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -593,7 +586,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, INT_PAGE_SIZE, Integer.BYTES);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.INT_PAGE_SIZE, Integer.BYTES);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
|
|
@@ -603,12 +596,12 @@ public class BigArrays {
|
|
|
* @param clearOnResize whether values should be set to 0 on initialization and resize
|
|
|
*/
|
|
|
public LongArray newLongArray(long size, boolean clearOnResize) {
|
|
|
- if (size > LONG_PAGE_SIZE) {
|
|
|
+ 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 >= LONG_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -645,7 +638,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, LONG_PAGE_SIZE, Long.BYTES);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
|
|
@@ -655,12 +648,12 @@ public class BigArrays {
|
|
|
* @param clearOnResize whether values should be set to 0 on initialization and resize
|
|
|
*/
|
|
|
public DoubleArray newDoubleArray(long size, boolean clearOnResize) {
|
|
|
- if (size > LONG_PAGE_SIZE) {
|
|
|
+ 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 >= LONG_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -694,7 +687,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, LONG_PAGE_SIZE, Long.BYTES);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.LONG_PAGE_SIZE, Long.BYTES);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
|
|
@@ -704,12 +697,12 @@ public class BigArrays {
|
|
|
* @param clearOnResize whether values should be set to 0 on initialization and resize
|
|
|
*/
|
|
|
public FloatArray newFloatArray(long size, boolean clearOnResize) {
|
|
|
- if (size > INT_PAGE_SIZE) {
|
|
|
+ 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 >= INT_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -743,7 +736,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, INT_PAGE_SIZE, Float.BYTES);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.INT_PAGE_SIZE, Float.BYTES);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
|
|
@@ -752,12 +745,12 @@ public class BigArrays {
|
|
|
* @param size the initial length of the array
|
|
|
*/
|
|
|
public <T> ObjectArray<T> newObjectArray(long size) {
|
|
|
- if (size > OBJECT_PAGE_SIZE) {
|
|
|
+ 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 >= OBJECT_PAGE_SIZE / 2 && recycler != null) {
|
|
|
+ } 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 {
|
|
@@ -785,7 +778,7 @@ public class BigArrays {
|
|
|
if (minSize <= array.size()) {
|
|
|
return array;
|
|
|
}
|
|
|
- final long newSize = overSize(minSize, OBJECT_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
|
|
|
+ final long newSize = overSize(minSize, PageCacheRecycler.OBJECT_PAGE_SIZE, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
|
|
|
return resize(array, newSize);
|
|
|
}
|
|
|
}
|