Search in sources :

Example 11 with Invoke

use of org.graalvm.compiler.nodes.Invoke in project graal by oracle.

the class UninterruptibleAnnotationChecker method checkUninterruptibleCallees.

/**
 * Check that each method annotated with {@link Uninterruptible} calls only methods that are
 * also annotated with {@link Uninterruptible}, or methods annotated with {@link CFunction} that
 * specify "Transition = NO_TRANSITION".
 *
 * A caller can be annotated with "calleeMustBe = false" to allow calls to methods that are not
 * annotated with {@link Uninterruptible}, to allow the few cases where that should be allowed.
 */
@SuppressWarnings("try")
private void checkUninterruptibleCallees(DebugContext debug) {
    if (Options.PrintUninterruptibleCalleeDOTGraph.getValue()) {
        System.out.println("/* DOT */ digraph uninterruptible {");
    }
    for (HostedMethod caller : methodCollection) {
        try (DebugContext.Scope s = debug.scope("CheckUninterruptibleCallees", caller.compilationInfo.graph, caller, this)) {
            Uninterruptible callerAnnotation = caller.getAnnotation(Uninterruptible.class);
            StructuredGraph graph = caller.compilationInfo.getGraph();
            if (callerAnnotation != null) {
                if (callerAnnotation.calleeMustBe()) {
                    if (graph != null) {
                        for (Invoke invoke : graph.getInvokes()) {
                            HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
                            if (Options.PrintUninterruptibleCalleeDOTGraph.getValue()) {
                                printDotGraphEdge(caller, callee);
                            }
                            if (!isNotInterruptible(callee)) {
                                postUninterruptibleWarning("Unannotated callee: " + callee.format("%h.%n(%p)") + " called by annotated caller " + caller.format("%h.%n(%p)"));
                            }
                        }
                    }
                } else {
                    // Print DOT graph edge even if callee need not be annotated.
                    if (graph != null) {
                        for (Invoke invoke : graph.getInvokes()) {
                            HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
                            if (Options.PrintUninterruptibleCalleeDOTGraph.getValue()) {
                                printDotGraphEdge(caller, callee);
                            }
                        }
                    }
                }
            }
        } catch (Throwable t) {
            throw debug.handle(t);
        }
    }
    if (Options.PrintUninterruptibleCalleeDOTGraph.getValue()) {
        System.out.println("/* DOT */ }");
    }
}
Also used : Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 12 with Invoke

use of org.graalvm.compiler.nodes.Invoke in project graal by oracle.

the class UninterruptibleAnnotationChecker method checkUninterruptibleCallers.

/**
 * Check that each method that calls a method annotated with {@linkplain Uninterruptible} that
 * has "callerMustBeUninterrutible = true" is also annotated with {@linkplain Uninterruptible}.
 */
@SuppressWarnings("try")
private void checkUninterruptibleCallers(DebugContext debug) {
    for (HostedMethod caller : methodCollection) {
        try (DebugContext.Scope s = debug.scope("CheckUninterruptibleCallers", caller.compilationInfo.graph, caller, this)) {
            Uninterruptible callerAnnotation = caller.getAnnotation(Uninterruptible.class);
            StructuredGraph graph = caller.compilationInfo.getGraph();
            if (callerAnnotation == null && graph != null) {
                for (Invoke invoke : graph.getInvokes()) {
                    HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
                    if (isCallerMustBe(callee)) {
                        postUninterruptibleWarning("Unannotated caller: " + caller.format("%h.%n(%p)") + " calls annotated callee " + callee.format("%h.%n(%p)"));
                    }
                }
            }
        } catch (Throwable t) {
            throw debug.handle(t);
        }
    }
}
Also used : Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 13 with Invoke

use of org.graalvm.compiler.nodes.Invoke in project graal by oracle.

the class BytecodeParser method createNonInlinedInvoke.

protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, ValueNode[] invokeArgs, ResolvedJavaMethod targetMethod, InvokeKind invokeKind, JavaKind resultType, JavaType returnType, JavaTypeProfile profile) {
    StampPair returnStamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, targetMethod, invokeArgs, returnStamp, profile));
    Invoke invoke = createNonInlinedInvoke(exceptionEdge, invokeBci, callTarget, resultType);
    for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) {
        plugin.notifyNotInlined(this, targetMethod, invoke);
    }
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 14 with Invoke

