changeset 18371:837e4c31f9d8

Make GraphMaker a static inner class to allow subclassing it independently from ReplacementsImpl
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 13 Nov 2014 14:30:15 -0800
parents 6713fef8c859
children 18b19a6f9851
files graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java
diffstat 1 files changed, 28 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Thu Nov 13 14:23:56 2014 -0800
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Thu Nov 13 14:30:15 2014 -0800
@@ -61,10 +61,10 @@
 
 public class ReplacementsImpl implements Replacements {
 
-    protected final Providers providers;
-    protected final SnippetReflectionProvider snippetReflection;
-    protected final TargetDescription target;
-    protected final Assumptions assumptions;
+    public final Providers providers;
+    public final SnippetReflectionProvider snippetReflection;
+    public final TargetDescription target;
+    public final Assumptions assumptions;
 
     /**
      * The preprocessed replacement graphs.
@@ -419,7 +419,7 @@
      * Can be overridden to return an object that specializes various parts of graph preprocessing.
      */
     protected GraphMaker createGraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original, FrameStateProcessing frameStateProcessing) {
-        return new GraphMaker(substitute, original, frameStateProcessing);
+        return new GraphMaker(this, substitute, original, frameStateProcessing);
     }
 
     /**
@@ -450,7 +450,10 @@
     /**
      * Creates and preprocesses a graph for a replacement.
      */
