Search in sources :

Example 11 with MethodCallTargetNode

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

the class CompileQueue method defaultParseFunction.

@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
    if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
        throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
    }
    HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
    boolean needParsing = false;
    OptionValues options = HostedOptionValues.singleton();
    StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
    if (graph == null) {
        InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
        if (plugin != null && !plugin.inlineOnly()) {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            // DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
            graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
        }
    }
    if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
    }
    if (graph == null) {
        needParsing = true;
        if (!method.compilationInfo.isDeoptTarget()) {
            /*
                 * Disabling liveness analysis preserves the values of local variables beyond the
                 * bytecode-liveness. This greatly helps debugging. When local variable numbers are
                 * reused by javac, local variables can still get illegal values. Since we cannot
                 * "restore" such illegal values during deoptimization, we must do liveness analysis
                 * for deoptimization target methods.
                 */
            options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
        }
        graph = new StructuredGraph.Builder(options, debug).method(method).build();
    }
    try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
        try {
            if (needParsing) {
                GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
                new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
            } else {
                graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
            }
            new DeadStoreRemovalPhase().apply(graph);
            new DevirtualizeCallsPhase().apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /*
                 * The StrengthenStampsPhase may not insert type check nodes for specialized
                 * methods, because we would get type state mismatches regarding Const<Type> !=
                 * <Type>
                 */
            /*
                 * cwimmer: the old, commented out, condition always disabled checking of static
                 * analysis results. Therefore, the checks are broken right now.
                 */
            // new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
            // && method.compilationInfo.deoptTarget != null &&
            // !method.compilationInfo.isDeoptTarget).apply(graph);
            new StrengthenStampsPhase(false).apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /* Check that graph is in good shape after parsing. */
            assert GraphOrder.assertSchedulableGraph(graph);
            method.compilationInfo.graph = graph;
            for (Invoke invoke : graph.getInvokes()) {
                if (!canBeUsedForInlining(invoke)) {
                    invoke.setUseForInlining(false);
                }
                if (invoke.callTarget() instanceof MethodCallTargetNode) {
                    MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
                    HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
                    if (targetNode.invokeKind().isDirect()) {
                        if (invokeTarget.wrapped.isImplementationInvoked()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
                            ensureParsed(invokeTarget, new DirectCallReason(method, reason));
                        }
                    } else {
                        for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
                            ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
                        }
                    }
                }
            }
        } catch (Throwable ex) {
            GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
            error.addContext("method: " + method.format("%r %H.%n(%p)"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Invoke(org.graalvm.compiler.nodes.Invoke) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 12 with MethodCallTargetNode

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

the class InliningUtilities method isTrivialMethod.

public static boolean isTrivialMethod(StructuredGraph graph) {
    int numInvokes = 0;
    int numOthers = 0;
    for (Node n : graph.getNodes()) {
        if (n instanceof StartNode || n instanceof ParameterNode || n instanceof FullInfopointNode || n instanceof ValueProxy || n instanceof AssertValueNode) {
            continue;
        }
        if (n instanceof MethodCallTargetNode) {
            numInvokes++;
        } else {
            numOthers++;
        }
        if (!shouldBeTrivial(numInvokes, numOthers, graph)) {
            return false;
        }
    }
    return true;
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueProxy(org.graalvm.compiler.nodes.spi.ValueProxy) StartNode(org.graalvm.compiler.nodes.StartNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) AssertValueNode(com.oracle.svm.hosted.nodes.AssertValueNode) AssertValueNode(com.oracle.svm.hosted.nodes.AssertValueNode)

Example 13 with MethodCallTargetNode

use of org.graalvm.compiler.nodes.java.MethodCallTargetNode 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 MethodCallTargetNode

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

the class SubstrateReplacements method registerSnippet.

/**
 * Compiles the snippet and stores the graph.
 */
@Platforms(Platform.HOSTED_ONLY.class)
@Override
public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    assert method.hasBytecodes() : "Snippet must not be abstract or native";
    assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName();
    try (DebugContext debug = openDebugContext("Snippet_", method)) {
        StructuredGraph graph = makeGraph(debug, defaultBytecodeProvider, method, null, null, trackNodeSourcePosition, null);
        // Check if all methods which should be inlined are really inlined.
        for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = callTarget.targetMethod();
            if (!builder.delayedInvocationPluginMethods.contains(callee)) {
                throw shouldNotReachHere("method " + callee.getName() + " not inlined in snippet " + method.getName() + " (maybe not final?)");
            }
        }
        builder.graphs.put(method, graph);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Snippet(org.graalvm.compiler.api.replacements.Snippet) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 15 with MethodCallTargetNode

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

the class GraphKit method startInvokeWithException.

public InvokeWithExceptionNode startInvokeWithException(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    assert method.isStatic() == (invokeKind == InvokeKind.Static);
    Signature signature = method.getSignature();
    JavaType returnType = signature.getReturnType(null);
    assert checkArgs(method, args);
    StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    ExceptionObjectNode exceptionObject = add(new ExceptionObjectNode(getMetaAccess()));
    if (frameStateBuilder != null) {
        FrameStateBuilder exceptionState = frameStateBuilder.copy();
        exceptionState.clearStack();
        exceptionState.push(JavaKind.Object, exceptionObject);
        exceptionState.setRethrowException(false);
        exceptionObject.setStateAfter(exceptionState.create(exceptionEdgeBci, exceptionObject));
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, invokeBci));
    InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionObject, invokeBci));
    AbstractBeginNode noExceptionEdge = graph.add(KillingBeginNode.create(LocationIdentity.any()));
    invoke.setNext(noExceptionEdge);
    if (frameStateBuilder != null) {
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.push(invoke.getStackKind(), invoke);
        }
        invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.pop(invoke.getStackKind());
        }
    }
    lastFixedNode = null;
    InvokeWithExceptionStructure s = new InvokeWithExceptionStructure();
    s.state = InvokeWithExceptionStructure.State.INVOKE;
    s.noExceptionEdge = noExceptionEdge;
    s.exceptionEdge = exceptionObject;
    s.exceptionObject = exceptionObject;
    pushStructure(s);
    return invoke;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)46 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)15 ValueNode (org.graalvm.compiler.nodes.ValueNode)15 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 Invoke (org.graalvm.compiler.nodes.Invoke)10 Node (org.graalvm.compiler.graph.Node)9 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)9 ArrayList (java.util.ArrayList)7 StampPair (org.graalvm.compiler.core.common.type.StampPair)7 PiNode (org.graalvm.compiler.nodes.PiNode)7 DebugContext (org.graalvm.compiler.debug.DebugContext)6 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)6 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)5 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)5 FrameState (org.graalvm.compiler.nodes.FrameState)5 JavaType (jdk.vm.ci.meta.JavaType)4 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)4 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)4 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)4