changeset 11611:a27678c47948

made Debug.ENABLED static (i.e. a compile-time constant)
author Doug Simon <doug.simon@oracle.com>
date Thu, 12 Sep 2013 16:23:28 +0200
parents 5f532ea846fb
children 54dff87002e0
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/DebugEnvironment.java
diffstat 3 files changed, 25 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Thu Sep 12 14:43:21 2013 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Thu Sep 12 16:23:28 2013 +0200
@@ -22,24 +22,38 @@
  */
 package com.oracle.graal.debug;
 
-import com.oracle.graal.debug.internal.*;
+import static com.oracle.graal.debug.Debug.Initializer.*;
 
 import java.io.*;
 import java.util.*;
 import java.util.concurrent.*;
 
+import com.oracle.graal.debug.internal.*;
+
+/**
+ * Scope based debugging facility. This facility is {@link #isEnabled()} if assertions are enabled
+ * for the {@link Debug} class or the {@value Initializer#INITIALIZER_PROPERTY_NAME} system property
+ * is {@code "true"} when {@link Debug} is initialized.
+ */
 public class Debug {
 
-    private static boolean ENABLED = false;
+    /**
+     * Class declaring the name of the system property to be used enabling the debugging facilities.
+     */
+    public static class Initializer {
 
-    public static void enable() {
-        ENABLED = true;
+        public static final String INITIALIZER_PROPERTY_NAME = "graal.debug.enable";
     }
 
-    public static void disable() {
-        ENABLED = false;
+    @SuppressWarnings("all")
+    private static boolean assertionsEnabled() {
+        boolean enabled = false;
+        assert enabled = true;
+        return enabled;
     }
 
+    private static final boolean ENABLED = assertionsEnabled() || Boolean.getBoolean(INITIALIZER_PROPERTY_NAME);
+
     public static boolean isEnabled() {
         return ENABLED;
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java	Thu Sep 12 14:43:21 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java	Thu Sep 12 16:23:28 2013 +0200
@@ -183,7 +183,7 @@
      */
     public static void finalizeOptions(boolean ciTime) {
         if (areDebugScopePatternsEnabled() || ciTime) {
-            Debug.enable();
+            System.setProperty(Debug.Initializer.INITIALIZER_PROPERTY_NAME, "true");
         }
     }
 
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/DebugEnvironment.java	Thu Sep 12 14:43:21 2013 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/DebugEnvironment.java	Thu Sep 12 16:23:28 2013 +0200
@@ -34,7 +34,10 @@
 public class DebugEnvironment {
 
     public static void initialize(PrintStream log) {
-        Debug.enable();
+        if (!Debug.isEnabled()) {
+            log.println("WARNING: Scope debugging needs to be enabled with -esa or -D" + Debug.Initializer.INITIALIZER_PROPERTY_NAME + "=true");
+            return;
+        }
         List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
         dumpHandlers.add(new GraphPrinterDumpHandler());
         if (PrintCFG.getValue() || PrintBackendCFG.getValue()) {