Search in sources :

Example 76 with Pointer

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

the class FirstObjectTable method verify.

/**
 * Verify a FirstObjectTable.
 */
protected static boolean verify(Pointer tableStart, Pointer memoryStart, Pointer memoryLimit) {
    /*
         * Walk the table checking that I can find the start of the object that crosses onto this
         * entry.
         */
    final Log trace = HeapImpl.getHeapImpl().getHeapVerifierImpl().getTraceLog().string("[FirstObjectTable.verify:");
    trace.string("  tableStart: ").hex(tableStart).string("  memoryStart: ").hex(memoryStart).string("  memoryLimit: ").hex(memoryLimit);
    final UnsignedWord indexLimit = getTableSizeForMemoryPointers(memoryStart, memoryLimit);
    for (UnsignedWord index = WordFactory.unsigned(0); index.belowThan(indexLimit); index = index.add(1)) {
        trace.newline().string("  FirstObjectTable.verify: index: ").unsigned(index).newline();
        final Pointer objStart = getPreciseFirstObjectPointer(tableStart, memoryStart, memoryLimit, index);
        trace.string("  objStart: ").hex(objStart).newline();
        if (objStart.belowThan(memoryStart)) {
            /* Map points below memory. */
            trace.string("  FirstObjectTable.verify: objStart.belowThan(memoryStart) => false]").newline();
            return false;
        }
        if (memoryLimit.belowOrEqual(objStart)) {
            /* Map points above memory. */
            trace.string("  FirstObjectTable.verify: memoryLimit.belowOrEqual(objStart) => false]").newline();
            return false;
        }
        if (!HeapImpl.getHeapImpl().getHeapVerifierImpl().verifyObjectAt(objStart)) {
            /* Bad object. */
            final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
            witness.string("  tableStart: ").hex(tableStart).string("  memoryStart: ").hex(memoryStart).string("  memoryLimit: ").hex(memoryLimit);
            witness.string("  objStart: ").hex(objStart).string("  fails to verify").string("]").newline();
            return false;
        }
        /* Check that the object crosses onto this entry. */
        /*
             * - Things are okay if ((objStart <= entryStart) && (entryStart < objEnd)) so I need to
             * return false if either of those conditions is false
             */
        final Pointer entryStart = memoryStart.add(indexToMemoryOffset(index));
        trace.string("  entryStart: ").hex(entryStart);
        if (!(objStart.belowOrEqual(entryStart))) {
            /* Object doesn't start before this entry. */
            final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
            witness.string("  tableStart: ").hex(tableStart).string("  memoryStart: ").hex(memoryStart).string("  memoryLimit: ").hex(memoryLimit);
            witness.string("  objStart: ").hex(objStart).string("  entryStart: ").hex(entryStart).string("  !(objStart.belowOrEqual(entryStart))").string("]").newline();
            return false;
        }
        final Object obj = objStart.toObject();
        final Pointer objEnd = LayoutEncoding.getObjectEnd(obj);
        trace.string("  ");
        trace.string(obj.getClass().getName());
        trace.string("  objEnd: ").hex(objEnd);
        if (!(entryStart.belowThan(objEnd))) {
            /* Object doesn't continue onto this entry. */
            final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
            witness.string("  tableStart: ").hex(tableStart).string("  memoryStart: ").hex(memoryStart).string("  memoryLimit: ").hex(memoryLimit);
            witness.string("  objEnd: ").hex(objEnd).string("  entryStart: ").hex(entryStart).string("  !(entryStart.belowThan(objEnd))").string("]").newline();
            return false;
        }
    }
    trace.string("  => true]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 77 with Pointer

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

the class GarbageCollectorManagementFactory method blackenStackRoots.

@SuppressWarnings("try")
private void blackenStackRoots() {
    final Log trace = Log.noopLog().string("[GCImpl.blackenStackRoots:").newline();
    try (Timer bsr = blackenStackRootsTimer.open()) {
        Pointer sp = readCallerStackPointer();
        trace.string("[blackenStackRoots:").string("  sp: ").hex(sp);
        CodePointer ip = readReturnAddress();
        trace.string("  ip: ").hex(ip).newline();
        JavaStackWalker.walkCurrentThread(sp, ip, frameWalker);
        if (SubstrateOptions.MultiThreaded.getValue()) {
            /*
                 * Scan the stacks of all the threads. Other threads will be blocked at a safepoint
                 * (or in native code) so they will each have a JavaFrameAnchor in their VMThread.
                 */
            for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
                if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
                    /*
                         * The current thread is already scanned by code above, so we do not have to
                         * do anything for it here. It might have a JavaFrameAnchor from earlier
                         * Java-to-C transitions, but certainly not at the top of the stack since it
                         * is running this code, so just this scan would be incomplete.
                         */
                    continue;
                }
                JavaStackWalker.walkThread(vmThread, frameWalker);
                trace.newline();
            }
        }
        trace.string("]").newline();
    }
    trace.string("]").newline();
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Log(com.oracle.svm.core.log.Log) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) KnownIntrinsics.readCallerStackPointer(com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer)

