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 */
23
24
25 package org.graalvm.compiler.nodes.graphbuilderconf;
26
27 import static org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.resolveType;
28
29 import java.lang.reflect.Method;
30 import java.lang.reflect.Modifier;
31 import java.lang.reflect.Type;
32 import java.util.Arrays;
33 import java.util.stream.Collectors;
34
35 import org.graalvm.compiler.bytecode.BytecodeProvider;
36 import org.graalvm.compiler.debug.GraalError;
37 import org.graalvm.compiler.nodes.ValueNode;
38
39 import jdk.vm.ci.meta.MetaAccessProvider;
40 import jdk.vm.ci.meta.ResolvedJavaMethod;
41
42 /**
43 * An {@link InvocationPlugin} for a method where the implementation of the method is provided by a
44 * {@linkplain #getSubstitute(MetaAccessProvider) substitute} method. A substitute method must be
45 * static even if the substituted method is not.
46 *
160 return m;
161 }
162 }
163 return null;
164 }
165
166 /**
167 * Gets the substitute method of this plugin.
168 */
169 private Method lookupSubstitute() {
170 Method m = lookupSubstitute(null);
171 if (m != null) {
172 assert lookupSubstitute(m) == null : String.format("multiple matches found for %s:%n%s%n%s", this, m, lookupSubstitute(m));
173 return m;
174 }
175 throw new GraalError("No method found specified by %s", this);
176 }
177
178 @Override
179 public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver) {
180 ResolvedJavaMethod subst = getSubstitute(b.getMetaAccess());
181 return b.intrinsify(bytecodeProvider, targetMethod, subst, receiver, argsIncludingReceiver);
182 }
183
184 @Override
185 public StackTraceElement getApplySourceLocation(MetaAccessProvider metaAccess) {
186 Class<?> c = getClass();
187 for (Method m : c.getDeclaredMethods()) {
188 if (m.getName().equals("execute")) {
189 return metaAccess.lookupJavaMethod(m).asStackTraceElement(0);
190 }
191 }
192 throw new GraalError("could not find method named \"execute\" in " + c.getName());
193 }
194
195 @Override
196 public String toString() {
197 return String.format("%s[%s.%s(%s)]", getClass().getSimpleName(), declaringClass.getName(), name,
198 Arrays.asList(parameters).stream().map(c -> c.getTypeName()).collect(Collectors.joining(", ")));
199 }
|
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 */
23
24
25 package org.graalvm.compiler.nodes.graphbuilderconf;
26
27 import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;
28 import static org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.resolveType;
29
30 import java.lang.reflect.Method;
31 import java.lang.reflect.Modifier;
32 import java.lang.reflect.Type;
33 import java.util.Arrays;
34 import java.util.stream.Collectors;
35
36 import org.graalvm.compiler.bytecode.BytecodeProvider;
37 import org.graalvm.compiler.debug.GraalError;
38 import org.graalvm.compiler.nodes.ValueNode;
39
40 import jdk.vm.ci.meta.MetaAccessProvider;
41 import jdk.vm.ci.meta.ResolvedJavaMethod;
42
43 /**
44 * An {@link InvocationPlugin} for a method where the implementation of the method is provided by a
45 * {@linkplain #getSubstitute(MetaAccessProvider) substitute} method. A substitute method must be
46 * static even if the substituted method is not.
47 *
161 return m;
162 }
163 }
164 return null;
165 }
166
167 /**
168 * Gets the substitute method of this plugin.
169 */
170 private Method lookupSubstitute() {
171 Method m = lookupSubstitute(null);
172 if (m != null) {
173 assert lookupSubstitute(m) == null : String.format("multiple matches found for %s:%n%s%n%s", this, m, lookupSubstitute(m));
174 return m;
175 }
176 throw new GraalError("No method found specified by %s", this);
177 }
178
179 @Override
180 public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver) {
181 if (IS_IN_NATIVE_IMAGE) {
182 // these are currently unimplemented
183 return false;
184 }
185 ResolvedJavaMethod subst = getSubstitute(b.getMetaAccess());
186 return b.intrinsify(bytecodeProvider, targetMethod, subst, receiver, argsIncludingReceiver);
187 }
188
189 @Override
190 public StackTraceElement getApplySourceLocation(MetaAccessProvider metaAccess) {
191 Class<?> c = getClass();
192 for (Method m : c.getDeclaredMethods()) {
193 if (m.getName().equals("execute")) {
194 return metaAccess.lookupJavaMethod(m).asStackTraceElement(0);
195 }
196 }
197 throw new GraalError("could not find method named \"execute\" in " + c.getName());
198 }
199
200 @Override
201 public String toString() {
202 return String.format("%s[%s.%s(%s)]", getClass().getSimpleName(), declaringClass.getName(), name,
203 Arrays.asList(parameters).stream().map(c -> c.getTypeName()).collect(Collectors.joining(", ")));
204 }
|