Search in sources :

Example 1 with CodePointer

use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.

the class SnippetRuntime method deoptimize.

/**
 * Foreign call: {@link #DEOPTIMIZE}.
 */
@SubstrateForeignCallTarget
private static void deoptimize(long actionAndReason, SpeculationReason speculation) {
    Pointer sp = KnownIntrinsics.readCallerStackPointer();
    DeoptimizationAction action = Deoptimizer.decodeDeoptAction(actionAndReason);
    if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
        Log log = Log.log().string("[Deoptimization initiated").newline();
        CodePointer ip = KnownIntrinsics.readReturnAddress();
        SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(ip);
        if (installedCode != null) {
            log.string("    name: ").string(installedCode.getName()).newline();
        }
        log.string("    sp: ").hex(sp).string("  ip: ").hex(ip).newline();
        DeoptimizationReason reason = Deoptimizer.decodeDeoptReason(actionAndReason);
        log.string("    reason: ").string(reason.toString()).string("  action: ").string(action.toString()).newline();
        int debugId = Deoptimizer.decodeDebugId(actionAndReason);
        log.string("    debugId: ").signed(debugId).string("  speculation: ").string(Objects.toString(speculation)).newline();
        CodeInfoQueryResult info = CodeInfoTable.lookupCodeInfoQueryResult(ip);
        if (info != null) {
            NodeSourcePosition sourcePosition = DeoptimizationSourcePositionDecoder.decode(debugId, info);
            if (sourcePosition != null) {
                log.string("    stack trace that triggered deoptimization:").newline();
                NodeSourcePosition cur = sourcePosition;
                while (cur != null) {
                    log.string("        at ");
                    if (cur.getMethod() != null) {
                        StackTraceElement element = cur.getMethod().asStackTraceElement(cur.getBCI());
                        if (element.getFileName() != null && element.getLineNumber() >= 0) {
                            log.string(element.toString());
                        } else {
                            log.string(cur.getMethod().format("%H.%n(%p)")).string(" bci ").signed(cur.getBCI());
                        }
                    } else {
                        log.string("[unknown method]");
                    }
                    log.newline();
                    cur = cur.getCaller();
                }
            }
        }
    }
    if (action.doesInvalidateCompilation()) {
        Deoptimizer.invalidateMethodOfFrame(sp, speculation);
    } else {
        Deoptimizer.deoptimizeFrame(sp, false, speculation);
    }
    if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
        Log.log().string("]").newline();
    }
}
Also used : Log(com.oracle.svm.core.log.Log) SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodeInfoQueryResult(com.oracle.svm.core.code.CodeInfoQueryResult) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 2 with CodePointer

use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.

the class JavaStackWalker method walkThread.