Example 78 with Pointer

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

the class Space method copyAlignedObject.

/**
 * Copy an Object into the given memory.
 */
private Object copyAlignedObject(Object originalObj) {
    VMOperation.guaranteeInProgress("Should only be called from the collector.");
    assert ObjectHeaderImpl.getObjectHeaderImpl().isAlignedObject(originalObj);
    final Log trace = Log.noopLog().string("[SpaceImpl.copyAlignedObject:");
    trace.string("  originalObj: ").object(originalObj);
    /* ObjectAccess.writeWord needs an Object as a 0th argument. */
    /* - Allocate memory for the copy in this Space. */
    final UnsignedWord copySize = LayoutEncoding.getSizeFromObject(originalObj);
    trace.string("  copySize: ").unsigned(copySize);
    final Pointer copyMemory = allocateMemory(copySize);
    trace.string("  copyMemory: ").hex(copyMemory);
    if (copyMemory.isNull()) {
        /* TODO: Promotion failure! */
        final Log failureLog = Log.log().string("[!SpaceImpl.copyAlignedObject:");
        failureLog.string("  failure to allocate ").unsigned(copySize).string(" bytes").string("!]").newline();
        return null;
    }
    /* - Copy the Object. */
    final Pointer originalMemory = Word.objectToUntrackedPointer(originalObj);
    UnsignedWord offset = WordFactory.zero();
    while (offset.belowThan(copySize)) {
        /*
             * This copies words, without regard to whether they are pointers and so need to dirty
             * remembered sets, etc. That's okay, because when the dust settles, anything the copy
             * references will be in the old Space, so any card remembered sets for the object can
             * be "clean". This writes the hub from the original over the hub installed by the
             * allocateArray or allocateObject. That shouldn't be an issue, here.
             */
        copyMemory.writeWord(offset, originalMemory.readWord(offset));
        offset = offset.add(ConfigurationValues.getTarget().wordSize);
    }
    final Object copyObj = copyMemory.toObject();
    /* Note that the object needs a remembered set. */
    setAlignedRememberedSet(copyObj);
    trace.string("  copyObj: ").object(copyObj).string("]").newline();
    return copyObj;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 79 with Pointer

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

the class ThreadLocalAllocation method allocateMemory.

/**
 * The implementation of the AllocationSnippets.fastAllocateImpl(Unsigned).
 * <p>
 * This is bump-pointer allocation for the young generation, using a cached "top" and "end".
 * <p>
 * Since this is called from a snippet, it and all the methods it calls, must be able to be
 * inlined. The easy way to do that is to make this method, and all the methods it calls, final
 * or static.
 * <p>
 * This allocates *memory*, not an Object. The rest of the allocation path takes care of turning
 * the memory into an Object.
 * <p>
 * See also
 * {@linkplain AlignedHeapChunk#allocateMemory(AlignedHeapChunk.AlignedHeader, UnsignedWord)}.
 */
@Uninterruptible(reason = "returns uninitialized memory, modifies TLAB", callerMustBe = true)
public static Pointer allocateMemory(Descriptor allocator, UnsignedWord size) {
    Pointer top = KnownIntrinsics.nonNullPointer(allocator.getAllocationTop(TOP_IDENTITY));
    Pointer end = KnownIntrinsics.nonNullPointer(allocator.getAllocationEnd(END_IDENTITY));
    UnsignedWord available = end.subtract(top);
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, size.belowOrEqual(available))) {
        allocator.setAllocationTop(top.add(size), TOP_IDENTITY);
        return top;
    } else {
        return WordFactory.nullPointer();
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 80 with Pointer

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

the class UnalignedHeapChunkMemoryWalkerAccessFeature method allocateMemory.

/*
     * Methods on UnalignedHeapChunk.
     */
/**
 * Allocate memory within this AlignedHeapChunk. No initialization of the memory happens here.
 */
@Uninterruptible(reason = "Returns uninitialized memory.", callerMustBe = true)
public static Pointer allocateMemory(UnalignedHeader that, UnsignedWord size) {
    final UnsignedWord available = availableObjectMemory(that);
    // Is memory available for the requested size?
    Pointer result = WordFactory.nullPointer();
    if (size.belowOrEqual(available)) {
        // Returned memory is at the start,
        result = that.getTop();
        final Pointer newTop = result.add(size);
        setTopCarefully(that, newTop);
    }
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Aggregations

Pointer (org.graalvm.word.Pointer)103 UnsignedWord (org.graalvm.word.UnsignedWord)45 Log (com.oracle.svm.core.log.Log)30 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)17 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)15 Snippet (org.graalvm.compiler.api.replacements.Snippet)14 Word (org.graalvm.compiler.word.Word)12 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)9 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)7 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)5 NeverInline (com.oracle.svm.core.annotate.NeverInline)5 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3 SignedWord (org.graalvm.word.SignedWord)3 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2