# HG changeset patch # User Doug Simon # Date 1428526388 -7200 # Node ID 74f8a2ec0844c355ec078762af8fd29840648e71 # Parent ac9d0db0716e16efb47273d44cf5ad37c1e237cb generalized MathRuntimeCallPlugin to ForeignCallPlugin diff -r ac9d0db0716e -r 74f8a2ec0844 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/ForeignCallPlugin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/ForeignCallPlugin.java Wed Apr 08 22:53:08 2015 +0200 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.graphbuilderconf; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graphbuilderconf.InvocationPlugins.Receiver; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; + +/** + * {@link InvocationPlugin} for converting a method call directly to a foreign call. + */ +public final class ForeignCallPlugin implements InvocationPlugin { + private final ForeignCallsProvider foreignCalls; + private final ForeignCallDescriptor descriptor; + + public ForeignCallPlugin(ForeignCallsProvider foreignCalls, ForeignCallDescriptor descriptor) { + this.foreignCalls = foreignCalls; + this.descriptor = descriptor; + } + + public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode[] args) { + b.addPush(new ForeignCallNode(foreignCalls, descriptor, args)); + return true; + } +} diff -r ac9d0db0716e -r 74f8a2ec0844 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Wed Apr 08 22:28:23 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Wed Apr 08 22:53:08 2015 +0200 @@ -421,6 +421,9 @@ } public static boolean check(InvocationPlugins plugins, MethodInfo method, InvocationPlugin plugin) { + if (plugin instanceof ForeignCallPlugin) { + return true; + } if (plugin instanceof MethodSubstitutionPlugin) { MethodSubstitutionPlugin msplugin = (MethodSubstitutionPlugin) plugin; msplugin.getJavaSubstitute(); diff -r ac9d0db0716e -r 74f8a2ec0844 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodSubstitutionPlugin.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodSubstitutionPlugin.java Wed Apr 08 22:28:23 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodSubstitutionPlugin.java Wed Apr 08 22:53:08 2015 +0200 @@ -38,7 +38,7 @@ * {@linkplain #getSubstitute(MetaAccessProvider) substitute} method. A substitute method must be * static even if the substituted method is not. */ -public class MethodSubstitutionPlugin implements InvocationPlugin { +public final class MethodSubstitutionPlugin implements InvocationPlugin { private ResolvedJavaMethod cachedSubstitute; private final Class declaringClass; diff -r ac9d0db0716e -r 74f8a2ec0844 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Wed Apr 08 22:28:23 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Wed Apr 08 22:53:08 2015 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.meta; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.hotspot.replacements.SystemSubstitutions.*; import java.lang.invoke.*; @@ -31,9 +32,8 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; -import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Receiver; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; import com.oracle.graal.hotspot.*; @@ -163,18 +163,8 @@ private static void registerSystemPlugins(InvocationPlugins plugins, ForeignCallsProvider foreignCalls) { Registration r = new Registration(plugins, System.class); - r.register0("currentTimeMillis", new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - b.addPush(Kind.Long, new ForeignCallNode(foreignCalls, SystemSubstitutions.JAVA_TIME_MILLIS, StampFactory.forKind(Kind.Long))); - return true; - } - }); - r.register0("nanoTime", new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - b.addPush(Kind.Long, new ForeignCallNode(foreignCalls, SystemSubstitutions.JAVA_TIME_NANOS, StampFactory.forKind(Kind.Long))); - return true; - } - }); + r.register0("currentTimeMillis", new ForeignCallPlugin(foreignCalls, JAVA_TIME_MILLIS)); + r.register0("nanoTime", new ForeignCallPlugin(foreignCalls, JAVA_TIME_NANOS)); r.register1("identityHashCode", Object.class, new InvocationPlugin() { public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { b.addPush(new SystemIdentityHashCodeNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnType(), object)); diff -r ac9d0db0716e -r 74f8a2ec0844 graal/com.oracle.graal.replacements.sparc/src/com/oracle/graal/replacements/sparc/SPARCGraphBuilderPlugins.java --- a/graal/com.oracle.graal.replacements.sparc/src/com/oracle/graal/replacements/sparc/SPARCGraphBuilderPlugins.java Wed Apr 08 22:28:23 2015 +0200 +++ b/graal/com.oracle.graal.replacements.sparc/src/com/oracle/graal/replacements/sparc/SPARCGraphBuilderPlugins.java Wed Apr 08 22:53:08 2015 +0200 @@ -28,10 +28,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.graphbuilderconf.*; -import com.oracle.graal.graphbuilderconf.InvocationPlugins.Receiver; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; import com.oracle.graal.replacements.*; public class SPARCGraphBuilderPlugins { @@ -51,31 +48,11 @@ r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type); } - static class MathRuntimeCallPlugin implements InvocationPlugin { - private final ForeignCallsProvider foreignCalls; - private final ForeignCallDescriptor descriptor; - - public MathRuntimeCallPlugin(ForeignCallsProvider foreignCalls, ForeignCallDescriptor descriptor) { - this.foreignCalls = foreignCalls; - this.descriptor = descriptor; - } - - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { - b.addPush(new ForeignCallNode(foreignCalls, descriptor, value)); - return true; - } - - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.addPush(new ForeignCallNode(foreignCalls, descriptor, x, y)); - return true; - } - } - private static void registerMathPlugins(InvocationPlugins plugins, ForeignCallsProvider foreignCalls) { Registration r = new Registration(plugins, Math.class); - r.register1("sin", Double.TYPE, new MathRuntimeCallPlugin(foreignCalls, ARITHMETIC_SIN)); - r.register1("cos", Double.TYPE, new MathRuntimeCallPlugin(foreignCalls, ARITHMETIC_COS)); - r.register1("tan", Double.TYPE, new MathRuntimeCallPlugin(foreignCalls, ARITHMETIC_TAN)); - r.register2("pow", Double.TYPE, Double.TYPE, new MathRuntimeCallPlugin(foreignCalls, ARITHMETIC_POW)); + r.register1("sin", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_SIN)); + r.register1("cos", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_COS)); + r.register1("tan", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_TAN)); + r.register2("pow", Double.TYPE, Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_POW)); } }