@AlwaysInline("avoid virtual call to visitor")
public static boolean walkThread(IsolateThread thread, StackFrameVisitor visitor) {
    JavaFrameAnchor anchor = JavaFrameAnchors.getFrameAnchor(thread);
    Pointer sp = WordFactory.nullPointer();
    CodePointer ip = WordFactory.nullPointer();
    if (anchor.isNonNull()) {
        sp = anchor.getLastJavaSP();
        ip = FrameAccess.readReturnAddress(sp);
    }
    // always call doWalk() to invoke visitor's methods
    return doWalk(anchor, sp, ip, visitor);
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 3 with CodePointer

use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.

the class Deoptimizer method invalidateMethodOfFrame.

/**
 * Invalidates the {@link InstalledCode} of the method of the given frame. The method must be a
 * runtime compiled method, since there is not {@link InstalledCode} for native image methods.
 */
public static void invalidateMethodOfFrame(Pointer sourceSp, SpeculationReason speculation) {
    CodePointer returnAddress = FrameAccess.readReturnAddress(sourceSp);
    SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(returnAddress);
    /*
         * We look up the installedCode before checking if the frame is deoptimized to avoid race
         * conditions. We are not in a VMOperation here. When a deoptimization happens, e.g., at a
         * safepoint taken at the method exit of checkDeoptimized, then the result value
         * deoptimizedFrame will be null but the return address is already patched to the deoptStub.
         * We would not be able to find the installedCode in such a case. Invalidating the same
         * installedCode multiple times in case of a race is not a problem because the actual
         * invalidation is in a VMOperation.
         */
    DeoptimizedFrame deoptimizedFrame = checkDeoptimized(sourceSp);
    if (deoptimizedFrame != null) {
        installedCode = deoptimizedFrame.getSourceInstalledCode();
        if (installedCode == null) {
            /* When the method was invalidated before, all the metadata can be gone by now. */
            return;
        }
    } else {
        if (installedCode == null) {
            CodeInfoTable.getRuntimeCodeCache().logTable();
            throw VMError.shouldNotReachHere("Only runtime compiled methods can be invalidated. sp = " + Long.toHexString(sourceSp.rawValue()) + ", returnAddress = " + Long.toHexString(returnAddress.rawValue()));
        }
    }
    registerSpeculationFailure(installedCode, speculation);
    VMOperation.guaranteeNotInProgress("invalidateMethodOfFrame: running user code that can block");
    installedCode.invalidate();
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer)

Example 4 with CodePointer

use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.

the class JavaLangSubstitutions method fillInStackTrace.

@Substitute
@NeverInline("Prevent inlining in Truffle compilations")
private Object fillInStackTrace() {
    Pointer sp = KnownIntrinsics.readCallerStackPointer();
    CodePointer ip = KnownIntrinsics.readReturnAddress();
    StackTraceBuilder stackTraceBuilder = new StackTraceBuilder();
    JavaStackWalker.walkCurrentThread(sp, ip, stackTraceBuilder);
    this.stackTrace = stackTraceBuilder.getTrace();
    return this;
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) NeverInline(com.oracle.svm.core.annotate.NeverInline) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 5 with CodePointer

use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.

the class JavaStackWalker method doWalk.

@AlwaysInline("avoid virtual call to visitor")
private static boolean doWalk(JavaFrameAnchor lastAnchor, Pointer startSP, CodePointer startIP, StackFrameVisitor visitor) {
    if (!visitor.prologue()) {
        return false;
    }
    if (startSP.isNonNull() && startIP.isNonNull()) {
        JavaFrameAnchor anchor = lastAnchor;
        Pointer sp = startSP;
        CodePointer ip = startIP;
        while (true) {
            while (anchor.isNonNull() && anchor.getLastJavaSP().belowOrEqual(sp)) {
                /* Skip anchors that are in parts of the stack we are not traversing. */
                anchor = anchor.getPreviousAnchor();
            }
            long totalFrameSize;
            DeoptimizedFrame deoptFrame = Deoptimizer.checkDeoptimized(sp);
            if (deoptFrame != null) {
                totalFrameSize = deoptFrame.getSourceTotalFrameSize();
            } else {
                totalFrameSize = CodeInfoTable.lookupTotalFrameSize(ip);
            }
            if (totalFrameSize != -1) {
                /* This is a Java frame, visit it. */
                if (!visitor.visitFrame(sp, ip, deoptFrame)) {
                    return false;
                }
                /* Bump sp *up* over my frame. */
                sp = sp.add(WordFactory.unsigned(totalFrameSize));
                /* Read the return address to my caller. */
                ip = FrameAccess.readReturnAddress(sp);
            } else if (anchor.isNonNull()) {
                /*
                     * At the end of a block of Java frames, but we have more Java frames after a
                     * block of C frames.
                     */
                assert anchor.getLastJavaSP().aboveThan(sp);
                sp = anchor.getLastJavaSP();
                ip = FrameAccess.readReturnAddress(sp);
                anchor = anchor.getPreviousAnchor();
            } else {
                /* Really at the end of the stack, we are done with walking. */
                break;
            }
        }
    } else {
    /*
             * It is fine for a thread to have no Java frames, for example in the case of a native
             * thread that was attached via JNI, but is currently not executing any Java code.
             */
    }
    return visitor.epilogue();
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizedFrame(com.oracle.svm.core.deopt.DeoptimizedFrame) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Aggregations

CodePointer (org.graalvm.nativeimage.c.function.CodePointer)14 Pointer (org.graalvm.word.Pointer)11 NeverInline (com.oracle.svm.core.annotate.NeverInline)4 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)3 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)2 CodeInfoQueryResult (com.oracle.svm.core.code.CodeInfoQueryResult)2 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 Log (com.oracle.svm.core.log.Log)2 IsolateThread (org.graalvm.nativeimage.IsolateThread)2 Substitute (com.oracle.svm.core.annotate.Substitute)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 SubstrateInstalledCode (com.oracle.svm.core.deopt.SubstrateInstalledCode)1 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)1 JavaFrameAnchor (com.oracle.svm.core.stack.JavaFrameAnchor)1 StackFrameVisitor (com.oracle.svm.core.stack.StackFrameVisitor)1 StackIntrospection (jdk.vm.ci.code.stack.StackIntrospection)1 DeoptimizationAction (jdk.vm.ci.meta.DeoptimizationAction)1 DeoptimizationReason (jdk.vm.ci.meta.DeoptimizationReason)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1 NodeSourcePosition (org.graalvm.compiler.graph.NodeSourcePosition)1