use of org.graalvm.compiler.nodes.Invoke in project graal by oracle.

the class PEGraphDecoder method tryInvocationPlugin.

protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
    if (invocationPlugins == null || invocationPlugins.isEmpty()) {
        return false;
    }
    Invoke invoke = invokeData.invoke;
    ResolvedJavaMethod targetMethod = callTarget.targetMethod();
    InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
    if (invocationPlugin == null) {
        return false;
    }
    ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
    FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
    /*
         * Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
         */
    invoke.asNode().replaceAtPredecessor(null);
    PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
    PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
    InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
    if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
        if (graphBuilderContext.invokeConsumed) {
        /* Nothing to do. */
        } else if (graphBuilderContext.lastInstr != null) {
            registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
            invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
            graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
            deleteInvoke(invoke);
        } else {
            assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
            invoke.asNode().replaceAtUsages(null);
            deleteInvoke(invoke);
        }
        return true;
    } else {
        /* Intrinsification failed, restore original state: invoke is in Graph. */
        invokePredecessor.setNext(invoke.asNode());
        return false;
    }
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 15 with Invoke

use of org.graalvm.compiler.nodes.Invoke in project graal by oracle.

the class VerifyDebugUsage method verifyParameters.

private void verifyParameters(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, List<? extends ValueNode> args, ResolvedJavaType stringType, int startArgIdx, int varArgsIndex) {
    ResolvedJavaMethod verifiedCallee = debugCallTarget.targetMethod();
    Integer dumpLevel = null;
    int argIdx = startArgIdx;
    int varArgsElementIndex = 0;
    boolean reportVarArgs = false;
    for (int i = 0; i < args.size(); i++) {
        ValueNode arg = args.get(i);
        if (arg instanceof Invoke) {
            reportVarArgs = varArgsIndex >= 0 && argIdx >= varArgsIndex;
            Invoke invoke = (Invoke) arg;
            CallTargetNode callTarget = invoke.callTarget();
            if (callTarget instanceof MethodCallTargetNode) {
                ResolvedJavaMethod m = ((MethodCallTargetNode) callTarget).targetMethod();
                if (m.getName().equals("toString")) {
                    int bci = invoke.bci();
                    int nonVarArgIdx = reportVarArgs ? argIdx - varArgsElementIndex : argIdx;
                    verifyStringConcat(callerGraph, verifiedCallee, bci, nonVarArgIdx, reportVarArgs ? varArgsElementIndex : -1, m);
                    verifyToStringCall(callerGraph, verifiedCallee, stringType, m, bci, nonVarArgIdx, reportVarArgs ? varArgsElementIndex : -1);
                } else if (m.getName().equals("format")) {
                    int bci = invoke.bci();
                    int nonVarArgIdx = reportVarArgs ? argIdx - varArgsElementIndex : argIdx;
                    verifyFormatCall(callerGraph, verifiedCallee, stringType, m, bci, nonVarArgIdx, reportVarArgs ? varArgsElementIndex : -1);
                }
            }
        }
        if (i == 1) {
            if (verifiedCallee.getName().equals("dump")) {
                dumpLevel = verifyDumpLevelParameter(callerGraph, debugCallTarget, verifiedCallee, arg);
            }
        } else if (i == 2) {
            if (dumpLevel != null) {
                verifyDumpObjectParameter(callerGraph, debugCallTarget, arg, verifiedCallee, dumpLevel);
            }
        }
        if (varArgsIndex >= 0 && i >= varArgsIndex) {
            varArgsElementIndex++;
        }
        argIdx++;
    }
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Aggregations

Invoke (org.graalvm.compiler.nodes.Invoke)49 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 Node (org.graalvm.compiler.graph.Node)17 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)17 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 FixedNode (org.graalvm.compiler.nodes.FixedNode)13 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 FrameState (org.graalvm.compiler.nodes.FrameState)10 DebugContext (org.graalvm.compiler.debug.DebugContext)9 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 EndNode (org.graalvm.compiler.nodes.EndNode)7 GraalError (org.graalvm.compiler.debug.GraalError)6 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)6 ArrayList (java.util.ArrayList)5 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)5 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)5