changeset 15984:114ca0838327

[inlining] made explicit an invariant of InliningData
author Miguel Garcia <miguel.m.garcia@oracle.com>
date Fri, 30 May 2014 17:01:37 +0200
parents 1fbefda059a6
children 85fa16055535
files graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java
diffstat 2 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java	Thu May 29 16:35:01 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java	Fri May 30 17:01:37 2014 +0200
@@ -140,8 +140,10 @@
     protected void run(final StructuredGraph graph, final HighTierContext context) {
         final InliningData data = new InliningData(graph, context, maxMethodPerInlining, canonicalizer, inliningPolicy);
 
+        assert data.repOK();
         while (data.hasUnprocessedGraphs()) {
             boolean wasInlined = data.moveForward();
+            assert data.repOK();
             if (wasInlined) {
                 inliningCount++;
             }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java	Thu May 29 16:35:01 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java	Fri May 30 17:01:37 2014 +0200
@@ -610,4 +610,48 @@
 
         return false;
     }
+
+    /**
+     * This method checks an invariant that {@link #moveForward()} must maintain: "the top
+     * invocation records how many concrete target methods (for it) remain on the
+     * {@link #graphQueue}; those targets 'belong' to the current invocation in question."
+     */
+    private boolean topGraphsForTopInvocation() {
+        if (invocationQueue.isEmpty()) {
+            assert graphQueue.isEmpty();
+            return true;
+        }
+        if (currentInvocation().isRoot()) {
+            if (!graphQueue.isEmpty()) {
+                assert graphQueue.size() == 1;
+            }
+            return true;
+        }
+        final int remainingGraphs = currentInvocation().totalGraphs() - currentInvocation().processedGraphs();
+        final Iterator<CallsiteHolder> iter = graphQueue.iterator();
+        for (int i = (remainingGraphs - 1); i >= 0; i--) {
+            if (!iter.hasNext()) {
+                assert false;
+                return false;
+            }
+            CallsiteHolder queuedTargetCH = iter.next();
+            Inlineable targetIE = currentInvocation().callee().inlineableElementAt(i);
+            if (targetIE instanceof InlineableMacroNode) {
+                assert queuedTargetCH == DUMMY_CALLSITE_HOLDER;
+            } else {
+                InlineableGraph targetIG = (InlineableGraph) targetIE;
+                assert queuedTargetCH.method().equals(targetIG.getGraph().method());
+            }
+        }
+        return true;
+    }
+
+    /**
+     * This method checks invariants for this class. Named after shorthand for
+     * "internal representation is ok".
+     */
+    public boolean repOK() {
+        assert topGraphsForTopInvocation();
+        return true;
+    }
 }