Search in sources :

Example 1 with AlignedHeader

use of com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader in project graal by oracle.

the class ThreadLocalAllocation method allocateNewInstance.

static Object allocateNewInstance(DynamicHub hub, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet) {
    DeoptTester.disableDeoptTesting();
    log().string("[ThreadLocalAllocation.allocateNewInstance: ").string(hub.asClass().getName()).string(" in tlab ").hex(tlab).newline();
    // Slow-path check if allocation is disallowed.
    HeapImpl.exitIfAllocationDisallowed("ThreadLocalAllocation.allocateNewInstance", hub.asClass().getName());
    // Policy: Possibly collect before this allocation.
    HeapImpl.getHeapImpl().getHeapPolicy().getCollectOnAllocationPolicy().maybeCauseCollection();
    /*
         * On this path allocation failed in the 'allocation chunk', thus we refill it, i.e.., add a
         * new allocation chunk at the front of the TLAB's aligned chunks.
         */
    AlignedHeader newChunk = prepareNewAllocationChunk(tlab);
    UnsignedWord size = LayoutEncoding.getInstanceSize(hub.getLayoutEncoding());
    Object result = allocateNewInstanceUninterruptibly(hub, tlab, rememberedSet, size, newChunk);
    log().string("  ThreadLocalAllocation.allocateNewInstance returns ").object(result).string(" .. ").hex(LayoutEncoding.getObjectEnd(result)).string("]").newline();
    DeoptTester.enableDeoptTesting();
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)

Example 2 with AlignedHeader

use of com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader in project graal by oracle.

the class ThreadLocalAllocation method resumeAllocationChunk.

/**
 * Add a new allocation chunk at the front of the TLAB's aligned chunks.
 */
@Uninterruptible(reason = "Modifies TLAB.")
static void resumeAllocationChunk(Descriptor tlab) {
    assert tlab.getAllocationTop(TOP_IDENTITY).isNull();
    assert tlab.getAllocationTop(END_IDENTITY).isNull();
    AlignedHeader alignedChunk = tlab.getAlignedChunk();
    if (alignedChunk.isNonNull()) {
        tlab.setAllocationTop(alignedChunk.getTop(), TOP_IDENTITY);
        tlab.setAllocationEnd(alignedChunk.getEnd(), END_IDENTITY);
        alignedChunk.setTop(WordFactory.nullPointer());
    }
}
Also used : AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 3 with AlignedHeader

use of com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader in project graal by oracle.

the class ThreadLocalAllocation method retireAllocationChunk.

/**
 * Retire the current allocation chunk of current TLAB.
 */
@Uninterruptible(reason = "Modifies TLAB")
private static void retireAllocationChunk(Descriptor tlab) {
    Pointer allocationTop = tlab.getAllocationTop(TOP_IDENTITY);
    if (allocationTop.isNonNull()) {
        AlignedHeader alignedChunk = tlab.getAlignedChunk();
        assert alignedChunk.getTop().isNull();
        assert alignedChunk.getEnd().equal(tlab.getAllocationEnd(END_IDENTITY));
        /*
             * While the aligned chunk is the allocation chunk its top value is always 'null' and it
             * doesn't reflect the upper limit of allocated memory. The 'top' is stored in the TLAB
             * and only set in the top aligned chunk when it is retired.
             */
        alignedChunk.setTop(allocationTop);
        tlab.setAllocationTop(WordFactory.nullPointer(), TOP_IDENTITY);
        tlab.setAllocationEnd(WordFactory.nullPointer(), END_IDENTITY);
    }
}
Also used : AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 4 with AlignedHeader

use of com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader in project graal by oracle.

the class ThreadLocalAllocation method popFromThreadLocalFreeList.

/**
 * Pop an aligned chunk from the thread-local list of free chunks, or null if the list is empty.
 */
@Uninterruptible(reason = "Pops from the free list that is drained, at a safepoint, by garbage collections.")
private static AlignedHeader popFromThreadLocalFreeList() {
    final AlignedHeader result = freeList.get();
    if (result.isNonNull()) {
        final AlignedHeader next = result.getNext();
        result.setNext(WordFactory.nullPointer());
        freeList.set(next);
    }
    return result;
}
Also used : AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 5 with AlignedHeader

use of com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader in project graal by oracle.

the class ThreadLocalAllocation method getObjectBytes.

/**
 * Returns the total memory used by the TLAB in bytes. It counts only the memory actually used,
 * not the total committed memory.
 */
public static UnsignedWord getObjectBytes(Descriptor tlab) {
    Log log = log();
    log.newline();
    log.string("[ThreadLocalAllocator.usedMemory: tlab ").hex(tlab).newline();
    AlignedHeader aChunk = tlab.getAlignedChunk();
    UnsignedWord alignedUsedMemory = WordFactory.zero();
    while (aChunk.isNonNull()) {
        AlignedHeader next = aChunk.getNext();
        Pointer start = AlignedHeapChunk.getAlignedHeapChunkStart(aChunk);
        /* The allocation top has a null top; the TLAB is the one advancing the top pointer. */
        Pointer top = aChunk.getTop().isNull() ? tlab.getAllocationTop(TOP_IDENTITY) : aChunk.getTop();
        UnsignedWord aChunkUsedMemory = top.subtract(start);
        alignedUsedMemory = alignedUsedMemory.add(aChunkUsedMemory);
        log.string("     aligned chunk: ").hex(aChunk).string(" | used memory: ").unsigned(aChunkUsedMemory).newline();
        aChunk = next;
    }
    UnsignedWord unalignedUsedMemory = WordFactory.zero();
    UnalignedHeader uChunk = tlab.getUnalignedChunk();
    while (uChunk.isNonNull()) {
        UnalignedHeader next = uChunk.getNext();
        UnsignedWord uChunkUsedMemory = UnalignedHeapChunk.usedObjectMemoryOfUnalignedHeapChunk(uChunk);
        unalignedUsedMemory = unalignedUsedMemory.add(uChunkUsedMemory);
        log.string("     unaligned chunk ").hex(uChunk).string(" | used memory: ").unsigned(uChunkUsedMemory).newline();
        uChunk = next;
    }
    UnsignedWord tlabUsedMemory = alignedUsedMemory.add(unalignedUsedMemory);
    log.newline();
    log.string("  aligned used memory: ").unsigned(alignedUsedMemory).newline();
    log.string("  unaligned used memory: ").unsigned(unalignedUsedMemory).newline();
    log.string("  TLAB used memory: ").unsigned(tlabUsedMemory).newline();
    log.string("  ]").newline();
    return tlabUsedMemory;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader) UnalignedHeader(com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader) Pointer(org.graalvm.word.Pointer)

Aggregations

AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)13 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)4 UnalignedHeader (com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)4 UnsignedWord (org.graalvm.word.UnsignedWord)4 Pointer (org.graalvm.word.Pointer)2 Log (com.oracle.svm.core.log.Log)1