changeset 10937:87d9b5518065

Move VerifyUsageWithEquals phases into HighTier.
author Roland Schatz <roland.schatz@oracle.com>
date Fri, 02 Aug 2013 11:22:23 +0200
parents 963a090eb1d8
children 4c648c43150c f22cbff51c12
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java
diffstat 5 files changed, 30 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Fri Aug 02 11:05:19 2013 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Fri Aug 02 11:22:23 2013 +0200
@@ -40,25 +40,18 @@
 import com.oracle.graal.nodes.cfg.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.util.*;
-import com.oracle.graal.options.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.PhasePlan.PhasePosition;
 import com.oracle.graal.phases.common.*;
 import com.oracle.graal.phases.graph.*;
 import com.oracle.graal.phases.schedule.*;
 import com.oracle.graal.phases.tiers.*;
-import com.oracle.graal.phases.verify.*;
 
 /**
  * Static methods for orchestrating the compilation of a {@linkplain StructuredGraph graph}.
  */
 public class GraalCompiler {
 
-    // @formatter:off
-    @Option(help = "")
-    public static final OptionValue<Boolean> VerifyUsageWithEquals = new OptionValue<>(true);
-    // @formatter:on
-
     /**
      * Requests compilation of a given graph.
      * 
@@ -135,10 +128,6 @@
         } else {
             Debug.dump(graph, "initial state");
         }
-        if (VerifyUsageWithEquals.getValue()) {
-            new VerifyUsageWithEquals(runtime, Value.class).apply(graph);
-            new VerifyUsageWithEquals(runtime, Register.class).apply(graph);
-        }
 
         HighTierContext highTierContext = new HighTierContext(runtime, assumptions, replacements, cache, plan, optimisticOpts);
         suites.getHighTier().apply(graph, highTierContext);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java	Fri Aug 02 11:05:19 2013 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java	Fri Aug 02 11:22:23 2013 +0200
@@ -24,17 +24,22 @@
 
 import static com.oracle.graal.phases.GraalOptions.*;
 
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.loop.phases.*;
 import com.oracle.graal.nodes.spi.Lowerable.LoweringType;
 import com.oracle.graal.options.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.common.*;
 import com.oracle.graal.phases.tiers.*;
+import com.oracle.graal.phases.verify.*;
 import com.oracle.graal.virtual.phases.ea.*;
 
 public class HighTier extends PhaseSuite<HighTierContext> {
 
     // @formatter:off
+    @Option(help = "")
+    public static final OptionValue<Boolean> VerifyUsageWithEquals = new OptionValue<>(true);
     @Option(help = "Enable inlining")
     public static final OptionValue<Boolean> Inline = new OptionValue<>(true);
     // @formatter:on
@@ -42,6 +47,11 @@
     public HighTier() {
         CanonicalizerPhase canonicalizer = new CanonicalizerPhase(!AOTCompilation.getValue());
 
+        if (VerifyUsageWithEquals.getValue()) {
+            appendPhase(new VerifyUsageWithEquals(Value.class));
+            appendPhase(new VerifyUsageWithEquals(Register.class));
+        }
+
         if (OptCanonicalizer.getValue()) {
             appendPhase(canonicalizer);
         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java	Fri Aug 02 11:05:19 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java	Fri Aug 02 11:22:23 2013 +0200
@@ -25,6 +25,7 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.tiers.*;
 
 /**
  * Checks for illegal object constants in a graph processed for AOT compilation. The only legal
@@ -33,10 +34,10 @@
  * 
  * @see LoadJavaMirrorWithKlassPhase
  */
-public class AheadOfTimeVerificationPhase extends VerifyPhase {
+public class AheadOfTimeVerificationPhase extends VerifyPhase<PhaseContext> {
 
     @Override
-    protected boolean verify(StructuredGraph graph) {
+    protected boolean verify(StructuredGraph graph, PhaseContext context) {
         for (ConstantNode node : graph.getNodes().filter(ConstantNode.class)) {
             assert !isObject(node) || isNullReference(node) || isInternedString(node) : "illegal object constant: " + node;
         }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java	Fri Aug 02 11:05:19 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java	Fri Aug 02 11:22:23 2013 +0200
@@ -26,16 +26,16 @@
 
 /***
  * This phase serves as a verification, in order to check the graph for certain properties. The
- * {@link #verify(StructuredGraph)} method will be used as an assertion, and implements the actual
- * check. Instead of returning false, it is also valid to throw an {@link AssertionError} in the
- * implemented {@link #verify(StructuredGraph)} method.
+ * {@link #verify(StructuredGraph, Object)} method will be used as an assertion, and implements the
+ * actual check. Instead of returning false, it is also valid to throw an {@link AssertionError} in
+ * the implemented {@link #verify(StructuredGraph, Object)} method.
  */
-public abstract class VerifyPhase extends Phase {
+public abstract class VerifyPhase<C> extends BasePhase<C> {
 
     @Override
-    protected final void run(StructuredGraph graph) {
-        assert verify(graph);
+    protected final void run(StructuredGraph graph, C context) {
+        assert verify(graph, context);
     }
 
-    protected abstract boolean verify(StructuredGraph graph);
+    protected abstract boolean verify(StructuredGraph graph, C context);
 }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java	Fri Aug 02 11:05:19 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java	Fri Aug 02 11:22:23 2013 +0200
@@ -27,23 +27,22 @@
 import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.type.*;
 import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.tiers.*;
 
 /**
  * For certain types object identity should not be used for object equality check. This phase checks
  * the correct usage of the given type. Equality checks with == or != (except null checks) results
  * in an {@link AssertionError}.
  */
-public class VerifyUsageWithEquals extends VerifyPhase {
+public class VerifyUsageWithEquals extends VerifyPhase<PhaseContext> {
 
-    private MetaAccessProvider runtime;
-    private Class<?> klass;
+    private final Class<?> klass;
 
-    public VerifyUsageWithEquals(MetaAccessProvider runtime, Class<?> klass) {
-        this.runtime = runtime;
+    public VerifyUsageWithEquals(Class<?> klass) {
         this.klass = klass;
     }
 
-    private boolean isAssignableType(ValueNode node) {
+    private boolean isAssignableType(ValueNode node, MetaAccessProvider runtime) {
         if (node.stamp() instanceof ObjectStamp) {
             ResolvedJavaType valueType = runtime.lookupJavaType(klass);
             ResolvedJavaType nodeType = node.objectStamp().type();
@@ -59,8 +58,8 @@
         return node.isConstant() && node.asConstant().isNull();
     }
 
-    private boolean checkUsage(ValueNode x, ValueNode y) {
-        return isAssignableType(x) && !isNullConstant(y);
+    private boolean checkUsage(ValueNode x, ValueNode y, MetaAccessProvider runtime) {
+        return isAssignableType(x, runtime) && !isNullConstant(y);
     }
 
     private static boolean isEqualsMethod(StructuredGraph graph) {
@@ -69,12 +68,12 @@
     }
 
     @Override
-    protected boolean verify(StructuredGraph graph) {
+    protected boolean verify(StructuredGraph graph, PhaseContext context) {
         for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
             if (!isEqualsMethod(graph)) {
                 // bail out if we compare an object of type klass with == or != (except null checks)
-                assert !(checkUsage(cn.x(), cn.y()) && checkUsage(cn.y(), cn.x())) : "Verifcation of " + klass.getName() + " usage failed: Comparing " + cn.x() + " and" + cn.y() + " in " +
-                                graph.method() + " must use .equals() for object equality, not '==' or '!='";
+                assert !(checkUsage(cn.x(), cn.y(), context.getRuntime()) && checkUsage(cn.y(), cn.x(), context.getRuntime())) : "Verifcation of " + klass.getName() + " usage failed: Comparing " +
+                                cn.x() + " and" + cn.y() + " in " + graph.method() + " must use .equals() for object equality, not '==' or '!='";
             }
         }
         return true;