Search in sources :

Example 11 with AlignedHeader

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

the class ThreadLocalAllocation method releaseMemory.

/**
 * Releases all the memory allocated in this TLAB, without any safety checks that the memory is
 * no longer referenced from other objects.
 */
public static void releaseMemory(Descriptor tlab) {
    log().string("[ThreadLocalAllocator.releaseMemory: tlab ").hex(tlab).newline();
    retireAllocationChunk(tlab);
    AlignedHeader alignedChunk = tlab.getAlignedChunk();
    UnalignedHeader unalignedChunk = tlab.getUnalignedChunk();
    tlab.setAlignedChunk(WordFactory.nullPointer());
    tlab.setUnalignedChunk(WordFactory.nullPointer());
    while (alignedChunk.isNonNull()) {
        AlignedHeader next = alignedChunk.getNext();
        /*
             * TODO: Should this do a full clean of the header, remembered set, and optionally zap
             * the contents, or just set the next pointer to null?
             */
        HeapChunkProvider.resetAlignedHeader(alignedChunk);
        log().string("  aligned chunk ").hex(alignedChunk).newline();
        // Put the chunk on a free list.
        pushToThreadLocalFreeList(alignedChunk);
        alignedChunk = next;
    }
    while (unalignedChunk.isNonNull()) {
        UnalignedHeader next = unalignedChunk.getNext();
        unalignedChunk.setNext(WordFactory.nullPointer());
        log().string("  unaligned chunk ").hex(alignedChunk).newline();
        HeapChunkProvider.get().consumeUnalignedChunk(unalignedChunk);
        unalignedChunk = next;
    }
    log().string("  ]").newline();
}
Also used : AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader) UnalignedHeader(com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)

Example 12 with AlignedHeader

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

the class HeapChunkProvider method popUnusedAlignedChunk.

/**
 * Pop a chunk from the global linked list of unused chunks. Returns {@code null} if the list is
 * empty.
 * <p>
 * This method uses compareAndSet to protect itself from races with competing pop operations,
 * but it is <em>not</em> safe with respect to competing pushes. Since pushes can happen during
 * garbage collections, I avoid the ABA problem by making the kernel of this method
 * uninterruptible so it can not be interrupted by a safepoint.
 *
 * Note the asymmetry with {@link #popUnusedAlignedChunk()}, which does not use a global free
 * list.
 */
private AlignedHeader popUnusedAlignedChunk() {
    log().string("  old list top: ").hex(unusedAlignedChunks.get()).string("  list bytes ").signed(bytesInUnusedAlignedChunks.get()).newline();
    AlignedHeader result = popUnusedAlignedChunkUninterruptibly();
    if (result.isNull()) {
        /* Unused list is empty. */
        return WordFactory.nullPointer();
    } else {
        /* Successfully popped an unused chunk from the list. */
        bytesInUnusedAlignedChunks.subtractAndGet(HeapPolicy.getAlignedHeapChunkSize());
        log().string("  new list top: ").hex(unusedAlignedChunks.get()).string("  list bytes ").signed(bytesInUnusedAlignedChunks.get()).newline();
        return result;
    }
}
Also used : AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)

Example 13 with AlignedHeader

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

the class HeapChunkProvider method produceAlignedChunk.

/**
 * Produce a new AlignedHeapChunk, either from the free list or from the operating system.
 */
AlignedHeader produceAlignedChunk() {
    UnsignedWord chunkSize = HeapPolicy.getAlignedHeapChunkSize();
    log().string("[HeapChunkProvider.produceAlignedChunk  chunk size: ").unsigned(chunkSize).newline();
    AlignedHeader result = popUnusedAlignedChunk();
    log().string("  unused chunk: ").hex(result).newline();
    if (result.isNull()) {
        /* Unused list was empty, need to allocate memory. */
        noteFirstAllocationTime();
        result = (AlignedHeader) ConfigurationValues.getOSInterface().allocateVirtualMemoryAligned(chunkSize, HeapPolicy.getAlignedHeapChunkAlignment());
        if (result.isNull()) {
            throw AllocatorOutOfMemoryError.throwError("No virtual memory for aligned chunk");
        }
        log().string("  new chunk: ").hex(result).newline();
        initializeChunk(result, chunkSize);
        resetAlignedHeapChunk(result);
    }
    assert result.getTop().equal(AlignedHeapChunk.getAlignedHeapChunkStart(result));
    assert result.getEnd().equal(HeapChunk.asPointer(result).add(chunkSize));
    if (HeapPolicy.getZapProducedHeapChunks()) {
        zap(result, HeapPolicy.getProducedHeapChunkZapValue());
    }
    HeapPolicy.bytesAllocatedSinceLastCollection.addAndGet(chunkSize);
    log().string("  result chunk: ").hex(result).string("  ]").newline();
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) AlignedHeader(com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)

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