-    protected class GraphMaker {
+    public static class GraphMaker {
+        /** The replacements object that the graphs are created for. */
+        protected final ReplacementsImpl replacements;
+
         /**
          * The method for which a graph is being created.
          */
@@ -468,7 +471,8 @@
          */
         private FrameStateProcessing frameStateProcessing;
 
-        protected GraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod substitutedMethod, FrameStateProcessing frameStateProcessing) {
+        protected GraphMaker(ReplacementsImpl replacements, ResolvedJavaMethod substitute, ResolvedJavaMethod substitutedMethod, FrameStateProcessing frameStateProcessing) {
+            this.replacements = replacements;
             this.method = substitute;
             this.substitutedMethod = substitutedMethod;
             this.frameStateProcessing = frameStateProcessing;
@@ -495,7 +499,7 @@
          * Does final processing of a snippet graph.
          */
         protected void finalizeGraph(StructuredGraph graph) {
-            createNodeIntrinsificationPhase().apply(graph);
+            replacements.createNodeIntrinsificationPhase().apply(graph);
             if (!SnippetTemplate.hasConstantParameter(method)) {
                 NodeIntrinsificationVerificationPhase.verify(graph);
             }
@@ -535,7 +539,7 @@
                         if (callTarget instanceof MethodCallTargetNode) {
                             ResolvedJavaMethod targetMethod = ((MethodCallTargetNode) callTarget).targetMethod();
                             if (targetMethod.isConstructor()) {
-                                ResolvedJavaType throwableType = providers.getMetaAccess().lookupJavaType(Throwable.class);
+                                ResolvedJavaType throwableType = replacements.providers.getMetaAccess().lookupJavaType(Throwable.class);
                                 return !throwableType.isAssignableFrom(targetMethod.getDeclaringClass());
                             }
                         }
@@ -551,17 +555,17 @@
         private static final int MAX_GRAPH_INLINING_DEPTH = 100; // more than enough
 
         private StructuredGraph parseGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy, int inliningDepth) {
-            StructuredGraph graph = graphCache.get(methodToParse);
+            StructuredGraph graph = replacements.graphCache.get(methodToParse);
             if (graph == null) {
                 StructuredGraph newGraph = null;
                 try (Scope s = Debug.scope("ParseGraph", methodToParse)) {
-                    newGraph = buildGraph(methodToParse, policy == null ? inliningPolicy(methodToParse) : policy, inliningDepth);
+                    newGraph = buildGraph(methodToParse, policy == null ? replacements.inliningPolicy(methodToParse) : policy, inliningDepth);
                 } catch (Throwable e) {
                     throw Debug.handle(e);
                 }
 
-                graphCache.putIfAbsent(methodToParse, newGraph);
-                graph = graphCache.get(methodToParse);
+                replacements.graphCache.putIfAbsent(methodToParse, newGraph);
+                graph = replacements.graphCache.get(methodToParse);
                 assert graph != null;
             }
             return graph;
@@ -573,7 +577,7 @@
         protected StructuredGraph buildInitialGraph(final ResolvedJavaMethod methodToParse) {
             final StructuredGraph graph = new StructuredGraph(methodToParse);
             try (Scope s = Debug.scope("buildInitialGraph", graph)) {
-                MetaAccessProvider metaAccess = providers.getMetaAccess();
+                MetaAccessProvider metaAccess = replacements.providers.getMetaAccess();
 
                 if (MethodsElidedInSnippets != null && methodToParse.getSignature().getReturnKind() == Kind.Void && MethodFilter.matches(MethodsElidedInSnippets, methodToParse)) {
                     graph.addAfterFixed(graph.start(), graph.add(ReturnNode.create(null)));
@@ -581,11 +585,9 @@
                     createGraphBuilder(metaAccess, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.NONE).apply(graph);
                 }
                 afterParsing(graph);
-                new WordTypeVerificationPhase(metaAccess, snippetReflection, target.wordKind).apply(graph);
-                new WordTypeRewriterPhase(metaAccess, snippetReflection, target.wordKind).apply(graph);
 
                 if (OptCanonicalizer.getValue()) {
-                    new CanonicalizerPhase(true).apply(graph, new PhaseContext(providers, assumptions));
+                    new CanonicalizerPhase(true).apply(graph, new PhaseContext(replacements.providers, replacements.assumptions));
                 }
             } catch (Throwable e) {
                 throw Debug.handle(e);
@@ -597,7 +599,10 @@
             return new GraphBuilderPhase.Instance(metaAccess, graphBuilderConfig, optimisticOpts);
         }
 
-        protected void afterParsing(@SuppressWarnings("unused") StructuredGraph graph) {
+        protected void afterParsing(StructuredGraph graph) {
+            MetaAccessProvider metaAccess = replacements.providers.getMetaAccess();
+            new WordTypeVerificationPhase(metaAccess, replacements.snippetReflection, replacements.target.wordKind).apply(graph);
+            new WordTypeRewriterPhase(metaAccess, replacements.snippetReflection, replacements.target.wordKind).apply(graph);
         }
 
         protected Object beforeInline(@SuppressWarnings("unused") MethodCallTargetNode callTarget, @SuppressWarnings("unused") StructuredGraph callee) {
@@ -613,7 +618,7 @@
          */
         protected void afterInline(StructuredGraph caller, StructuredGraph callee, Object beforeInlineData) {
             if (OptCanonicalizer.getValue()) {
-                new CanonicalizerPhase(true).apply(caller, new PhaseContext(providers, assumptions));
+                new CanonicalizerPhase(true).apply(caller, new PhaseContext(replacements.providers, replacements.assumptions));
             }
         }
 
@@ -621,10 +626,10 @@
          * Called after all inlining for a given graph is complete.
          */
         protected void afterInlining(StructuredGraph graph) {
-            createNodeIntrinsificationPhase().apply(graph);
+            replacements.createNodeIntrinsificationPhase().apply(graph);
             new DeadCodeEliminationPhase(Optional).apply(graph);
             if (OptCanonicalizer.getValue()) {
-                new CanonicalizerPhase(true).apply(graph, new PhaseContext(providers, assumptions));
+                new CanonicalizerPhase(true).apply(graph, new PhaseContext(replacements.providers, replacements.assumptions));
             }
         }
 
@@ -662,11 +667,11 @@
                             afterInline(graph, originalGraph, null);
                         }
                     } else {
-                        Class<? extends FixedWithNextNode> macroNodeClass = InliningUtil.getMacroNodeClass(ReplacementsImpl.this, callee);
+                        Class<? extends FixedWithNextNode> macroNodeClass = InliningUtil.getMacroNodeClass(replacements, callee);
                         if (macroNodeClass != null) {
                             InliningUtil.inlineMacroNode(callTarget.invoke(), callee, macroNodeClass);
                         } else {
-                            StructuredGraph intrinsicGraph = InliningUtil.getIntrinsicGraph(ReplacementsImpl.this, callee);
+                            StructuredGraph intrinsicGraph = InliningUtil.getIntrinsicGraph(replacements, callee);
                             if ((callTarget.invokeKind() == InvokeKind.Static || callTarget.invokeKind() == InvokeKind.Special) &&
                                             (policy.shouldInline(callee, methodToParse) || (intrinsicGraph != null && policy.shouldUseReplacement(callee, methodToParse)))) {
                                 StructuredGraph targetGraph;