@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; }
@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; }
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); }
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); }
@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); } }
@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); } }