Search in sources :

Example 81 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class SubstrateReplacements method makeInvocationPlugins.

@Platforms(Platform.HOSTED_ONLY.class)
private static InvocationPlugins makeInvocationPlugins(GraphBuilderConfiguration.Plugins plugins, Builder builder, Function<Object, Object> objectReplacer) {
    Map<ResolvedJavaMethod, InvocationPlugin> result = new HashMap<>(builder.delayedInvocationPluginMethods.size());
    for (ResolvedJavaMethod method : builder.delayedInvocationPluginMethods) {
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) objectReplacer.apply(method);
        InvocationPlugin plugin = plugins.getInvocationPlugins().lookupInvocation(replacedMethod);
        assert plugin != null : "expected invocation plugin for " + replacedMethod;
        result.put(replacedMethod, plugin);
    }
    return new InvocationPlugins(result, null);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) HashMap(java.util.HashMap) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 82 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod 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 83 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class GraalTutorial method testGetBytecodes.

/*
     * Example for the Graal API: access the Graal API metadata object for a method.
     */
@Test
public void testGetBytecodes() throws NoSuchMethodException {
    Method reflectionMethod = String.class.getDeclaredMethod("hashCode");
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflectionMethod);
    /*
         * ResolvedJavaMethod provides all information that you want about a method, for example,
         * the bytecodes.
         */
    byte[] bytecodes = method.getCode();
    /*
         * BytecodeDisassembler shows you how to iterate bytecodes, how to access type information,
         * and more.
         */
    String disassembly = new BytecodeDisassembler().disassemble(method);
    /*
         * We don't want test cases to print any output, so we check the validity of the output
         * instead.
         */
    Pattern disassemblyLineRE = Pattern.compile(" *\\d+: [a-z][\\w_]+");
    for (String line : disassembly.split("\\n")) {
        Assert.assertTrue(line, disassemblyLineRE.matcher(line).find());
    }
    Assert.assertTrue(bytecodes.length > 0);
}
Also used : Pattern(java.util.regex.Pattern) BytecodeDisassembler(org.graalvm.compiler.bytecode.BytecodeDisassembler) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Example 84 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerBinaryMath.

private void lowerBinaryMath(BinaryMathIntrinsicNode math, LoweringTool tool) {
    if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
        return;
    }
    ResolvedJavaMethod method = math.graph().method();
    if (method != null) {
        if (method.getAnnotation(Snippet.class) != null) {
            /*
                 * In the context of the snippet use the LIR lowering instead of the Node lowering.
                 */
            return;
        }
        if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
            /*
                 * A root compilation of the intrinsic method should emit the full assembly
                 * implementation.
                 */
            return;
        }
    }
    ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
    if (foreignCall != null) {
        StructuredGraph graph = math.graph();
        ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, toForeignCall(math.getOperation()), math.getX(), math.getY()));
        graph.addAfterFixed(tool.lastFixedNode(), call);
        math.replaceAtUsages(call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 85 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class GraphKit method inline.

/**
 * Inlines a given invocation to a method. The graph of the inlined method is processed in the
 * same manner as for snippets and method substitutions.
 */
public void inline(InvokeNode invoke) {
    ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(graphBuilderPlugins);
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
    if (invoke.graph().trackNodeSourcePosition()) {
        calleeGraph.setTrackNodeSourcePosition();
    }
    IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
    GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
    instance.apply(calleeGraph);
    // Remove all frame states from inlinee
    calleeGraph.clearAllStateAfter();
    new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
    InliningUtil.inline(invoke, calleeGraph, false, method);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16