Replacements.java revision 12651:6ef01bd40ce2
1299425Smm/*
2299425Smm * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3299425Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4299425Smm *
5299425Smm * This code is free software; you can redistribute it and/or modify it
6299425Smm * under the terms of the GNU General Public License version 2 only, as
7299425Smm * published by the Free Software Foundation.
8299425Smm *
9299425Smm * This code is distributed in the hope that it will be useful, but WITHOUT
10299425Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11299425Smm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12299425Smm * version 2 for more details (a copy is included in the LICENSE file that
13299425Smm * accompanied this code).
14299425Smm *
15299425Smm * You should have received a copy of the GNU General Public License version
16299425Smm * 2 along with this work; if not, write to the Free Software Foundation,
17299425Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18299425Smm *
19299425Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20299425Smm * or visit www.oracle.com if you need additional information or have any
21299425Smm * questions.
22299425Smm */
23299425Smmpackage org.graalvm.compiler.nodes.spi;
24299425Smm
25299425Smmimport org.graalvm.compiler.api.replacements.MethodSubstitution;
26299425Smmimport org.graalvm.compiler.api.replacements.SnippetTemplateCache;
27299425Smmimport org.graalvm.compiler.bytecode.BytecodeProvider;
28299425Smmimport org.graalvm.compiler.nodes.StructuredGraph;
29299425Smmimport org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
30299425Smm
31299425Smmimport jdk.vm.ci.meta.ResolvedJavaMethod;
32299425Smm
33299425Smm/**
34299425Smm * Interface for managing replacements.
35299425Smm */
36299425Smmpublic interface Replacements {
37299425Smm
38299425Smm    /**
39299425Smm     * Gets the snippet graph derived from a given method.
40299425Smm     *
41299425Smm     * @param args arguments to the snippet if available, otherwise {@code null}
42299425Smm     * @return the snippet graph, if any, that is derived from {@code method}
43299425Smm     */
44299425Smm    StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args);
45299425Smm
46299425Smm    /**
47299425Smm     * Gets the snippet graph derived from a given method.
48299425Smm     *
49299425Smm     * @param recursiveEntry if the snippet contains a call to this method, it's considered as
50299425Smm     *            recursive call and won't be processed for {@linkplain MethodSubstitution
51299425Smm     *            substitutions}.
52299425Smm     * @param args arguments to the snippet if available, otherwise {@code null}
53299425Smm     * @return the snippet graph, if any, that is derived from {@code method}
54299425Smm     */
55299425Smm    StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args);
56299425Smm
57299425Smm    /**
58299425Smm     * Registers a method as snippet.
59299425Smm     */
60299425Smm    void registerSnippet(ResolvedJavaMethod method);
61299425Smm
62299425Smm    /**
63299425Smm     * Gets a graph that is a substitution for a given method.
64299425Smm     *
65299425Smm     * @param invokeBci the call site BCI if this request is made for inlining a substitute
66299425Smm     *            otherwise {@code -1}
67299425Smm     * @return the graph, if any, that is a substitution for {@code method}
68299425Smm     */
69299425Smm    StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci);
70299425Smm
71299425Smm    /**
72299425Smm     * Gets a method that is a substitution for a given method.
73299425Smm     *
74299425Smm     * @return the method, if any, whose bytecode are a substitution for {@code method}
75299425Smm     */
76299425Smm    ResolvedJavaMethod getSubstitutionMethod(ResolvedJavaMethod method);
77299425Smm
78299425Smm    /**
79315433Smm     * Determines if there may be a {@linkplain #getSubstitution(ResolvedJavaMethod, int)
80315433Smm     * substitution graph} for a given method.
81315433Smm     *
82315433Smm     * A call to {@link #getSubstitution} may still return {@code null} for {@code method} and
83299425Smm     * {@code invokeBci}. A substitution may be based on an {@link InvocationPlugin} that returns
84299425Smm     * {@code false} for {@link InvocationPlugin#execute} making it impossible to create a
85299425Smm     * substitute graph.
86358090Smm     *
87348608Smm     * @param invokeBci the call site BCI if this request is made for inlining a substitute
88358090Smm     *            otherwise {@code -1}
89299425Smm     * @return true iff there may be a substitution graph available for {@code method}
90299425Smm     */
91299425Smm    boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci);
92299425Smm
93299425Smm    /**
94299425Smm     * Gets the provider for accessing the bytecode of a substitution method.
95299425Smm     */
96299425Smm    BytecodeProvider getReplacementBytecodeProvider();
97299425Smm
98299425Smm    /**
99299425Smm     * Register snippet templates.
100299425Smm     */
101299425Smm    void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates);
102299425Smm
103299425Smm    /**
104299425Smm     * Get snippet templates that were registered with
105299425Smm     * {@link Replacements#registerSnippetTemplateCache(SnippetTemplateCache)}.
106299425Smm     */
107299425Smm    <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass);
108299425Smm}
109299425Smm