Search in sources :

Example 6 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class PolyglotNativeAPI method polyglot_get_callback_info.

@CEntryPoint(name = "polyglot_get_callback_info")
public static PolyglotStatus polyglot_get_callback_info(IsolateThread isolate_thread, PolyglotCallbackInfo callback_info, SizeTPointer argc, PolyglotValuePointerPointer argv, WordPointer data) {
    return withHandledErrors(() -> {
        PolyglotCallbackInfoInternal callbackInfo = fetchHandle(callback_info);
        UnsignedWord numberOfArguments = WordFactory.unsigned(callbackInfo.arguments.length);
        UnsignedWord bufferSize = argc.read();
        UnsignedWord size = bufferSize.belowThan(numberOfArguments) ? bufferSize : numberOfArguments;
        argc.write(size);
        for (UnsignedWord i = WordFactory.zero(); i.belowThan(size); i = i.add(1)) {
            int index = (int) i.rawValue();
            ObjectHandle argument = callbackInfo.arguments[index];
            argv.write(index, argument);
        }
        data.write(callbackInfo.data);
    });
}
Also used : ObjectHandle(org.graalvm.nativeimage.ObjectHandle) UnsignedWord(org.graalvm.word.UnsignedWord) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 7 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class Space method getUnalignedObjectBytes.

/**
 * Aggregate the bytes in Object in unaligned chunks.
 */
private UnsignedWord getUnalignedObjectBytes() {
    UnsignedWord result = WordFactory.zero();
    UnalignedHeapChunk.UnalignedHeader uChunk = getFirstUnalignedHeapChunk();
    while (uChunk.isNonNull()) {
        final UnsignedWord allocatedBytes = uChunk.getTop().subtract(UnalignedHeapChunk.getObjectStart(uChunk));
        result = result.add(allocatedBytes);
        uChunk = uChunk.getNext();
    }
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 8 with UnsignedWord

use of org.graalvm.word.UnsignedWord 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 9 with UnsignedWord

use of org.graalvm.word.UnsignedWord 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)

Example 10 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class UnalignedHeapChunkMemoryWalkerAccessFeature method dirtyCardForObjectOfUnalignedHeapChunk.

/**
 * Dirty the card corresponding to the given Object.
 *
 * This has to be fast, because it is used by the post-write barrier.
 */
public static void dirtyCardForObjectOfUnalignedHeapChunk(Object obj) {
    final UnalignedHeader chunk = getEnclosingUnalignedHeapChunk(obj);
    final Pointer rememberedSetStart = getCardTableStart(chunk);
    final UnsignedWord objectIndex = getObjectIndex();
    CardTable.dirtyEntryAtIndex(rememberedSetStart, objectIndex);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Aggregations

UnsignedWord (org.graalvm.word.UnsignedWord)137 Pointer (org.graalvm.word.Pointer)43 Log (com.oracle.svm.core.log.Log)30 DynamicHub (com.oracle.svm.core.hub.DynamicHub)11 Fold (org.graalvm.compiler.api.replacements.Fold)11 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)9 Snippet (org.graalvm.compiler.api.replacements.Snippet)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)6 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)4 WordBase (org.graalvm.word.WordBase)4 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)3 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 UnalignedHeader (com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)3 XOptions (com.oracle.svm.core.option.XOptions)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)2 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaKind (jdk.vm.ci.meta.JavaKind)2