/** * Returns the size of this big array in bytes. */ public long sizeOf() { return INSTANCE_SIZE + array.sizeOf() + sizeOfSlices + trackedSlices.sizeOf(); }
/** * Decrements the reference count of an object by 1 and returns the updated reference count */ public int decrementAndGet(Object key) { long hashCode = getHashCode(key); int previousCount = addTo(hashCode, -1); if (previousCount == 1) { remove(hashCode); } return previousCount - 1; }
/** * Increments the reference count of an object by 1 and returns the updated reference count */ public int incrementAndGet(Object key) { return addTo(getHashCode(key), 1) + 1; }
@Benchmark @OperationsPerInvocation(NUMBER_OF_ENTRIES) public ReferenceCountMap benchmarkInserts(Data data) { ReferenceCountMap map = new ReferenceCountMap(); for (int i = 0; i < NUMBER_OF_ENTRIES; i++) { map.incrementAndGet(data.slices[i]); map.incrementAndGet(data.slices[i].getBase()); } return map; }
@Test public void testRetainedSizeWithOverlappingBlocks() { int entries = 123; BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries); for (int i = 0; i < entries; i++) { blockBuilder.writeInt(i); } Block block = blockBuilder.build(); // Verify we do not over count int arraySize = 456; int blocks = 7890; BlockBigArray blockBigArray = new BlockBigArray(); blockBigArray.ensureCapacity(arraySize); for (int i = 0; i < blocks; i++) { blockBigArray.set(i % arraySize, block.getRegion(0, entries)); } ReferenceCountMap referenceCountMap = new ReferenceCountMap(); referenceCountMap.incrementAndGet(block); long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize(); assertEquals(blockBigArray.sizeOf(), expectedSize); } }
private void updateRetainedSize(long index, Slice value) { Slice currentValue = array.get(index); if (currentValue != null) { int baseReferenceCount = trackedSlices.decrementAndGet(currentValue.getBase()); int sliceReferenceCount = trackedSlices.decrementAndGet(currentValue); if (baseReferenceCount == 0) { // it is the last referenced base sizeOfSlices -= currentValue.getRetainedSize(); } else if (sliceReferenceCount == 0) { // it is the last referenced slice sizeOfSlices -= SLICE_INSTANCE_SIZE; } } if (value != null) { int baseReferenceCount = trackedSlices.incrementAndGet(value.getBase()); int sliceReferenceCount = trackedSlices.incrementAndGet(value); if (baseReferenceCount == 1) { // it is the first referenced base sizeOfSlices += value.getRetainedSize(); } else if (sliceReferenceCount == 1) { // it is the first referenced slice sizeOfSlices += SLICE_INSTANCE_SIZE; } } } }
@Benchmark @OperationsPerInvocation(NUMBER_OF_ENTRIES) public ReferenceCountMap benchmarkInserts(Data data) { ReferenceCountMap map = new ReferenceCountMap(); for (int i = 0; i < NUMBER_OF_ENTRIES; i++) { map.incrementAndGet(data.slices[i]); map.incrementAndGet(data.slices[i].getBase()); } return map; }
@Test public void testRetainedSizeWithOverlappingBlocks() { int entries = 123; BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries); for (int i = 0; i < entries; i++) { blockBuilder.writeInt(i); } Block block = blockBuilder.build(); // Verify we do not over count int arraySize = 456; int blocks = 7890; BlockBigArray blockBigArray = new BlockBigArray(); blockBigArray.ensureCapacity(arraySize); for (int i = 0; i < blocks; i++) { blockBigArray.set(i % arraySize, block.getRegion(0, entries)); } ReferenceCountMap referenceCountMap = new ReferenceCountMap(); referenceCountMap.incrementAndGet(block); long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize(); assertEquals(blockBigArray.sizeOf(), expectedSize); } }
private void updateRetainedSize(long index, Slice value) { Slice currentValue = array.get(index); if (currentValue != null) { int baseReferenceCount = trackedSlices.decrementAndGet(currentValue.getBase()); int sliceReferenceCount = trackedSlices.decrementAndGet(currentValue); if (baseReferenceCount == 0) { // it is the last referenced base sizeOfSlices -= currentValue.getRetainedSize(); } else if (sliceReferenceCount == 0) { // it is the last referenced slice sizeOfSlices -= SLICE_INSTANCE_SIZE; } } if (value != null) { int baseReferenceCount = trackedSlices.incrementAndGet(value.getBase()); int sliceReferenceCount = trackedSlices.incrementAndGet(value); if (baseReferenceCount == 1) { // it is the first referenced base sizeOfSlices += value.getRetainedSize(); } else if (sliceReferenceCount == 1) { // it is the first referenced slice sizeOfSlices += SLICE_INSTANCE_SIZE; } } } }
/** * Increments the reference count of an object by 1 and returns the updated reference count */ public int incrementAndGet(Object key) { return addTo(getHashCode(key), 1) + 1; }
private void updateRetainedSize() { // increment the size only when it is the first reference retainedSizeInBytes = Page.INSTANCE_SIZE + SizeOf.sizeOfObjectArray(page.getChannelCount()); ReferenceCountMap referenceCountMap = new ReferenceCountMap(); for (int channel = 0; channel < page.getChannelCount(); channel++) { Block block = page.getBlock(channel); if (!isNotLoadedLazyBlock(block)) { block.retainedBytesForEachPart((object, size) -> { if (referenceCountMap.incrementAndGet(object) == 1) { retainedSizeInBytes += size; } }); } } for (Block previouslyComputedResult : previouslyComputedResults) { if (previouslyComputedResult != null) { previouslyComputedResult.retainedBytesForEachPart((object, size) -> { if (referenceCountMap.incrementAndGet(object) == 1) { retainedSizeInBytes += size; } }); } } memoryContext.setBytes(retainedSizeInBytes); }
return; if (trackedObjects.decrementAndGet(object) == 0) { return; if (trackedObjects.incrementAndGet(object) == 1) {
/** * Decrements the reference count of an object by 1 and returns the updated reference count */ public int decrementAndGet(Object key) { long hashCode = getHashCode(key); int previousCount = addTo(hashCode, -1); if (previousCount == 1) { remove(hashCode); } return previousCount - 1; }
/** * Returns the size of this big array in bytes. */ public long sizeOf() { return INSTANCE_SIZE + array.sizeOf() + sizeOfBlocks + trackedObjects.sizeOf(); }
private void updateRetainedSize() { // increment the size only when it is the first reference retainedSizeInBytes = Page.INSTANCE_SIZE + SizeOf.sizeOfObjectArray(page.getChannelCount()); ReferenceCountMap referenceCountMap = new ReferenceCountMap(); for (int channel = 0; channel < page.getChannelCount(); channel++) { Block block = page.getBlock(channel); if (!isNotLoadedLazyBlock(block)) { block.retainedBytesForEachPart((object, size) -> { if (referenceCountMap.incrementAndGet(object) == 1) { retainedSizeInBytes += size; } }); } } for (Block previouslyComputedResult : previouslyComputedResults) { if (previouslyComputedResult != null) { previouslyComputedResult.retainedBytesForEachPart((object, size) -> { if (referenceCountMap.incrementAndGet(object) == 1) { retainedSizeInBytes += size; } }); } } memoryContext.setBytes(retainedSizeInBytes); }
return; if (trackedObjects.decrementAndGet(object) == 0) { return; if (trackedObjects.incrementAndGet(object) == 1) {
/** * Returns the size of this big array in bytes. */ public long sizeOf() { return INSTANCE_SIZE + array.sizeOf() + sizeOfSlices + trackedSlices.sizeOf(); }
/** * Returns the size of this big array in bytes. */ public long sizeOf() { return INSTANCE_SIZE + array.sizeOf() + sizeOfBlocks + trackedObjects.sizeOf(); }