changeset 16297:b9236eaecf4c

simplified DebugVerifyHandler API to be closer to DebugDumpHandler
author Doug Simon <doug.simon@oracle.com>
date Mon, 30 Jun 2014 17:23:56 +0200
parents f2d75b3b3963
children 3e4c83ac68d2
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugVerifyHandler.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java
diffstat 5 files changed, 41 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Mon Jun 30 15:43:25 2014 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Mon Jun 30 17:23:56 2014 +0200
@@ -90,7 +90,7 @@
      * Determines if verification is enabled in the current method, regardless of the
      * {@linkplain Debug#currentScope() current debug scope}.
      *
-     * @see Debug#verify(Object, Object)
+     * @see Debug#verify(Object, String)
      */
     public static boolean isVerifyEnabledForMethod() {
         if (!ENABLED) {
@@ -107,7 +107,7 @@
      * Determines if verification is enabled in the {@linkplain Debug#currentScope() current debug
      * scope}.
      *
-     * @see Debug#verify(Object, Object)
+     * @see Debug#verify(Object, String)
      */
     public static boolean isVerifyEnabled() {
         return ENABLED && DebugScope.getInstance().isVerifyEnabled();
@@ -491,13 +491,13 @@
      * config} to perform verification on a given object.
      *
      * @param object object to verify
-     * @param context object describing the context of verification
+     * @param message description of verification context
      *
-     * @see DebugVerifyHandler#verify(Object, Object...)
+     * @see DebugVerifyHandler#verify(Object, String)
      */
-    public static void verify(Object object, Object context) {
+    public static void verify(Object object, String message) {
         if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) {
-            DebugScope.getInstance().verify(object, context);
+            DebugScope.getInstance().verify(object, message);
         }
     }
 
@@ -506,28 +506,28 @@
      * config} to perform verification on a given object.
      *
      * @param object object to verify
-     * @param context1 first object describing the context of verification
-     * @param context2 second object describing the context of verification
+     * @param format a format string for the description of the verification context
+     * @param arg the argument referenced by the format specifiers in {@code format}
      *
-     * @see DebugVerifyHandler#verify(Object, Object...)
+     * @see DebugVerifyHandler#verify(Object, String)
      */
-    public static void verify(Object object, Object context1, Object context2) {
+    public static void verify(Object object, String format, Object arg) {
         if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) {
-            DebugScope.getInstance().verify(object, context1, context2);
+            DebugScope.getInstance().verify(object, format, arg);
         }
     }
 
     /**
-     * This override exists to catch cases when {@link #verify(Object, Object)} is called with one
-     * argument bound to a varargs method parameter. It will bind to this method instead of the
-     * single arg variant and produce a deprecation warning instead of silently wrapping the
+     * This override exists to catch cases when {@link #verify(Object, String, Object)} is called
+     * with one argument bound to a varargs method parameter. It will bind to this method instead of
+     * the single arg variant and produce a deprecation warning instead of silently wrapping the
      * Object[] inside of another Object[].
      */
     @Deprecated
-    public static void verify(Object object, Object[] args) {
+    public static void verify(Object object, String format, Object[] args) {
         assert false : "shouldn't use this";
         if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) {
-            DebugScope.getInstance().verify(object, args);
+            DebugScope.getInstance().verify(object, format, args);
         }
     }
 
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugVerifyHandler.java	Mon Jun 30 15:43:25 2014 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugVerifyHandler.java	Mon Jun 30 17:23:56 2014 +0200
@@ -31,25 +31,7 @@
      * Verifies that a given object satisfies some invariants.
      *
      * @param object object to verify
-     * @param context object(s) describing the context of verification
-     */
-    void verify(Object object, Object... context);
-
-    /**
-     * Extracts the first object of a given type from a verification input object.
+     * @param message description of verification context
      */
-    default <T> T extract(Class<T> type, Object input) {
-        if (type.isInstance(input)) {
-            return type.cast(input);
-        }
-        if (input instanceof Object[]) {
-            for (Object nestedContext : (Object[]) input) {
-                T object = extract(type, nestedContext);
-                if (object != null) {
-                    return object;
-                }
-            }
-        }
-        return null;
-    }
+    void verify(Object object, String message);
 }
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Mon Jun 30 15:43:25 2014 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Mon Jun 30 17:23:56 2014 +0200
@@ -218,14 +218,15 @@
     }
 
     /**
-     * @see Debug#verify(Object, Object)
+     * @see Debug#verify(Object, String)
      */
