# HG changeset patch # User Lukas Stadler # Date 1335357269 -7200 # Node ID 55bf72fafc4132919a933e34e4aff95f40c560dd # Parent 23ea81293bd572803d6685acb6ae37a38161b316 (preliminary) logging to file (-G:LogFile=asdf.txt) diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- 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 dumpHandlers) { + public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled, final Collection 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; + } }; } diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java --- 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 dumpHandlers(); + + PrintStream output(); } diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java --- 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 instanceTL = new ThreadLocal<>(); private static ThreadLocal configTL = new ThreadLocal<>(); private static ThreadLocal lastExceptionThrownTL = new ThreadLocal<>(); + private static ThreadLocal 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; - } } diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java --- 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(); diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotDebugConfig.java --- 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 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()) { diff -r 23ea81293bd5 -r 55bf72fafc41 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- 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.