changeset 14166:a0c31f940950

use AssertionError subclass for verification errors found by VerifyPhases
author Doug Simon <doug.simon@oracle.com>
date Thu, 13 Mar 2014 11:37:24 +0100
parents a1ddf86f5d79
children 37f7dfdbd25b
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.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, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java	Thu Mar 13 01:33:50 2014 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java	Thu Mar 13 11:37:24 2014 +0100
@@ -37,6 +37,7 @@
 import com.oracle.graal.java.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.VerifyPhase.VerificationError;
 import com.oracle.graal.phases.tiers.*;
 import com.oracle.graal.phases.util.*;
 import com.oracle.graal.phases.verify.*;
@@ -115,10 +116,12 @@
                             try (DebugConfigScope s = Debug.setConfig(noInterceptConfig)) {
                                 graphBuilderSuite.apply(graph, context);
                                 checkGraph(context, graph);
-                            } catch (AssertionError e) {
+                            } catch (VerificationError e) {
                                 errors.add(e.getMessage());
                             } catch (LinkageError e) {
                                 // suppress linkages errors resulting from eager resolution
+                            } catch (Throwable e) {
+                                throw new AssertionError("Error while checking " + methodName, e);
                             }
 
                         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java	Thu Mar 13 01:33:50 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java	Thu Mar 13 11:37:24 2014 +0100
@@ -42,7 +42,9 @@
     protected boolean verify(StructuredGraph graph, PhaseContext context) {
         for (ConstantNode node : getConstantNodes(graph)) {
             if (node.recordsUsages() || !node.gatherUsages(graph).isEmpty()) {
-                assert !isObject(node) || isNullReference(node) || isInternedString(node) : "illegal object constant: " + node;
+                if (isObject(node) && !isNullReference(node) && !isInternedString(node)) {
+                    throw new VerificationError("illegal object constant: " + node);
+                }
             }
         }
         return true;
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Thu Mar 13 01:33:50 2014 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Thu Mar 13 11:37:24 2014 +0100
@@ -825,7 +825,7 @@
              * calls). Also, interfaces are initialized only under special circumstances, so that
              * this assertion would often fail for interface calls.
              */
-            assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaMethod && (opcode != INVOKESTATIC || ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized()));
+            assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaMethod && (opcode != INVOKESTATIC || ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized())) : result;
             return result;
         }
 
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java	Thu Mar 13 01:33:50 2014 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java	Thu Mar 13 11:37:24 2014 +0100
@@ -27,15 +27,35 @@
 /***
  * This phase serves as a verification, in order to check the graph for certain properties. The
  * {@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.
+ * actual check. Instead of returning false, it is also valid to throw an {@link VerificationError}
+ * in the implemented {@link #verify(StructuredGraph, Object)} method.
  */
 public abstract class VerifyPhase<C> extends BasePhase<C> {
 
+    /**
+     * Thrown when verification performed by a {@link VerifyPhase} fails.
+     */
+    @SuppressWarnings("serial")
+    public static class VerificationError extends AssertionError {
+
+        public VerificationError(String message) {
+            super(message);
+        }
+
+        public VerificationError(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
     @Override
     protected final void run(StructuredGraph graph, C context) {
         assert verify(graph, context);
     }
 
+    /**
+     * Performs the actual verification.
+     * 
+     * @throws VerificationError if the verification fails
+     */
     protected abstract boolean verify(StructuredGraph graph, C context);
 }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java	Thu Mar 13 01:33:50 2014 +0100
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java	Thu Mar 13 11:37:24 2014 +0100
@@ -66,8 +66,10 @@
     protected boolean verify(StructuredGraph graph, PhaseContext context) {
         for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
             // bail out if we compare an object of type klass with == or != (except null checks)
-            assert !(checkUsage(cn.x(), cn.y(), context.getMetaAccess()) && checkUsage(cn.y(), cn.x(), context.getMetaAccess())) : "Verification of " + klass.getName() + " usage failed: Comparing " +
-                            cn.x() + " and " + cn.y() + " in " + graph.method() + " must use .equals() for object equality, not '==' or '!='";
+            if (checkUsage(cn.x(), cn.y(), context.getMetaAccess()) && checkUsage(cn.y(), cn.x(), context.getMetaAccess())) {
+                throw new VerificationError("Verification of " + klass.getName() + " usage failed: Comparing " + cn.x() + " and " + cn.y() + " in " + graph.method() +
+                                " must use .equals() for object equality, not '==' or '!='");
+            }
         }
         return true;
     }