Java Code Examples for io.prestosql.spi.block.Block#getRetainedSizeInBytes()

The following examples show how to use io.prestosql.spi.block.Block#getRetainedSizeInBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagesIndex.java    From presto with Apache License 2.0 6 votes vote down vote up
public void addPage(Page page)
{
    // ignore empty pages
    if (page.getPositionCount() == 0) {
        return;
    }

    positionCount += page.getPositionCount();

    int pageIndex = (channels.length > 0) ? channels[0].size() : 0;
    for (int i = 0; i < channels.length; i++) {
        Block block = page.getBlock(i);
        if (eagerCompact) {
            block = block.copyRegion(0, block.getPositionCount());
        }
        channels[i].add(block);
        pagesMemorySize += block.getRetainedSizeInBytes();
    }

    for (int position = 0; position < page.getPositionCount(); position++) {
        long sliceAddress = encodeSyntheticAddress(pageIndex, position);
        valueAddresses.add(sliceAddress);
    }
    estimatedSize = calculateEstimatedSize();
}
 
Example 2
Source File: PagesIndex.java    From presto with Apache License 2.0 6 votes vote down vote up
public void compact()
{
    if (eagerCompact) {
        return;
    }
    for (int channel = 0; channel < types.size(); channel++) {
        ObjectArrayList<Block> blocks = channels[channel];
        for (int i = nextBlockToCompact; i < blocks.size(); i++) {
            Block block = blocks.get(i);

            // Copy the block to compact its size
            Block compactedBlock = block.copyRegion(0, block.getPositionCount());
            blocks.set(i, compactedBlock);
            pagesMemorySize -= block.getRetainedSizeInBytes();
            pagesMemorySize += compactedBlock.getRetainedSizeInBytes();
        }
    }
    nextBlockToCompact = channels[0].size();
    estimatedSize = calculateEstimatedSize();
}
 
Example 3
Source File: Page.java    From presto with Apache License 2.0 5 votes vote down vote up
private long updateRetainedSize()
{
    long retainedSizeInBytes = INSTANCE_SIZE + sizeOf(blocks);
    for (Block block : blocks) {
        retainedSizeInBytes += block.getRetainedSizeInBytes();
    }
    this.retainedSizeInBytes = retainedSizeInBytes;
    return retainedSizeInBytes;
}
 
Example 4
Source File: TestBlockBigArray.java    From presto with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: AbstractTestBlock.java    From presto with Apache License 2.0 4 votes vote down vote up
private void assertRetainedSize(Block block)
{
    long retainedSize = ClassLayout.parseClass(block.getClass()).instanceSize();
    Field[] fields = block.getClass().getDeclaredFields();
    try {
        for (Field field : fields) {
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            Class<?> type = field.getType();
            if (type.isPrimitive()) {
                continue;
            }

            field.setAccessible(true);

            if (type == Slice.class) {
                Slice slice = (Slice) field.get(block);
                if (slice != null) {
                    retainedSize += slice.getRetainedSize();
                }
            }
            else if (type == BlockBuilderStatus.class) {
                if (field.get(block) != null) {
                    retainedSize += BlockBuilderStatus.INSTANCE_SIZE;
                }
            }
            else if (type == BlockBuilder.class || type == Block.class) {
                retainedSize += ((Block) field.get(block)).getRetainedSizeInBytes();
            }
            else if (type == BlockBuilder[].class || type == Block[].class) {
                Block[] blocks = (Block[]) field.get(block);
                for (Block innerBlock : blocks) {
                    assertRetainedSize(innerBlock);
                    retainedSize += innerBlock.getRetainedSizeInBytes();
                }
            }
            else if (type == SliceOutput.class) {
                retainedSize += ((SliceOutput) field.get(block)).getRetainedSize();
            }
            else if (type == int[].class) {
                retainedSize += sizeOf((int[]) field.get(block));
            }
            else if (type == boolean[].class) {
                retainedSize += sizeOf((boolean[]) field.get(block));
            }
            else if (type == byte[].class) {
                retainedSize += sizeOf((byte[]) field.get(block));
            }
            else if (type == long[].class) {
                retainedSize += sizeOf((long[]) field.get(block));
            }
            else if (type == short[].class) {
                retainedSize += sizeOf((short[]) field.get(block));
            }
            else if (type == DictionaryId.class) {
                retainedSize += ClassLayout.parseClass(DictionaryId.class).instanceSize();
            }
            else if (type == MapHashTables.class) {
                retainedSize += ((MapHashTables) field.get(block)).getRetainedSizeInBytes();
            }
            else if (type == MethodHandle.class) {
                // MethodHandles are only used in MapBlock/MapBlockBuilder,
                // and they are shared among blocks created by the same MapType.
                // So we don't account for the memory held onto by MethodHandle instances.
                // Otherwise, we will be counting it multiple times.
            }
            else {
                throw new IllegalArgumentException(format("Unknown type encountered: %s", type));
            }
        }
    }
    catch (IllegalAccessException t) {
        throw new RuntimeException(t);
    }
    assertEquals(block.getRetainedSizeInBytes(), retainedSize);
}