# HG changeset patch # User Doug Simon # Date 1432631990 -7200 # Node ID f4b3a6dadb446c41361d56189238f1c3483aafbf # Parent 78f0792aa8901c9de8a5bc7ec5d23e1a15575d8b moved Receiver inner class from MethodIdMap to InvocationPlugin (JBS:GRAAL-53) diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue May 26 11:19:50 2015 +0200 @@ -49,7 +49,6 @@ import com.oracle.graal.graph.*; import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.java.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.phases.*; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/ForeignCallPlugin.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/ForeignCallPlugin.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/ForeignCallPlugin.java Tue May 26 11:19:50 2015 +0200 @@ -24,7 +24,6 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; @@ -40,7 +39,7 @@ this.descriptor = descriptor; } - public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode[] args) { + public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) { ForeignCallNode foreignCall = new ForeignCallNode(foreignCalls, descriptor, args); foreignCall.setBci(b.bci()); b.addPush(foreignCall); diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugin.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugin.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugin.java Tue May 26 11:19:50 2015 +0200 @@ -26,8 +26,8 @@ import java.lang.reflect.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; import com.oracle.jvmci.common.*; /** @@ -36,6 +36,28 @@ public interface InvocationPlugin extends GraphBuilderPlugin { /** + * The receiver in a non-static method. The class literal for this interface must be used with + * {@link MethodIdMap#put(Object, boolean, Class, String, Class...)} to denote the receiver + * argument for such a non-static method. + */ + public interface Receiver { + /** + * Gets the receiver value, null checking it first if necessary. + * + * @return the receiver value with a {@linkplain StampTool#isPointerNonNull(ValueNode) + * non-null} stamp + */ + ValueNode get(); + + /** + * Determines if the receiver is constant. + */ + default boolean isConstant() { + return false; + } + } + + /** * Determines if this plugin is for a method with a polymorphic signature (e.g. * {@link MethodHandle#invokeExact(Object...)}). */ @@ -59,49 +81,49 @@ * position 0 if {@code targetMethod} is not static * @see #execute */ - default boolean applyPolymorphic(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode... argsIncludingReceiver) { + default boolean applyPolymorphic(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode... argsIncludingReceiver) { return defaultHandler(b, targetMethod, receiver, argsIncludingReceiver); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver) { return defaultHandler(b, targetMethod, receiver); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg) { return defaultHandler(b, targetMethod, receiver, arg); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg1, ValueNode arg2) { return defaultHandler(b, targetMethod, receiver, arg1, arg2); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3) { return defaultHandler(b, targetMethod, receiver, arg1, arg2, arg3); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4) { return defaultHandler(b, targetMethod, receiver, arg1, arg2, arg3, arg4); } /** * @see #execute */ - default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4, ValueNode arg5) { + default boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4, ValueNode arg5) { return defaultHandler(b, targetMethod, receiver, arg1, arg2, arg3, arg4, arg5); } @@ -121,7 +143,7 @@ * inlining it or creating an {@link Invoke} node). A plugin that does not handle an * invocation must not modify the graph being constructed. */ - default boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode[] argsIncludingReceiver) { + default boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver) { if (isSignaturePolymorphic()) { return applyPolymorphic(b, targetMethod, receiver, argsIncludingReceiver); } else if (receiver != null) { @@ -164,7 +186,8 @@ /** * Handles an invocation when a specific {@code apply} method is not available. */ - default boolean defaultHandler(@SuppressWarnings("unused") GraphBuilderContext b, ResolvedJavaMethod targetMethod, @SuppressWarnings("unused") Receiver receiver, ValueNode... args) { + default boolean defaultHandler(@SuppressWarnings("unused") GraphBuilderContext b, ResolvedJavaMethod targetMethod, @SuppressWarnings("unused") InvocationPlugin.Receiver receiver, + ValueNode... args) { throw new JVMCIError("Invocation plugin for %s does not handle invocations with %d arguments", targetMethod.format("%H.%n(%p)"), args.length); } diff -r 78f0792aa890 -r f4b3a6dadb44 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 Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Tue May 26 11:19:50 2015 +0200 @@ -31,7 +31,6 @@ import com.oracle.graal.graph.*; import com.oracle.graal.graph.iterators.*; import com.oracle.graal.graphbuilderconf.MethodIdMap.MethodKey; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.nodes.*; /** @@ -39,7 +38,7 @@ */ public class InvocationPlugins { - public static class InvocationPluginReceiver implements Receiver { + public static class InvocationPluginReceiver implements InvocationPlugin.Receiver { private final GraphBuilderContext parser; private ValueNode[] args; private ValueNode value; @@ -163,7 +162,9 @@ * * @param substituteDeclaringClass the class declaring the substitute method * @param name the name of both the original and substitute method - * @param argumentTypes the parameter types of the substitute + * @param argumentTypes the argument types of the method. Element 0 of this array must be + * the {@link Class} value for {@link InvocationPlugin.Receiver} iff the method is non-static. + * Upon returning, element 0 will have been rewritten to {@code declaringClass} */ public void registerMethodSubstitution(Class substituteDeclaringClass, String name, Class... argumentTypes) { MethodSubstitutionPlugin plugin = new MethodSubstitutionPlugin(substituteDeclaringClass, name, argumentTypes); @@ -203,9 +204,17 @@ /** * Registers an invocation plugin for a given method. There must be no plugin currently * registered for {@code method}. + * + * @param argumentTypes the argument types of the method. Element 0 of this array must be the + * {@link Class} value for {@link InvocationPlugin.Receiver} iff the method is non-static. Upon + * returning, element 0 will have been rewritten to {@code declaringClass} */ public void register(InvocationPlugin plugin, Class declaringClass, String name, Class... argumentTypes) { - MethodKey methodInfo = plugins.put(plugin, declaringClass, name, argumentTypes); + boolean isStatic = argumentTypes.length == 0 || argumentTypes[0] != InvocationPlugin.Receiver.class; + if (!isStatic) { + argumentTypes[0] = declaringClass; + } + MethodKey methodInfo = plugins.put(plugin, isStatic, declaringClass, name, argumentTypes); assert Checker.check(this, methodInfo, plugin); } @@ -260,7 +269,7 @@ Class[] sig = method.getParameterTypes(); assert sig[0] == GraphBuilderContext.class; assert sig[1] == ResolvedJavaMethod.class; - assert sig[2] == Receiver.class; + assert sig[2] == InvocationPlugin.Receiver.class; assert Arrays.asList(Arrays.copyOfRange(sig, 3, sig.length)).stream().allMatch(c -> c == ValueNode.class); while (sigs.size() < sig.length - 2) { sigs.add(null); diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java --- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java Tue May 26 11:19:50 2015 +0200 @@ -29,8 +29,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.graphbuilderconf.MethodIdHolder.MethodIdAllocator; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.type.*; import com.oracle.jvmci.common.*; /** @@ -47,28 +45,6 @@ public class MethodIdMap { /** - * The receiver in a non-static method. The class literal for this interface must be used with - * {@link MethodIdMap#put(Object, Class, String, Class...)} to denote the receiver argument for - * such a non-static method. - */ - public interface Receiver { - /** - * Gets the receiver value, null checking it first if necessary. - * - * @return the receiver value with a {@linkplain StampTool#isPointerNonNull(ValueNode) - * non-null} stamp - */ - ValueNode get(); - - /** - * Determines if the receiver is constant. - */ - default boolean isConstant() { - return false; - } - } - - /** * Key for a method. */ public static class MethodKey { @@ -79,15 +55,13 @@ final T value; int id; - MethodKey(T data, Class declaringClass, String name, Class... argumentTypes) { + MethodKey(T data, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { + assert isStatic || argumentTypes[0] == declaringClass; this.value = data; - this.isStatic = argumentTypes.length == 0 || argumentTypes[0] != Receiver.class; + this.isStatic = isStatic; this.declaringClass = declaringClass; this.name = name; this.argumentTypes = argumentTypes; - if (!isStatic) { - argumentTypes[0] = declaringClass; - } assert resolveJava() != null; } @@ -171,14 +145,16 @@ * Adds an entry to this map for a specified method. * * @param value value to be associated with the specified method + * @param isStatic specifies if the method is static * @param declaringClass the class declaring the method * @param name the name of the method - * @param argumentTypes the argument types of the method. Element 0 of this array must be the - * {@link Class} value for {@link Receiver} iff the method is non-static. + * @param argumentTypes the argument types of the method. Element 0 of this array must be + * {@code declaringClass} iff the method is non-static. * @return an object representing the method */ - public MethodKey put(V value, Class declaringClass, String name, Class... argumentTypes) { - MethodKey methodKey = new MethodKey<>(value, declaringClass, name, argumentTypes); + public MethodKey put(V value, boolean isStatic, Class declaringClass, String name, Class... argumentTypes) { + assert isStatic || argumentTypes[0] == declaringClass; + MethodKey methodKey = new MethodKey<>(value, isStatic, declaringClass, name, argumentTypes); assert entries == null : "registration is closed"; assert !registrations.contains(methodKey) : "a value is already registered for " + methodKey; registrations.add(methodKey); diff -r 78f0792aa890 -r f4b3a6dadb44 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 Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodSubstitutionPlugin.java Tue May 26 11:19:50 2015 +0200 @@ -29,7 +29,6 @@ import sun.misc.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.nodes.*; import com.oracle.jvmci.common.*; @@ -66,13 +65,13 @@ * @param name the name of the substitute method * @param parameters the parameter types of the substitute method. If the original method is not * static, then {@code parameters[0]} must be the {@link Class} value denoting - * {@link Receiver} + * {@link InvocationPlugin.Receiver} */ public MethodSubstitutionPlugin(Class declaringClass, String name, Class... parameters) { this.declaringClass = declaringClass; this.name = name; this.parameters = parameters; - this.originalIsStatic = parameters.length == 0 || parameters[0] != Receiver.class; + this.originalIsStatic = parameters.length == 0 || parameters[0] != InvocationPlugin.Receiver.class; } /** @@ -178,7 +177,7 @@ } @Override - public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode[] argsIncludingReceiver) { + public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver) { ResolvedJavaMethod subst = getSubstitute(b.getMetaAccess()); if (receiver != null) { receiver.get(); diff -r 78f0792aa890 -r f4b3a6dadb44 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 Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Tue May 26 11:19:50 2015 +0200 @@ -36,7 +36,7 @@ import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; +import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver; import com.oracle.graal.hotspot.jvmci.*; import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.hotspot.replacements.*; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java --- a/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/LIRTest.java Tue May 26 11:19:50 2015 +0200 @@ -31,7 +31,6 @@ import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graphbuilderconf.*; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.jtt.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.nodeinfo.*; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java --- a/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64GraphBuilderPlugins.java Tue May 26 11:19:50 2015 +0200 @@ -32,7 +32,7 @@ import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; +import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.replacements.*; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/IntrinsicGraphBuilder.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/IntrinsicGraphBuilder.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/IntrinsicGraphBuilder.java Tue May 26 11:19:50 2015 +0200 @@ -26,7 +26,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graphbuilderconf.*; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; +import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver; import com.oracle.graal.nodes.CallTargetNode.InvokeKind; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Tue May 26 11:19:50 2015 +0200 @@ -37,7 +37,7 @@ import com.oracle.graal.graph.*; import com.oracle.graal.graphbuilderconf.*; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; +import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.debug.*; diff -r 78f0792aa890 -r f4b3a6dadb44 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Tue May 26 11:14:59 2015 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Tue May 26 11:19:50 2015 +0200 @@ -32,8 +32,8 @@ import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graphbuilderconf.*; +import com.oracle.graal.graphbuilderconf.InvocationPlugin.Receiver; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.graphbuilderconf.MethodIdMap.Receiver; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*;