Search in sources :

Example 1 with SharedMethod

use of com.oracle.svm.core.meta.SharedMethod in project graal by oracle.

the class RemoveUnwindPhase method run.

@Override
protected void run(StructuredGraph graph) {
    SharedMethod method = (SharedMethod) graph.method();
    if (method.isDeoptTarget()) {
        /*
             * Deoptimization targets need need to have an exception entry point for every invoke.
             * This decouples deoptimization from exception handling: the exception handling
             * mechanism can just deliver an exception to a deoptimized method without any checks.
             */
        return;
    }
    List<InvokeWithExceptionNode> invocations = new ArrayList<>();
    for (UnwindNode node : graph.getNodes().filter(UnwindNode.class)) {
        walkBack(node.predecessor(), node, invocations);
    }
    /*
         * Modify graph only after all suitable invocations are found, to avoid problems with
         * deleted nodes during graph traversal.
         */
    for (InvokeWithExceptionNode node : invocations) {
        InvokeNode replacement = node.graph().add(new InvokeNode(node.callTarget(), node.bci(), node.stamp(NodeView.DEFAULT)));
        replacement.setStateAfter(node.stateAfter());
        node.killExceptionEdge();
        node.graph().replaceSplit(node, replacement, node.next());
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ArrayList(java.util.ArrayList) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) SharedMethod(com.oracle.svm.core.meta.SharedMethod) UnwindNode(org.graalvm.compiler.nodes.UnwindNode)

Example 2 with SharedMethod

use of com.oracle.svm.core.meta.SharedMethod in project graal by oracle.

the class Deoptimizer method printDeoptimizedFrame.

private static void printDeoptimizedFrame(Log log, Pointer sp, DeoptimizedFrame deoptimizedFrame, FrameInfoQueryResult sourceFrameInfo) {
    log.string("[Deoptimization of frame").newline();
    SubstrateInstalledCode installedCode = deoptimizedFrame.getSourceInstalledCode();
    if (installedCode != null) {
        log.string("    name: ").string(installedCode.getName()).newline();
    }
    log.string("    sp: ").hex(sp).string("  ip: ").hex(deoptimizedFrame.getSourcePC()).newline();
    if (sourceFrameInfo != null) {
        log.string("    stack trace where execution continues:").newline();
        FrameInfoQueryResult sourceFrame = sourceFrameInfo;
        VirtualFrame targetFrame = deoptimizedFrame.getTopFrame();
        while (sourceFrame != null) {
            SharedMethod deoptMethod = sourceFrame.getDeoptMethod();
            int bci = sourceFrame.getBci();
            log.string("        at ");
            if (deoptMethod != null) {
                StackTraceElement element = deoptMethod.asStackTraceElement(bci);
                if (element.getFileName() != null && element.getLineNumber() >= 0) {
                    log.string(element.toString());
                } else {
                    log.string(deoptMethod.format("%H.%n(%p)")).string(" bci ").signed(bci);
                }
            } else {
                log.string("method at ").hex(sourceFrame.getDeoptMethodAddress()).string(" bci ").signed(bci);
            }
            log.newline();
            if (Options.TraceDeoptimizationDetails.getValue()) {
                printVirtualFrame(log, targetFrame);
            }
            sourceFrame = sourceFrame.getCaller();
            targetFrame = targetFrame.getCaller();
        }
    }
    log.string("]").newline();
}
Also used : VirtualFrame(com.oracle.svm.core.deopt.DeoptimizedFrame.VirtualFrame) SharedMethod(com.oracle.svm.core.meta.SharedMethod) FrameInfoQueryResult(com.oracle.svm.core.code.FrameInfoQueryResult)

Example 3 with SharedMethod

use of com.oracle.svm.core.meta.SharedMethod in project graal by oracle.

the class CFunctionCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    CFunction annotation = method.getAnnotation(CFunction.class);
    boolean needsTransition = annotation.transition() != Transition.NO_TRANSITION;
    if (purpose == Purpose.PREPARE_RUNTIME_COMPILATION && needsTransition) {
        /*
             * C function calls that need a transition cannot be runtime compiled (and cannot be
             * inlined during runtime compilation). Deoptimization could be required while we are
             * blocked in native code, which means the deoptimization stub would need to do the
             * native-to-Java transition.
             */
        ImageSingletons.lookup(CFunctionFeature.class).warnRuntimeCompilationReachableCFunctionWithTransition(this);
        return null;
    }
    boolean deoptimizationTarget = method instanceof SharedMethod && ((SharedMethod) method).isDeoptTarget();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    FrameStateBuilder state = kit.getFrameState();
    ValueNode callAddress = kit.unique(new CGlobalDataLoadAddressNode(linkage));
    List<ValueNode> arguments = kit.loadArguments(method.toParameterTypes());
    Signature signature = adaptSignatureAndConvertArguments(method, providers, nativeLibraries, kit, method.getSignature(), arguments);
    state.clearLocals();
    ValueNode returnValue = kit.createCFunctionCall(callAddress, method, arguments, signature, needsTransition, deoptimizationTarget);
    returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
    kit.createReturn(returnValue, signature.getReturnKind());
    assert kit.getGraph().verify();
    return kit.getGraph();
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)

