Search in sources :

Example 86 with StructuredGraph

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

the class SubstrateReplacements method getSnippet.

@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    Integer startOffset = snippetStartOffsets.get(method);
    if (startOffset == null) {
        throw VMError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
    }
    ParameterPlugin parameterPlugin = null;
    if (args != null) {
        parameterPlugin = new ConstantBindingParameterPlugin(args, providers.getMetaAccess(), snippetReflection);
    }
    EncodedGraph encodedGraph = new EncodedGraph(snippetEncoding, startOffset, snippetObjects, snippetNodeClasses, null, null, null, false, trackNodeSourcePosition);
    try (DebugContext debug = openDebugContext("SVMSnippet_", method)) {
        StructuredGraph result = new StructuredGraph.Builder(options, debug).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
        PEGraphDecoder graphDecoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, result, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), null, snippetInvocationPlugins, new InlineInvokePlugin[0], parameterPlugin, null, null, null) {

            @Override
            protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean track) {
                if (lookupMethod.equals(method)) {
                    assert !track || encodedGraph.trackNodeSourcePosition();
                    return encodedGraph;
                } else {
                    throw VMError.shouldNotReachHere(method.format("%H.%n(%p)"));
                }
            }
        };
        graphDecoder.decode(method, trackNodeSourcePosition);
        assert result.verify();
        return result;
    }
}
Also used : ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) PEGraphDecoder(org.graalvm.compiler.replacements.PEGraphDecoder) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 87 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph 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 88 with StructuredGraph

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

the class SubstrateReplacements method encodeSnippets.

@Platforms(Platform.HOSTED_ONLY.class)
public void encodeSnippets() {
    GraphEncoder encoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    for (StructuredGraph graph : builder.graphs.values()) {
        encoder.prepare(graph);
    }
    encoder.finishPrepare();
    snippetStartOffsets = new HashMap<>();
    for (Map.Entry<ResolvedJavaMethod, StructuredGraph> entry : builder.graphs.entrySet()) {
        snippetStartOffsets.put(entry.getKey(), encoder.encode(entry.getValue()));
    }
    snippetEncoding = encoder.getEncoding();
    snippetObjects = encoder.getObjects();
    snippetNodeClasses = encoder.getNodeClasses();
    snippetInvocationPlugins = makeInvocationPlugins(getGraphBuilderPlugins(), builder, Function.identity());
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HashMap(java.util.HashMap) Map(java.util.Map) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 89 with StructuredGraph

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

the class PolymorphicInliningTest method testPolymorphicInlining.

public void testPolymorphicInlining() {
    for (int i = 0; i < 10000; i++) {
        if (i % 2 == 0) {
            polymorphicCallsite(Receivers.subClassA);
        } else {
            polymorphicCallsite(Receivers.subClassB);
        }
    }
    StructuredGraph graph = getGraph("polymorphicCallsite", false);
    // This callsite should be inlined with a TypeCheckedInliningViolated deoptimization.
    assertTrue(getNodeCount(graph, InvokeNode.class) == 0);
    assertTrue(getNodeCount(graph, TypeSwitchNode.class) == 1);
    assertTrue(getNodeCount(graph, DeoptimizeNode.class) >= 1);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 90 with StructuredGraph

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

the class PolymorphicInliningTest method testMegamorphicNotInlining.

public void testMegamorphicNotInlining() {
    for (int i = 0; i < 10000; i++) {
        switch(i % 10) {
            case 0:
            case 1:
                polymorphicCallsite3(Receivers.subClassA);
                break;
            case 2:
                polymorphicCallsite3(Receivers.subClassB);
                break;
            case 3:
                polymorphicCallsite3(Receivers.subClassC);
                break;
            case 4:
                polymorphicCallsite3(Receivers.subClassD);
                break;
            case 5:
                polymorphicCallsite3(Receivers.subClassE);
                break;
            case 6:
                polymorphicCallsite3(Receivers.subClassF);
                break;
            case 7:
                polymorphicCallsite3(Receivers.subClassG);
                break;
            case 8:
                polymorphicCallsite3(Receivers.subClassH);
                break;
            default:
                polymorphicCallsite3(Receivers.notInlinableSubClass);
                break;
        }
    }
    StructuredGraph graph = getGraph("polymorphicCallsite3", false);
    // This callsite should not be inlined due to non of the potential callee method exceeds the
    // probability specified by GraalOptions.MegamorphicInliningMinMethodProbability.
    assertTrue(getNodeCount(graph, InvokeNode.class) == 1);
    assertTrue(getNodeCount(graph, TypeSwitchNode.class) == 0);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)360 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)97 Test (org.junit.Test)96 DebugContext (org.graalvm.compiler.debug.DebugContext)88 ValueNode (org.graalvm.compiler.nodes.ValueNode)70 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)62 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)62 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)57 Node (org.graalvm.compiler.graph.Node)39 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)37 OptionValues (org.graalvm.compiler.options.OptionValues)34 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)28 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)26 FixedNode (org.graalvm.compiler.nodes.FixedNode)26 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)25 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)24 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)24 LogicNode (org.graalvm.compiler.nodes.LogicNode)21 CompilationResult (org.graalvm.compiler.code.CompilationResult)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)19