changeset 18514:7a3bba33f2b7

added support for binding arguments of arbitrary types to parameters of a SubstitutionGuard constructor used above support to remove static access to HotSpotGraalRuntime from CRC32Substitutions.Guard
author Doug Simon <doug.simon@oracle.com>
date Wed, 26 Nov 2014 09:27:58 +0100
parents 62aac33db669
children 8b87897f5b42
files graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/SnippetReflectionProvider.java graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java
diffstat 6 files changed, 48 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/SnippetReflectionProvider.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/SnippetReflectionProvider.java	Wed Nov 26 09:27:58 2014 +0100
@@ -67,4 +67,13 @@
      * @return the value of the constant
      */
     Object asBoxedValue(JavaConstant constant);
+
+    /**
+     * Gets the value to bind to a parameter in a {@link SubstitutionGuard} constructor.
+     *
+     * @param type the type of a parameter in a {@link SubstitutionGuard} constructor
+     * @return the value that should be bound to the parameter when invoking the constructor or null
+     *         if this provider cannot provide a value of the requested type
+     */
+    Object getSubstitutionGuardParameter(Class<?> type);
 }
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java	Wed Nov 26 09:27:58 2014 +0100
@@ -157,7 +157,7 @@
             Assumptions assumptions = new Assumptions(false);
             Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, new HotSpotStampProvider());
             try (InitTimer rt = timer("create SnippetReflection provider")) {
-                snippetReflection = createSnippetReflection();
+                snippetReflection = createSnippetReflection(runtime);
             }
             try (InitTimer rt = timer("create Replacements provider")) {
                 replacements = createReplacements(runtime, assumptions, p, snippetReflection);
@@ -216,8 +216,8 @@
         return new HotSpotSuitesProvider(runtime);
     }
 
-    protected HotSpotSnippetReflectionProvider createSnippetReflection() {
-        return new HotSpotSnippetReflectionProvider();
+    protected HotSpotSnippetReflectionProvider createSnippetReflection(HotSpotGraalRuntime runtime) {
+        return new HotSpotSnippetReflectionProvider(runtime);
     }
 
     protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntime runtime, HotSpotMetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackendFactory.java	Wed Nov 26 09:27:58 2014 +0100
@@ -64,7 +64,7 @@
         // to be valid for the entire run of the VM.
         Assumptions assumptions = new Assumptions(false);
         Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, new HotSpotStampProvider());
-        HotSpotSnippetReflectionProvider snippetReflection = new HotSpotSnippetReflectionProvider();
+        HotSpotSnippetReflectionProvider snippetReflection = new HotSpotSnippetReflectionProvider(runtime);
         HotSpotReplacementsImpl replacements = new HotSpotReplacementsImpl(p, snippetReflection, runtime.getConfig(), assumptions, target);
         HotSpotDisassemblerProvider disassembler = new HotSpotDisassemblerProvider(runtime);
         HotSpotSuitesProvider suites = new HotSpotSuitesProvider(runtime);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java	Wed Nov 26 09:27:58 2014 +0100
@@ -24,9 +24,16 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.replacements.*;
+import com.oracle.graal.hotspot.*;
 
 public class HotSpotSnippetReflectionProvider implements SnippetReflectionProvider {
 
+    private final HotSpotGraalRuntime runtime;
+
+    public HotSpotSnippetReflectionProvider(HotSpotGraalRuntime runtime) {
+        this.runtime = runtime;
+    }
+
     @Override
     public JavaConstant forObject(Object object) {
         return HotSpotObjectConstantImpl.forObject(object);
@@ -46,4 +53,11 @@
     public Object asBoxedValue(JavaConstant constant) {
         return HotSpotObjectConstantImpl.asBoxedValue(constant);
     }
+
+    public Object getSubstitutionGuardParameter(Class<?> type) {
+        if (type.isInstance(runtime)) {
+            return runtime;
+        }
+        return null;
+    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CRC32Substitutions.java	Wed Nov 26 09:27:58 2014 +0100
@@ -31,6 +31,7 @@
 import com.oracle.graal.api.replacements.*;
 import com.oracle.graal.graph.Node.ConstantNodeParameter;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
+import com.oracle.graal.hotspot.*;
 import com.oracle.graal.hotspot.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.word.*;
@@ -42,8 +43,15 @@
 public class CRC32Substitutions {
 
     public static class Guard implements SubstitutionGuard {
+
+        private HotSpotGraalRuntime runtime;
+
+        public Guard(HotSpotGraalRuntime runtime) {
+            this.runtime = runtime;
+        }
+
         public boolean execute() {
-            return runtime().getConfig().useCRC32Intrinsics;
+            return runtime.getConfig().useCRC32Intrinsics;
         }
     }
 
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Wed Nov 26 01:06:38 2014 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Wed Nov 26 09:27:58 2014 +0100
@@ -313,17 +313,22 @@
             Class<?>[] paramTypes = constructor.getParameterTypes();
             // Check for supported constructor signatures
             try {
-                if (constructor.getParameterCount() == 1 && paramTypes[0] == Architecture.class) {
-                    // Guard(Architecture)
-                    return (SubstitutionGuard) constructor.newInstance(target.arch);
-                } else if (constructor.getParameterCount() == 0) {
-                    // Guard()
-                    return (SubstitutionGuard) constructor.newInstance();
+                Object[] args = new Object[constructor.getParameterCount()];
+                for (int i = 0; i < args.length; i++) {
+                    Object arg = snippetReflection.getSubstitutionGuardParameter(paramTypes[0]);
+                    if (arg != null) {
+                        args[i] = arg;
+                    } else if (paramTypes[0].isInstance(target.arch)) {
+                        args[i] = target.arch;
+                    } else {
+                        throw new GraalInternalError("Unsupported type %s in substitution guard constructor: %s", paramTypes[i].getName(), constructor);
+                    }
                 }
+
+                return (SubstitutionGuard) constructor.newInstance(args);
             } catch (Exception e) {
                 throw new GraalInternalError(e);
             }
-            throw new GraalInternalError("Unsupported constructor signature in substitution guard: " + constructor);
         }
         return null;
     }