Example 4 with SharedMethod

use of com.oracle.svm.core.meta.SharedMethod in project graal by oracle.

the class SubstrateAMD64Backend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenResult, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    Assembler masm = createAssembler(frameMap);
    SharedMethod method = ((SubstrateLIRGenerationResult) lirGenResult).getMethod();
    Deoptimizer.StubType stubType = method.getDeoptStubType();
    DataBuilder dataBuilder = new SubstrateDataBuilder();
    FrameContext frameContext;
    if (stubType == Deoptimizer.StubType.EntryStub) {
        frameContext = new DeoptEntryStubContext();
    } else if (stubType == Deoptimizer.StubType.ExitStub) {
        frameContext = new DeoptExitStubContext();
    } else {
        frameContext = new SubstrateAMD64FrameContext();
    }
    LIR lir = lirGenResult.getLIR();
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    CompilationResultBuilder tasm = factory.createBuilder(getCodeCache(), getForeignCalls(), lirGenResult.getFrameMap(), masm, dataBuilder, frameContext, options, debug, compilationResult);
    tasm.setTotalFrameSize(lirGenResult.getFrameMap().totalFrameSize());
    return tasm;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) FrameContext(org.graalvm.compiler.lir.asm.FrameContext) DebugContext(org.graalvm.compiler.debug.DebugContext) Deoptimizer(com.oracle.svm.core.deopt.Deoptimizer) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) SubstrateDataBuilder(com.oracle.svm.core.graal.code.SubstrateDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) SharedMethod(com.oracle.svm.core.meta.SharedMethod) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) Assembler(org.graalvm.compiler.asm.Assembler) SubstrateDataBuilder(com.oracle.svm.core.graal.code.SubstrateDataBuilder)

Example 5 with SharedMethod

use of com.oracle.svm.core.meta.SharedMethod in project graal by oracle.

the class InstalledCodeBuilder method getTargetCodeAddress.

private long getTargetCodeAddress(Call callInfo) {
    // NOTE that for the moment, we don't make static calls to external
    // (e.g. native) functions.
    // This will change, and we will have to case-split here... but not yet.
    SharedMethod targetMethod = (SharedMethod) callInfo.target;
    long callTargetStart = CodeInfoTable.getImageCodeCache().absoluteIP(targetMethod.getCodeOffsetInImage()).rawValue();
    if (allInstalledCode != null) {
        InstalledCodeBuilder targetInstalledCodeBuilder = allInstalledCode.get(targetMethod);
        if (targetInstalledCodeBuilder != null) {
            SubstrateInstalledCode targetInstalledCode = targetInstalledCodeBuilder.getInstalledCode();
            if (targetInstalledCode != null && targetInstalledCode.isValid()) {
                callTargetStart = targetInstalledCode.getAddress();
            }
        }
    }
    if (callTargetStart == 0) {
        throw VMError.shouldNotReachHere("target method not compiled: " + targetMethod.format("%H.%n(%p)"));
    }
    return callTargetStart;
}
Also used : SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) SharedMethod(com.oracle.svm.core.meta.SharedMethod)

Aggregations

SharedMethod (com.oracle.svm.core.meta.SharedMethod)10 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 FrameInfoQueryResult (com.oracle.svm.core.code.FrameInfoQueryResult)1 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)1 VirtualFrame (com.oracle.svm.core.deopt.DeoptimizedFrame.VirtualFrame)1 Deoptimizer (com.oracle.svm.core.deopt.Deoptimizer)1 SubstrateInstalledCode (com.oracle.svm.core.deopt.SubstrateInstalledCode)1 SubstrateDataBuilder (com.oracle.svm.core.graal.code.SubstrateDataBuilder)1 CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)1 FarReturnNode (com.oracle.svm.core.graal.nodes.FarReturnNode)1 FormatArrayNode (com.oracle.svm.core.graal.nodes.FormatArrayNode)1 FormatObjectNode (com.oracle.svm.core.graal.nodes.FormatObjectNode)1 ReadCallerStackPointerNode (com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode)1 ReadInstructionPointerNode (com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode)1 ReadReturnAddressNode (com.oracle.svm.core.graal.nodes.ReadReturnAddressNode)1 ReadStackPointerNode (com.oracle.svm.core.graal.nodes.ReadStackPointerNode)1 TestDeoptimizeNode (com.oracle.svm.core.graal.nodes.TestDeoptimizeNode)1 WriteStackPointerNode (com.oracle.svm.core.graal.nodes.WriteStackPointerNode)1