Search in sources :

Example 16 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread 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 17 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class StackVerifier method verifyInAllThreads.

public boolean verifyInAllThreads(Pointer currentSp, CodePointer currentIp, String message) {
    final Log trace = getTraceLog();
    trace.string("[StackVerifier.verifyInAllThreads:").string(message).newline();
    // Flush thread-local allocation data.
    ThreadLocalAllocation.disableThreadLocalAllocation();
    trace.string("Current thread ").hex(CEntryPointContext.getCurrentIsolateThread()).string(": [").newline();
    if (!JavaStackWalker.walkCurrentThread(currentSp, currentIp, stackFrameVisitor)) {
        return false;
    }
    trace.string("]").newline();
    if (SubstrateOptions.MultiThreaded.getValue()) {
        for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
            if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
                continue;
            }
            trace.string("Thread ").hex(vmThread).string(": [").newline();
            if (!JavaStackWalker.walkThread(vmThread, stackFrameVisitor)) {
                return false;
            }
            trace.string("]").newline();
        }
    }
    trace.string("]").newline();
    return true;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Log(com.oracle.svm.core.log.Log)

Example 18 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class PinnedAllocatorImpl method close.

@Override
public void close() {
    log().string("[PinnedAllocatorImpl.close: ").object(this).newline();
    ensureOpen();
    /* Capture "this", the tlab and the VMThread for the VMOperation. */
    final PinnedAllocatorImpl pinnedAllocatorImpl = this;
    final ThreadLocalAllocation.Descriptor tlab = ThreadLocalAllocation.pinnedTLAB.getAddress();
    final IsolateThread requestingVMThread = CEntryPointContext.getCurrentIsolateThread();
    VMOperation.enqueueBlockingSafepoint("PinnedAllocatorImpl.close", () -> {
        ThreadLocalAllocation.retireToSpace(tlab, HeapImpl.getHeapImpl().getOldGeneration().getPinnedFromSpace());
        assert ThreadLocalAllocation.verifyUninitialized(tlab);
        /* Now our TLAB is clean, so we can change the phase. */
        openPinnedAllocator.set(requestingVMThread, null);
        pinnedAllocatorImpl.phase = LifeCyclePhase.CLOSED;
    });
    assert phase == LifeCyclePhase.CLOSED : "PinnedAllocatorImpl.close: VMOperation failed to close.";
    log().string("  ]").newline();
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread)

Example 19 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class Deoptimizer method deoptimizeInRangeOperation.

/**
 * Deoptimize a specific method on all thread stacks.
 */
private static void deoptimizeInRangeOperation(CodePointer fromIp, CodePointer toIp, boolean deoptAll) {
    VMOperation.guaranteeInProgress("Deoptimizer.deoptimizeInRangeOperation, but not in VMOperation.");
    /* Handle my own thread specially, because I do not have a JavaFrameAnchor. */
    StackFrameVisitor currentThreadDeoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, CEntryPointContext.getCurrentIsolateThread());
    Pointer sp = KnownIntrinsics.readCallerStackPointer();
    CodePointer ip = KnownIntrinsics.readReturnAddress();
    JavaStackWalker.walkCurrentThread(sp, ip, currentThreadDeoptVisitor);
    /* If I am multi-threaded, deoptimize this method on all the other stacks. */
    if (SubstrateOptions.MultiThreaded.getValue()) {
        for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
            if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
                continue;
            }
            StackFrameVisitor deoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, vmThread);
            JavaStackWalker.walkThread(vmThread, deoptVisitor);
        }
    }
    if (testGCinDeoptimizer) {
        Heap.getHeap().getGC().collect("from Deoptimizer.deoptimizeInRange because of testGCinDeoptimizer");
    }
}
Also used : StackFrameVisitor(com.oracle.svm.core.stack.StackFrameVisitor) IsolateThread(org.graalvm.nativeimage.IsolateThread) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer)

Example 20 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class CInterfaceTutorial method dump.

protected static void dump(MyData data) {
    System.out.format("**** In Java ****\n");
    System.out.format("primitive: %d\n", data.getPrimitive());
    System.out.format("length: %d\n", getDataLength());
    for (int i = 0; i < getDataLength(); i++) {
        System.out.format("%d ", data.addressOfArray().read(i));
    }
    System.out.format("\n");
    IsolateThread currentThread = CEntryPointContext.getCurrentIsolateThread();
    /* Call a C function directly. */
    printingInC(currentThread, data.getCString());
    /* Call a C function indirectly via function pointer. */
    data.getPrintFunction().invoke(currentThread, data.getCString());
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

IsolateThread (org.graalvm.nativeimage.IsolateThread)20 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)5 Log (com.oracle.svm.core.log.Log)3 Safepoint (com.oracle.svm.core.thread.Safepoint)3 NeverInline (com.oracle.svm.core.annotate.NeverInline)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)2 Pointer (org.graalvm.word.Pointer)2 RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)1 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)1 StackFrameVisitor (com.oracle.svm.core.stack.StackFrameVisitor)1 HashMap (java.util.HashMap)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1