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

The following examples show how to use io.prestosql.spi.block.Block#retainedBytesForEachPart() . 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: PageProcessor.java    From presto with Apache License 2.0 5 votes vote down vote up
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);
        // TODO: block might be partially loaded
        if (block.isLoaded()) {
            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);
}
 
Example 2
Source File: BlockBigArray.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the element of this big array at specified index.
 *
 * @param index a position in this big array.
 */
public void set(long index, Block value)
{
    Block currentValue = array.get(index);
    if (currentValue != null) {
        currentValue.retainedBytesForEachPart((object, size) -> {
            if (currentValue == object) {
                // track instance size separately as the reference count for an instance is always 1
                sizeOfBlocks -= size;
                return;
            }
            if (trackedObjects.decrementAndGet(object) == 0) {
                // decrement the size only when it is the last reference
                sizeOfBlocks -= size;
            }
        });
    }
    if (value != null) {
        value.retainedBytesForEachPart((object, size) -> {
            if (value == object) {
                // track instance size separately as the reference count for an instance is always 1
                sizeOfBlocks += size;
                return;
            }
            if (trackedObjects.incrementAndGet(object) == 1) {
                // increment the size only when it is the first reference
                sizeOfBlocks += size;
            }
        });
    }
    array.set(index, value);
}