changeset 5302:55bf72fafc41

(preliminary) logging to file (-G:LogFile=asdf.txt)
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 25 Apr 2012 14:34:29 +0200
parents 23ea81293bd5
children 31110c447ad2 2558ff0945f8
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java
diffstat 6 files changed, 42 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java	Wed Apr 25 14:34:29 2012 +0200
@@ -23,6 +23,8 @@
 package com.oracle.graal.debug;
 
 import com.oracle.graal.debug.internal.*;
+
+import java.io.*;
 import java.util.*;
 import java.util.concurrent.*;
 
@@ -32,7 +34,6 @@
 
     public static void enable() {
         ENABLED = true;
-        DebugScope.initialize();
     }
 
     public static boolean isEnabled() {
@@ -188,7 +189,7 @@
         }
     }
 
-    public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled, final Collection<? extends DebugDumpHandler> dumpHandlers) {
+    public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled, final Collection<? extends DebugDumpHandler> dumpHandlers, final PrintStream output) {
         return new DebugConfig() {
 
             @Override
@@ -220,6 +221,11 @@
             public Collection< ? extends DebugDumpHandler> dumpHandlers() {
                 return dumpHandlers;
             }
+
+            @Override
+            public PrintStream output() {
+                return output;
+            }
         };
     }
 
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java	Wed Apr 25 14:34:29 2012 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.debug;
 
+import java.io.*;
 import java.util.*;
 
 
@@ -49,4 +50,6 @@
     RuntimeException interceptException(Throwable e);
 
     Collection<? extends DebugDumpHandler> dumpHandlers();
+
+    PrintStream output();
 }
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Wed Apr 25 14:34:29 2012 +0200
@@ -33,6 +33,7 @@
     private static ThreadLocal<DebugScope> instanceTL = new ThreadLocal<>();
     private static ThreadLocal<DebugConfig> configTL = new ThreadLocal<>();
     private static ThreadLocal<Throwable> lastExceptionThrownTL = new ThreadLocal<>();
+    private static ThreadLocal<DebugScope> lastLogScope = new ThreadLocal<>();
     private static DebugTimer scopeTime = Debug.timer("ScopeTime");
 
     private final DebugScope parent;
@@ -49,6 +50,8 @@
     private boolean timeEnabled;
     private boolean dumpEnabled;
 
+    private PrintStream output;
+
     public static DebugScope getInstance() {
         DebugScope result = instanceTL.get();
         if (result == null) {
@@ -103,7 +106,11 @@
 
     public void log(String msg, Object... args) {
         if (isLogEnabled()) {
-            cachedOut.println(String.format(msg, args));
+            if (lastLogScope.get() != this) {
+                output.println("scope: " + qualifiedName + " " + this);
+                lastLogScope.set(this);
+            }
+            output.println(String.format(msg, args));
         }
     }
 
@@ -173,11 +180,13 @@
             meterEnabled = false;
             timeEnabled = false;
             dumpEnabled = false;
+            output = null;
         } else {
             logEnabled = config.isLogEnabled();
             meterEnabled = config.isMeterEnabled();
             timeEnabled = config.isTimeEnabled();
             dumpEnabled = config.isDumpEnabled();
+            output = config.output();
         }
     }
 
@@ -281,10 +290,4 @@
     public String getQualifiedName() {
         return qualifiedName;
     }
-
-    public static PrintStream cachedOut;
-
-    public static void initialize() {
-        cachedOut = System.out;
-    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java	Wed Apr 25 14:34:29 2012 +0200
@@ -57,7 +57,7 @@
     public void run() {
         if (GraalOptions.Debug) {
             Debug.enable();
-            HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter);
+            HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter, GraalOptions.LogFile);
             Debug.setConfig(hotspotDebugConfig);
         }
         super.run();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java	Wed Apr 25 14:34:29 2012 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.hotspot;
 
+import java.io.*;
 import java.util.*;
 
 import com.oracle.graal.compiler.*;
@@ -40,10 +41,12 @@
     private final DebugFilter dumpFilter;
     private final MethodFilter[] methodFilter;
     private final List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
+    private final PrintStream output;
+
+    private static final PrintStream cachedOut = System.out;
 
 
-
-    public HotSpotDebugConfig(String logFilter, String meterFilter, String timerFilter, String dumpFilter, String methodFilter) {
+    public HotSpotDebugConfig(String logFilter, String meterFilter, String timerFilter, String dumpFilter, String methodFilter, String logFile) {
         this.logFilter = DebugFilter.parse(logFilter);
         this.meterFilter = DebugFilter.parse(meterFilter);
         this.timerFilter = DebugFilter.parse(timerFilter);
@@ -69,6 +72,15 @@
             dumpHandlers.add(new IdealGraphPrinterDumpHandler(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort));
         }
         dumpHandlers.add(new CFGPrinterObserver());
+        if (logFile == null || logFile.isEmpty()) {
+            output = cachedOut;
+        } else {
+            try {
+                output = new PrintStream(logFile);
+            } catch (FileNotFoundException e) {
+                throw new RuntimeException("couldn't create log file: " + logFile, e);
+            }
+        }
     }
 
     public boolean isLogEnabled() {
@@ -87,6 +99,10 @@
         return isEnabled(timerFilter);
     }
 
+    public PrintStream output() {
+        return output;
+    }
+
     private boolean isEnabled(DebugFilter filter) {
         return checkDebugFilter(Debug.currentScope(), filter) && checkMethodFilter();
     }
@@ -142,7 +158,7 @@
         if (e instanceof CiBailout) {
             return null;
         }
-        Debug.setConfig(Debug.fixedConfig(true, true, false, false, dumpHandlers));
+        Debug.setConfig(Debug.fixedConfig(true, true, false, false, dumpHandlers, output));
         // sync "Exception occured in scope: " with mx/sanitycheck.py::Test.__init__
         Debug.log(String.format("Exception occured in scope: %s", Debug.currentScope()));
         for (Object o : Debug.context()) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Wed Apr 25 13:33:28 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Wed Apr 25 14:34:29 2012 +0200
@@ -92,7 +92,7 @@
 
         if (GraalOptions.Debug) {
             Debug.enable();
-            HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter);
+            HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter, GraalOptions.LogFile);
             Debug.setConfig(hotspotDebugConfig);
         }
         // Install intrinsics.