-    public void verify(Object object, Object... ctx) {
+    public void verify(Object object, String formatString, Object... args) {
         if (isVerifyEnabled()) {
             DebugConfig config = getConfig();
             if (config != null) {
+                String message = String.format(formatString, args);
                 for (DebugVerifyHandler handler : config.verifyHandlers()) {
-                    handler.verify(object, ctx);
+                    handler.verify(object, message);
                 }
             }
         }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java	Mon Jun 30 15:43:25 2014 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java	Mon Jun 30 17:23:56 2014 +0200
@@ -101,7 +101,7 @@
                 Debug.dump(graph, "After phase %s", getName());
             }
             if (Debug.isVerifyEnabled()) {
-                Debug.verify(graph, this, "After phase " + getName());
+                Debug.verify(graph, "After phase %s", getName());
             }
             assert graph.verify();
         } catch (Throwable t) {
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java	Mon Jun 30 15:43:25 2014 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/NoDeadCodeVerifyHandler.java	Mon Jun 30 17:23:56 2014 +0200
@@ -25,14 +25,12 @@
 import static com.oracle.graal.printer.NoDeadCodeVerifyHandler.Options.*;
 
 import java.util.*;
-import java.util.concurrent.*;
 
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.options.*;
-import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.common.*;
 
 /**
@@ -54,34 +52,24 @@
         // @formatter:on
     }
 
-    private static final Map<Class<?>, Boolean> discovered = new ConcurrentHashMap<>();
-
-    public void verify(Object object, Object... context) {
-        if (NDCV.getValue() != OFF) {
-            StructuredGraph graph = extract(StructuredGraph.class, object);
-            BasePhase<?> phase = extract(BasePhase.class, context);
-            assert phase != null : "a Phase context is required by " + getClass().getSimpleName();
-            if (graph != null) {
-                List<Node> before = graph.getNodes().snapshot();
-                new DeadCodeEliminationPhase().run(graph);
-                List<Node> after = graph.getNodes().snapshot();
-                assert after.size() <= before.size();
-                if (before.size() != after.size()) {
-                    before.removeAll(after);
-                    if (discovered.put(phase.getClass(), Boolean.TRUE) == null) {
-                        String message = extract(String.class, context);
-                        String prefix = message == null ? "" : message + ": ";
-                        String phaseClass = phase.getClass().getName();
-                        GraalInternalError error = new GraalInternalError("%sfound dead nodes in %s (phase class=%s): %s", prefix, graph, phaseClass, before);
-                        if (NDCV.getValue() == INFO) {
-                            System.out.println(error.getMessage());
-                        } else if (NDCV.getValue() == VERBOSE) {
-                            error.printStackTrace(System.out);
-                        } else {
-                            assert NDCV.getValue() == FATAL;
-                            throw error;
-                        }
-                    }
+    public void verify(Object object, String message) {
+        if (NDCV.getValue() != OFF && object instanceof StructuredGraph) {
+            StructuredGraph graph = (StructuredGraph) object;
+            List<Node> before = graph.getNodes().snapshot();
+            new DeadCodeEliminationPhase().run(graph);
+            List<Node> after = graph.getNodes().snapshot();
+            assert after.size() <= before.size();
+            if (before.size() != after.size()) {
+                before.removeAll(after);
+                String prefix = message == null ? "" : message + ": ";
+                GraalInternalError error = new GraalInternalError("%sfound dead nodes in %s: %s", prefix, graph, before);
+                if (NDCV.getValue() == INFO) {
+                    System.out.println(error.getMessage());
+                } else if (NDCV.getValue() == VERBOSE) {
+                    error.printStackTrace(System.out);
+                } else {
+                    assert NDCV.getValue() == FATAL;
+                    throw error;
                 }
             }
         }