43972
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
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.BytecodeProvider;
|
52578
|
30 |
import org.graalvm.compiler.core.common.CompilationIdentifier;
|
|
31 |
import org.graalvm.compiler.debug.DebugContext;
|
49451
|
32 |
import org.graalvm.compiler.graph.NodeSourcePosition;
|
55509
|
33 |
import org.graalvm.compiler.nodes.Cancellable;
|
43972
|
34 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
46459
|
35 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
52956
|
36 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
|
54601
|
37 |
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
|
43972
|
38 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
54601
|
39 |
import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
|
46344
|
40 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
41 |
|
|
42 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Interface for managing replacements.
|
|
46 |
*/
|
|
47 |
public interface Replacements {
|
|
48 |
|
54601
|
49 |
CoreProviders getProviders();
|
46344
|
50 |
|
43972
|
51 |
/**
|
46459
|
52 |
* Gets the object managing the various graph builder plugins used by this object when parsing
|
|
53 |
* bytecode into a graph.
|
|
54 |
*/
|
|
55 |
GraphBuilderConfiguration.Plugins getGraphBuilderPlugins();
|
|
56 |
|
|
57 |
/**
|
52956
|
58 |
* Gets the plugin type that intrinsifies calls to {@code method}.
|
|
59 |
*/
|
|
60 |
Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method);
|
|
61 |
|
|
62 |
/**
|
43972
|
63 |
* Gets the snippet graph derived from a given method.
|
|
64 |
*
|
|
65 |
* @param recursiveEntry if the snippet contains a call to this method, it's considered as
|
|
66 |
* recursive call and won't be processed for {@linkplain MethodSubstitution
|
|
67 |
* substitutions}.
|
|
68 |
* @param args arguments to the snippet if available, otherwise {@code null}
|
49451
|
69 |
* @param trackNodeSourcePosition
|
54601
|
70 |
* @param options
|
43972
|
71 |
* @return the snippet graph, if any, that is derived from {@code method}
|
|
72 |
*/
|
54601
|
73 |
StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition,
|
|
74 |
OptionValues options);
|
43972
|
75 |
|
|
76 |
/**
|
|
77 |
* Registers a method as snippet.
|
|
78 |
*/
|
54601
|
79 |
void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options);
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Gets a graph that is a substitution for a given {@link MethodSubstitutionPlugin plugin} in
|
|
83 |
* the {@link org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext
|
|
84 |
* context}.
|
|
85 |
*
|
|
86 |
* @param plugin the plugin being substituted
|
|
87 |
* @param original the method being substituted
|
|
88 |
* @param context the kind of inlining to be performed for the substitution
|
|
89 |
* @param allowAssumptions
|
55509
|
90 |
* @param cancellable
|
54601
|
91 |
* @param options
|
|
92 |
* @return the method substitution graph, if any, that is derived from {@code method}
|
|
93 |
*/
|
|
94 |
StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context,
|
55509
|
95 |
StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options);
|
54601
|
96 |
|
|
97 |
/**
|
|
98 |
* Registers a plugin as a substitution.
|
|
99 |
*/
|
|
100 |
void registerMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, OptionValues options);
|
43972
|
101 |
|
|
102 |
/**
|
|
103 |
* Gets a graph that is a substitution for a given method.
|
|
104 |
*
|
|
105 |
* @param invokeBci the call site BCI if this request is made for inlining a substitute
|
|
106 |
* otherwise {@code -1}
|
49451
|
107 |
* @param trackNodeSourcePosition
|
54601
|
108 |
* @param options
|
43972
|
109 |
* @return the graph, if any, that is a substitution for {@code method}
|
|
110 |
*/
|
54601
|
111 |
StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options);
|
43972
|
112 |
|
|
113 |
/**
|
52578
|
114 |
* Gets a graph produced from the intrinsic for a given method that can be compiled and
|
|
115 |
* installed for the method.
|
|
116 |
*
|
|
117 |
* @param method
|
|
118 |
* @param compilationId
|
|
119 |
* @param debug
|
55509
|
120 |
* @param cancellable
|
52578
|
121 |
* @return an intrinsic graph that can be compiled and installed for {@code method} or null
|
|
122 |
*/
|
55509
|
123 |
StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable);
|
52578
|
124 |
|
|
125 |
/**
|
49451
|
126 |
* Determines if there may be a
|
54601
|
127 |
* {@linkplain #getSubstitution(ResolvedJavaMethod, int, boolean, NodeSourcePosition, OptionValues)
|
43972
|
128 |
* substitution graph} for a given method.
|
|
129 |
*
|
|
130 |
* A call to {@link #getSubstitution} may still return {@code null} for {@code method} and
|
|
131 |
* {@code invokeBci}. A substitution may be based on an {@link InvocationPlugin} that returns
|
|
132 |
* {@code false} for {@link InvocationPlugin#execute} making it impossible to create a
|
|
133 |
* substitute graph.
|
|
134 |
*
|
|
135 |
* @param invokeBci the call site BCI if this request is made for inlining a substitute
|
|
136 |
* otherwise {@code -1}
|
|
137 |
* @return true iff there may be a substitution graph available for {@code method}
|
|
138 |
*/
|
|
139 |
boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci);
|
|
140 |
|
|
141 |
/**
|
46459
|
142 |
* Gets the provider for accessing the bytecode of a substitution method if no other provider is
|
|
143 |
* associated with the substitution method.
|
43972
|
144 |
*/
|
46459
|
145 |
BytecodeProvider getDefaultReplacementBytecodeProvider();
|
43972
|
146 |
|
|
147 |
/**
|
|
148 |
* Register snippet templates.
|
|
149 |
*/
|
|
150 |
void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates);
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Get snippet templates that were registered with
|
|
154 |
* {@link Replacements#registerSnippetTemplateCache(SnippetTemplateCache)}.
|
|
155 |
*/
|
|
156 |
<T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass);
|
52956
|
157 |
|
|
158 |
/**
|
|
159 |
* Notifies this method that no further snippets will be registered via {@link #registerSnippet}
|
|
160 |
* or {@link #registerSnippetTemplateCache}.
|
|
161 |
*
|
|
162 |
* This is a hook for an implementation to check for or forbid late registration.
|
|
163 |
*/
|
|
164 |
default void closeSnippetRegistration() {
|
|
165 |
}
|
43972
|
166 |
}
|