Search in sources :

Example 1 with MethodSubstitutionPlugin

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

the class ReplacementsImpl method getSubstitutionBytecode.

@Override
public Bytecode getSubstitutionBytecode(ResolvedJavaMethod method) {
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin instanceof MethodSubstitutionPlugin) {
        MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
        ResolvedJavaMethod substitute = msPlugin.getSubstitute(providers.getMetaAccess());
        return msPlugin.getBytecodeProvider().getBytecode(substitute);
    }
    return null;
}
Also used : InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with MethodSubstitutionPlugin

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

the class ReplacementsImpl method getSubstitution.

@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    StructuredGraph result;
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
        MetaAccessProvider metaAccess = providers.getMetaAccess();
        if (plugin instanceof MethodSubstitutionPlugin) {
            MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
            ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
            StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
            if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
                try (DebugContext debug = openDebugContext("Substitution_", method)) {
                    graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
                    if (!UseSnippetGraphCache.getValue(options)) {
                        return graph;
                    }
                    graph.freeze();
                    graphs.putIfAbsent(substitute, graph);
                    graph = graphs.get(substitute);
                }
            }
            assert graph.isFrozen();
            result = graph;
        } else {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            ConstantReflectionProvider constantReflection = providers.getConstantReflection();
            ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
            StampProvider stampProvider = providers.getStampProvider();
            try (DebugContext debug = openDebugContext("Substitution_", method)) {
                result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
            }
        }
    } else {
        result = null;
    }
    return result;
}
Also used : StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) DebugContext(org.graalvm.compiler.debug.DebugContext) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Example 3 with MethodSubstitutionPlugin

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

the class TestIntrinsicCompiles method test.

@Test
@SuppressWarnings("try")
public void test() throws ClassNotFoundException {
    HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) JVMCI.getRuntime().getCompiler();
    HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
    HotSpotProviders providers = rt.getHostBackend().getProviders();
    Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins();
    InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins();
    EconomicMap<String, List<Binding>> bindings = invocationPlugins.getBindings(true);
    HotSpotVMConfigStore store = rt.getVMConfig().getStore();
    List<VMIntrinsicMethod> intrinsics = store.getIntrinsics();
    OptionValues options = getInitialOptions();
    DebugContext debug = getDebugContext(options);
    for (VMIntrinsicMethod intrinsic : intrinsics) {
        InvocationPlugin plugin = CheckGraalIntrinsics.findPlugin(bindings, intrinsic);
        if (plugin != null) {
            if (plugin instanceof MethodSubstitutionPlugin) {
                ResolvedJavaMethod method = CheckGraalIntrinsics.resolveIntrinsic(getMetaAccess(), intrinsic);
                if (!method.isNative()) {
                    StructuredGraph graph = compiler.getIntrinsicGraph(method, providers, INVALID_COMPILATION_ID, options, debug);
                    getCode(method, graph);
                }
            }
        }
    }
}
Also used : HotSpotGraalCompiler(org.graalvm.compiler.hotspot.HotSpotGraalCompiler) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) DebugContext(org.graalvm.compiler.debug.DebugContext) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) List(java.util.List) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) HotSpotVMConfigStore(jdk.vm.ci.hotspot.HotSpotVMConfigStore) VMIntrinsicMethod(jdk.vm.ci.hotspot.VMIntrinsicMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)3 MethodSubstitutionPlugin (org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin)3 DebugContext (org.graalvm.compiler.debug.DebugContext)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 GeneratedInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin)2 List (java.util.List)1 HotSpotVMConfigStore (jdk.vm.ci.hotspot.HotSpotVMConfigStore)1 VMIntrinsicMethod (jdk.vm.ci.hotspot.VMIntrinsicMethod)1 ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 Bytecode (org.graalvm.compiler.bytecode.Bytecode)1 ResolvedJavaMethodBytecode (org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode)1 ConstantFieldProvider (org.graalvm.compiler.core.common.spi.ConstantFieldProvider)1 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)1 HotSpotGraalCompiler (org.graalvm.compiler.hotspot.HotSpotGraalCompiler)1 HotSpotGraalRuntimeProvider (org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider)1 HotSpotProviders (org.graalvm.compiler.hotspot.meta.HotSpotProviders)1 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)1 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)1