16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.nodes.spi;
26
27 import org.graalvm.compiler.api.replacements.MethodSubstitution;
28 import org.graalvm.compiler.api.replacements.SnippetTemplateCache;
29 import org.graalvm.compiler.bytecode.Bytecode;
30 import org.graalvm.compiler.bytecode.BytecodeProvider;
31 import org.graalvm.compiler.core.common.CompilationIdentifier;
32 import org.graalvm.compiler.debug.DebugContext;
33 import org.graalvm.compiler.graph.NodeSourcePosition;
34 import org.graalvm.compiler.nodes.StructuredGraph;
35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
36 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
37 import org.graalvm.compiler.options.OptionValues;
38
39 import jdk.vm.ci.meta.ResolvedJavaMethod;
40
41 /**
42 * Interface for managing replacements.
43 */
44 public interface Replacements {
45
46 OptionValues getOptions();
47
48 /**
49 * Gets the object managing the various graph builder plugins used by this object when parsing
50 * bytecode into a graph.
51 */
52 GraphBuilderConfiguration.Plugins getGraphBuilderPlugins();
53
54 /**
55 * Gets the snippet graph derived from a given method.
56 *
57 * @param args arguments to the snippet if available, otherwise {@code null}
58 * @param trackNodeSourcePosition
59 * @return the snippet graph, if any, that is derived from {@code method}
60 */
61 StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
62
63 /**
64 * Gets the snippet graph derived from a given method.
65 *
66 * @param recursiveEntry if the snippet contains a call to this method, it's considered as
67 * recursive call and won't be processed for {@linkplain MethodSubstitution
68 * substitutions}.
69 * @param args arguments to the snippet if available, otherwise {@code null}
70 * @param trackNodeSourcePosition
71 * @return the snippet graph, if any, that is derived from {@code method}
72 */
73 StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
74
75 /**
76 * Registers a method as snippet.
77 */
78 void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition);
79
80 /**
81 * Gets a graph that is a substitution for a given method.
82 *
83 * @param invokeBci the call site BCI if this request is made for inlining a substitute
84 * otherwise {@code -1}
85 * @param trackNodeSourcePosition
86 * @return the graph, if any, that is a substitution for {@code method}
87 */
88 StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
89
90 /**
91 * Gets the substitute bytecode for a given method.
92 *
93 * @return the bytecode to substitute for {@code method} or {@code null} if there is no
94 * substitute bytecode for {@code method}
95 */
96 Bytecode getSubstitutionBytecode(ResolvedJavaMethod method);
97
98 /**
121 * @return true iff there may be a substitution graph available for {@code method}
122 */
123 boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci);
124
125 /**
126 * Gets the provider for accessing the bytecode of a substitution method if no other provider is
127 * associated with the substitution method.
128 */
129 BytecodeProvider getDefaultReplacementBytecodeProvider();
130
131 /**
132 * Register snippet templates.
133 */
134 void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates);
135
136 /**
137 * Get snippet templates that were registered with
138 * {@link Replacements#registerSnippetTemplateCache(SnippetTemplateCache)}.
139 */
140 <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass);
141 }
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.nodes.spi;
26
27 import org.graalvm.compiler.api.replacements.MethodSubstitution;
28 import org.graalvm.compiler.api.replacements.SnippetTemplateCache;
29 import org.graalvm.compiler.bytecode.Bytecode;
30 import org.graalvm.compiler.bytecode.BytecodeProvider;
31 import org.graalvm.compiler.core.common.CompilationIdentifier;
32 import org.graalvm.compiler.debug.DebugContext;
33 import org.graalvm.compiler.graph.NodeSourcePosition;
34 import org.graalvm.compiler.nodes.StructuredGraph;
35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
36 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
37 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
38 import org.graalvm.compiler.options.OptionValues;
39
40 import jdk.vm.ci.meta.ResolvedJavaMethod;
41
42 /**
43 * Interface for managing replacements.
44 */
45 public interface Replacements {
46
47 OptionValues getOptions();
48
49 /**
50 * Gets the object managing the various graph builder plugins used by this object when parsing
51 * bytecode into a graph.
52 */
53 GraphBuilderConfiguration.Plugins getGraphBuilderPlugins();
54
55 /**
56 * Gets the plugin type that intrinsifies calls to {@code method}.
57 */
58 Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method);
59
60 /**
61 * Gets the snippet graph derived from a given method.
62 *
63 * @param args arguments to the snippet if available, otherwise {@code null}
64 * @param trackNodeSourcePosition
65 * @return the snippet graph, if any, that is derived from {@code method}
66 */
67 StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
68
69 /**
70 * Gets the snippet graph derived from a given method.
71 *
72 * @param recursiveEntry if the snippet contains a call to this method, it's considered as
73 * recursive call and won't be processed for {@linkplain MethodSubstitution
74 * substitutions}.
75 * @param args arguments to the snippet if available, otherwise {@code null}
76 * @param trackNodeSourcePosition
77 * @return the snippet graph, if any, that is derived from {@code method}
78 */
79 StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
80
81 /**
82 * Registers a method as snippet.
83 */
84 void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition);
85
86 /**
87 * Gets a graph that is a substitution for a given method.
88 *
89 * @param invokeBci the call site BCI if this request is made for inlining a substitute
90 * otherwise {@code -1}
91 * @param trackNodeSourcePosition
92 * @return the graph, if any, that is a substitution for {@code method}
93 */
94 StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition);
95
96 /**
97 * Gets the substitute bytecode for a given method.
98 *
99 * @return the bytecode to substitute for {@code method} or {@code null} if there is no
100 * substitute bytecode for {@code method}
101 */
102 Bytecode getSubstitutionBytecode(ResolvedJavaMethod method);
103
104 /**
127 * @return true iff there may be a substitution graph available for {@code method}
128 */
129 boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci);
130
131 /**
132 * Gets the provider for accessing the bytecode of a substitution method if no other provider is
133 * associated with the substitution method.
134 */
135 BytecodeProvider getDefaultReplacementBytecodeProvider();
136
137 /**
138 * Register snippet templates.
139 */
140 void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates);
141
142 /**
143 * Get snippet templates that were registered with
144 * {@link Replacements#registerSnippetTemplateCache(SnippetTemplateCache)}.
145 */
146 <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass);
147
148 /**
149 * Notifies this method that no further snippets will be registered via {@link #registerSnippet}
150 * or {@link #registerSnippetTemplateCache}.
151 *
152 * This is a hook for an implementation to check for or forbid late registration.
153 */
154 default void closeSnippetRegistration() {
155 }
156 }
|