# HG changeset patch # User Thomas Wuerthinger # Date 1327067931 -3600 # Node ID 719ac1d92a5245fdc18d1a69c973d5818c6101dc # Parent 249752adcb8d4ce7763754359180c424f3ae33ef More work on debug framework. diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Fri Jan 20 14:58:51 2012 +0100 @@ -82,16 +82,24 @@ throw new CiBailout("No OSR supported"); } return Debug.scope("CompileMethod", method, new Callable() { - public CiTargetMethod call() { - final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null; - LIR lir = Debug.scope("EmitHIR", graph, new Callable() { - public LIR call() { - return emitHIR(graph, assumptions, plan); - } - }); - FrameMap frameMap = emitLIR(lir, graph, method); + public CiTargetMethod call() { + final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null; + final LIR lir = Debug.scope("FrontEnd", graph, new Callable() { + public LIR call() { + return emitHIR(graph, assumptions, plan); + } + }); + final FrameMap frameMap = Debug.scope("BackEnd", lir, new Callable() { + public FrameMap call() { + return emitLIR(lir, graph, method); + } + }); + return Debug.scope("CodeGen", frameMap, new Callable() { + public CiTargetMethod call() { return emitCode(assumptions, method, lir, frameMap); - } + } + }); + } }); } @@ -208,34 +216,39 @@ }); } - public FrameMap emitLIR(LIR lir, StructuredGraph graph, RiResolvedMethod method) { - LIRGenerator lirGenerator = null; - FrameMap frameMap; - frameMap = backend.newFrameMap(runtime.getRegisterConfig(method)); - - lirGenerator = backend.newLIRGenerator(graph, frameMap, method, lir, xir); + public FrameMap emitLIR(final LIR lir, StructuredGraph graph, final RiResolvedMethod method) { + final FrameMap frameMap = backend.newFrameMap(runtime.getRegisterConfig(method)); + final LIRGenerator lirGenerator = backend.newLIRGenerator(graph, frameMap, method, lir, xir); - for (LIRBlock b : lir.linearScanOrder()) { - lirGenerator.doBlock(b); - } + Debug.scope("LIRGen", new Runnable() { + public void run() { + for (LIRBlock b : lir.linearScanOrder()) { + lirGenerator.doBlock(b); + } - for (LIRBlock b : lir.linearScanOrder()) { - if (b.phis != null) { - b.phis.fillInputs(lirGenerator); - } + for (LIRBlock b : lir.linearScanOrder()) { + if (b.phis != null) { + b.phis.fillInputs(lirGenerator); } + } Debug.dump(lirGenerator, "After LIR generation"); if (GraalOptions.PrintLIR && !TTY.isSuppressed()) { LIR.printLIR(lir.linearScanOrder()); } + } + }); + Debug.scope("Allocator", new Runnable() { + public void run() { if (GraalOptions.AllocSSA) { new SpillAllAllocator(lir, frameMap).execute(); } else { - new LinearScan(target, method, graph, lir, lirGenerator, frameMap).allocate(); + new LinearScan(target, method, lir, lirGenerator, frameMap).allocate(); } - return frameMap; + } + }); + return frameMap; } private TargetMethodAssembler createAssembler(FrameMap frameMap, LIR lir) { diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Fri Jan 20 14:58:51 2012 +0100 @@ -82,9 +82,15 @@ public static boolean PrintLIR = ____; public static boolean PrintCFGToFile = ____; + // Debug settings: + public static boolean Debug = true; + public static String Dump = null; + public static String Meter = null; + public static String Time = null; + public static String Log = null; + public static String MethodFilter = null; + // Ideal graph visualizer output settings - public static boolean Plot = ____; - public static boolean PlotVerbose = ____; public static boolean PlotOnError = ____; public static int PlotLevel = 3; public static boolean PlotSnippets = ____; @@ -95,8 +101,6 @@ public static int PrintIdealGraphPort = 4444; // Other printing settings - public static boolean Meter = ____; - public static boolean Time = ____; public static boolean PrintQueue = ____; public static boolean PrintCompilation = ____; public static boolean PrintXirTemplates = ____; diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Fri Jan 20 14:58:51 2012 +0100 @@ -120,7 +120,7 @@ private final int firstVariableNumber; - public LinearScan(CiTarget target, RiResolvedMethod method, StructuredGraph graph, LIR ir, LIRGenerator gen, FrameMap frameMap) { + public LinearScan(CiTarget target, RiResolvedMethod method, LIR ir, LIRGenerator gen, FrameMap frameMap) { this.target = target; this.method = method; this.ir = ir; @@ -1782,78 +1782,66 @@ } } - private static final DebugTimer timerLifetimeAnalysis = Debug.timer("LifetimeAnalysis"); - private static final DebugTimer timerLinearScan = Debug.timer("LinearScan"); - private static final DebugTimer timerLinearScanResolution = Debug.timer("LinearScanResolution"); - private static final DebugTimer timerDebugInfo = Debug.timer("DebugInfo"); - private static final DebugTimer timerControlFlowOptimizations = Debug.timer("ControlFlowOptimizations"); - public void allocate() { - timerLifetimeAnalysis.start(); - try { - numberInstructions(); - - printLir("Before register allocation", true); + Debug.scope("LifetimeAnalysis", new Runnable() { - computeLocalLiveSets(); - computeGlobalLiveSets(); + public void run() { + numberInstructions(); + printLir("Before register allocation", true); + computeLocalLiveSets(); + computeGlobalLiveSets(); + buildIntervals(); + sortIntervalsBeforeAllocation(); + } + }); - buildIntervals(); - sortIntervalsBeforeAllocation(); - } finally { - timerLifetimeAnalysis.stop(); - } + Debug.scope("RegisterAllocation", new Runnable() { - timerLinearScan.start(); - try { - printIntervals("Before register allocation"); - - allocateRegisters(); + public void run() { + printIntervals("Before register allocation"); + allocateRegisters(); + } + }); - } finally { - timerLinearScan.stop(); - } + Debug.scope("ResolveDataFlow", new Runnable() { + public void run() { + resolveDataFlow(); + } + }); - timerLinearScanResolution.start(); - try { - resolveDataFlow(); - } finally { - timerLinearScanResolution.stop(); - } + Debug.scope("DebugInfo", new Runnable() { - timerDebugInfo.start(); - try { - frameMap.finish(); + public void run() { + frameMap.finish(); - printIntervals("After register allocation"); - printLir("After register allocation", true); + printIntervals("After register allocation"); + printLir("After register allocation", true); - sortIntervalsAfterAllocation(); + sortIntervalsAfterAllocation(); - if (GraalOptions.DetailedAsserts) { - verify(); - } + if (GraalOptions.DetailedAsserts) { + verify(); + } - eliminateSpillMoves(); - assignLocations(); + eliminateSpillMoves(); + assignLocations(); - if (GraalOptions.DetailedAsserts) { - verifyIntervals(); + if (GraalOptions.DetailedAsserts) { + verifyIntervals(); + } } - } finally { - timerDebugInfo.stop(); - } + }); + + Debug.scope("ControlFlowOptimizations", new Runnable() { - timerControlFlowOptimizations.start(); - try { - printLir("After register number assignment", true); - EdgeMoveOptimizer.optimize(ir.linearScanOrder()); - ControlFlowOptimizer.optimize(ir); - printLir("After control flow optimization", false); - } finally { - timerControlFlowOptimizations.stop(); - } + public void run() { + printLir("After register number assignment", true); + EdgeMoveOptimizer.optimize(ir.linearScanOrder()); + ControlFlowOptimizer.optimize(ir); + printLir("After control flow optimization", false); + } + }); } void printIntervals(String label) { diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java Fri Jan 20 14:58:51 2012 +0100 @@ -27,10 +27,13 @@ public abstract class Phase { - private final String name; + private String name; protected Phase() { this.name = this.getClass().getSimpleName(); + if (name.endsWith("Phase")) { + name = name.substring(0, name.length() - "Phase".length()); + } } protected Phase(String name) { diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java --- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java Fri Jan 20 14:58:51 2012 +0100 @@ -30,13 +30,15 @@ public class Debug { - public static boolean SCOPE = false; - public static boolean LOG = false; - public static boolean METER = false; - public static boolean TIME = false; + private static boolean ENABLED = false; + + public static void enable() { + ENABLED = true; + DebugScope.initialize(); + } public static void sandbox(String name, Runnable runnable) { - if (SCOPE) { + if (ENABLED) { DebugScope.getInstance().scope(name, runnable, null, true, new Object[0]); } else { runnable.run(); @@ -52,15 +54,23 @@ } public static void scope(String name, Object context, Runnable runnable) { - if (SCOPE) { + if (ENABLED) { DebugScope.getInstance().scope(name, runnable, null, false, new Object[]{context}); } else { runnable.run(); } } + public static String currentScope() { + if (ENABLED) { + return DebugScope.getInstance().getQualifiedName(); + } else { + return ""; + } + } + public static T scope(String name, Object context, Callable callable) { - if (SCOPE) { + if (ENABLED) { return DebugScope.getInstance().scope(name, null, callable, false, new Object[]{context}); } else { return DebugScope.call(callable); @@ -68,19 +78,19 @@ } public static void log(String msg, Object... args) { - if (LOG) { + if (ENABLED && DebugScope.getInstance().isLogEnabled()) { DebugScope.getInstance().log(msg, args); } } public static void dump(Object object, String msg, Object... args) { - if (LOG) { - DebugScope.getInstance().log(msg, args); + if (ENABLED && DebugScope.getInstance().isDumpEnabled()) { + DebugScope.getInstance().dump(object, msg, args); } } public static Iterable context() { - if (SCOPE) { + if (ENABLED) { return DebugScope.getInstance().getCurrentContext(); } else { return Collections.emptyList(); @@ -88,22 +98,26 @@ } public static DebugMetric metric(String name) { - if (METER) { + if (ENABLED && DebugScope.getInstance().isMeterEnabled()) { return new MetricImpl(name); } else { return VOID_METRIC; } } + public static void setConfig(DebugConfig config) { + if (ENABLED) { + DebugScope.getInstance().setConfig(config); + } + } + private static final DebugMetric VOID_METRIC = new DebugMetric() { - @Override public void increment() { } - @Override public void add(int value) { } }; public static DebugTimer timer(String name) { - if (TIME) { + if (ENABLED && DebugScope.getInstance().isTimerEnabled()) { return new TimerImpl(name); } else { return VOID_TIMER; @@ -111,9 +125,7 @@ } private static final DebugTimer VOID_TIMER = new DebugTimer() { - @Override public void start() { } - @Override public void stop() { } }; } diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java Fri Jan 20 14:58:51 2012 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.debug; + + +public interface DebugConfig { + boolean isLogEnabled(); + boolean isMeterEnabled(); + boolean isDumpEnabled(); + boolean isTimerEnabled(); +} diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugMetric.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugMetric.java Fri Jan 20 14:58:51 2012 +0100 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.debug; + +public interface DebugMetric { + void increment(); + void add(int value); +} diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugTimer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugTimer.java Fri Jan 20 14:58:51 2012 +0100 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.debug; + +public interface DebugTimer { + void start(); + void stop(); +} diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java --- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java Fri Jan 20 14:58:51 2012 +0100 @@ -22,84 +22,156 @@ */ package com.oracle.max.graal.debug.internal; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.io.*; +import java.util.*; import java.util.concurrent.*; +import com.oracle.max.graal.debug.*; + public final class DebugScope { private static ThreadLocal instance = new ThreadLocal<>(); - private final List children = new ArrayList<>(4); + private static ThreadLocal config = new ThreadLocal<>(); + private final String name; private final DebugScope parent; - private final Object[] context; - private final DebugValueMap valueMap = new DebugValueMap(); + + private Object[] context; + + private List children; + private DebugValueMap valueMap; + private String qualifiedName; - public static final DebugScope DEFAULT_CONTEXT = new DebugScope("DEFAULT", null); + public static final DebugScope DEFAULT_CONTEXT = new DebugScope("DEFAULT", "DEFAULT", null); + private static final char SCOPE_SEP = '.'; + + private boolean logEnabled; + private boolean meterEnabled; + private boolean timerEnabled; + private boolean dumpEnabled; public static DebugScope getInstance() { DebugScope result = instance.get(); if (result == null) { - return DEFAULT_CONTEXT; + instance.set(new DebugScope("DEFAULT", "DEFAULT", null)); + return instance.get(); } else { return result; } } - private DebugScope(String name, DebugScope parent, Object... context) { + public static DebugConfig getConfig() { + return config.get(); + } + + private DebugScope(String name, String qualifiedName, DebugScope parent, Object... context) { this.name = name; this.parent = parent; this.context = context; + this.qualifiedName = qualifiedName; + } + + public boolean isDumpEnabled() { + return dumpEnabled; + } + + public boolean isLogEnabled() { + return logEnabled; + } + + public boolean isMeterEnabled() { + return meterEnabled; + } + + public boolean isTimerEnabled() { + return timerEnabled; } public void log(String msg, Object... args) { + if (isLogEnabled()) { + cachedOut.println(String.format(msg, args)); + } + } + + public void dump(Object object, String msg, Object[] args) { } public T scope(String newName, Runnable runnable, Callable callable, boolean sandbox, Object[] newContext) { DebugScope oldContext = getInstance(); + DebugConfig oldConfig = getConfig(); DebugScope newChild = null; if (sandbox) { - newChild = new DebugScope(name, null, newContext); + newChild = new DebugScope(newName, newName, null, newContext); + setConfig(null); } else { - oldContext.createChild(newName, newContext); + newChild = oldContext.createChild(newName, newContext); } instance.set(newChild); T result = null; + updateFlags(); + log("Starting scope %s", newChild.getQualifiedName()); try { if (runnable != null) { runnable.run(); } if (callable != null) { - call(callable); + result = call(callable); } } catch (RuntimeException e) { throw interceptException(e); } finally { + newChild.deactivate(); instance.set(oldContext); + setConfig(oldConfig); } return result; } - public DebugValueMap getValueMap() { - return valueMap; + private void updateFlags() { + DebugConfig config = getConfig(); + if (config == null) { + logEnabled = false; + meterEnabled = false; + timerEnabled = false; + dumpEnabled = false; + } else { + logEnabled = config.isLogEnabled(); + meterEnabled = config.isMeterEnabled(); + timerEnabled = config.isTimerEnabled(); + dumpEnabled = config.isDumpEnabled(); + } + } + + private void deactivate() { + context = null; } private RuntimeException interceptException(RuntimeException e) { return e; } + private DebugValueMap getValueMap() { + if (valueMap == null) { + valueMap = new DebugValueMap(); + } + return valueMap; + } + long getCurrentValue(int index) { - return valueMap.getCurrentValue(index); + return getValueMap().getCurrentValue(index); } void setCurrentValue(int index, long l) { - valueMap.setCurrentValue(index, l); + getValueMap().setCurrentValue(index, l); } private DebugScope createChild(String newName, Object[] newContext) { - DebugScope result = new DebugScope(newName, this, newContext); + String newQualifiedName = this.qualifiedName + SCOPE_SEP + newName; + DebugScope result = new DebugScope(newName, newQualifiedName, this, newContext); + if (children == null) { + children = new ArrayList<>(4); + } children.add(result); return result; } @@ -156,5 +228,20 @@ } } } + + public void setConfig(DebugConfig newConfig) { + config.set(newConfig); + updateFlags(); + } + + public String getQualifiedName() { + return qualifiedName; + } + + public static PrintStream cachedOut; + + public static void initialize() { + cachedOut = System.out; + } } diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugValueMap.java --- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugValueMap.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugValueMap.java Fri Jan 20 14:58:51 2012 +0100 @@ -39,7 +39,10 @@ } private void ensureSize(int index) { - if (values == null || values.length <= index) { + if (values == null) { + values = new long[index + 1]; + } + if (values.length <= index) { values = Arrays.copyOf(values, index + 1); } } diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java Fri Jan 20 14:58:51 2012 +0100 @@ -30,14 +30,12 @@ import com.oracle.max.cri.ri.*; import com.oracle.max.cri.xir.*; import com.oracle.max.graal.compiler.*; -import com.oracle.max.graal.compiler.observer.*; import com.oracle.max.graal.compiler.target.*; import com.oracle.max.graal.cri.*; import com.oracle.max.graal.hotspot.bridge.*; import com.oracle.max.graal.hotspot.logging.*; import com.oracle.max.graal.hotspot.ri.*; import com.oracle.max.graal.hotspot.server.*; -import com.oracle.max.graal.printer.*; /** * Singleton class holding the instance of the GraalCompiler. @@ -218,16 +216,16 @@ if (GraalOptions.PrintCFGToFile) { // context.addCompilationObserver(new CFGPrinterObserver()); } - if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot || GraalOptions.PlotOnError) { - CompilationObserver observer; - if (GraalOptions.PrintIdealGraphFile) { - observer = new IdealGraphPrinterObserver(); - } else { - observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort); - } + // if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot || GraalOptions.PlotOnError) { + // CompilationObserver observer; + // if (GraalOptions.PrintIdealGraphFile) { + // observer = new IdealGraphPrinterObserver(); + // } else { + // observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort); + // } // context.addCompilationObserver(observer); // TODO(tw): Install observer. - } + // } runtime = new HotSpotRuntime(config, this); } return runtime; diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java Fri Jan 20 14:58:51 2012 +0100 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.hotspot; + +import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.debug.*; + + +public class HotSpotDebugConfig implements DebugConfig { + + public final String logFilter; + public final String meterFilter; + public final String timerFilter; + public final String dumpFilter; + public final String methodFilter; + + public HotSpotDebugConfig(String logFilter, String meterFilter, String timerFilter, String dumpFilter, String methodFilter) { + this.logFilter = logFilter; + this.meterFilter = meterFilter; + this.timerFilter = timerFilter; + this.dumpFilter = dumpFilter; + this.methodFilter = methodFilter; + } + + public boolean isLogEnabled() { + return isEnabled(logFilter); + } + + public boolean isMeterEnabled() { + return isEnabled(meterFilter); + } + + public boolean isDumpEnabled() { + return isEnabled(dumpFilter); + } + + public boolean isTimerEnabled() { + return isEnabled(timerFilter); + } + + private boolean isEnabled(String filter) { + return filter != null && Debug.currentScope().contains(filter) && checkMethodFilter(); + } + + private boolean checkMethodFilter() { + if (methodFilter == null) { + return true; + } else { + for (Object o : Debug.context()) { + if (o instanceof RiMethod) { + RiMethod riMethod = (RiMethod) o; + if (riMethod.toString().contains(methodFilter)) { + return true; + } + } + } + return false; + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Debug config:"); + add(sb, "Log", logFilter); + add(sb, "Meter", meterFilter); + add(sb, "Time", timerFilter); + add(sb, "Dump", dumpFilter); + add(sb, "MethodFilter", methodFilter); + return sb.toString(); + } + + private static void add(StringBuilder sb, String name, String filter) { + if (filter != null) { + sb.append(' '); + sb.append(name); + sb.append('='); + sb.append(filter); + } + } +} diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotOptions.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotOptions.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotOptions.java Fri Jan 20 14:58:51 2012 +0100 @@ -78,7 +78,11 @@ value = Boolean.parseBoolean(valueString); } } else if (f.getType() == String.class) { - value = valueString; + if (valueString == null) { + value = ""; + } else { + value = valueString; + } } } if (value != null) { diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java Fri Jan 20 14:58:51 2012 +0100 @@ -32,6 +32,7 @@ import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition; +import com.oracle.max.graal.debug.*; import com.oracle.max.graal.hotspot.*; import com.oracle.max.graal.hotspot.Compiler; import com.oracle.max.graal.hotspot.ri.*; @@ -46,6 +47,7 @@ private final Compiler compiler; private int compiledMethodCount; + private DebugConfig debugConfig; public final HotSpotTypePrimitive typeBoolean; public final HotSpotTypePrimitive typeChar; @@ -57,18 +59,23 @@ public final HotSpotTypePrimitive typeLong; public final HotSpotTypePrimitive typeVoid; - ThreadFactory daemonThreadFactory = new ThreadFactory() { + ThreadFactory compilerThreadFactory = new ThreadFactory() { @Override public Thread newThread(Runnable r) { - Thread t = new CompilerThread(r); - t.setDaemon(true); - return t; + return new CompilerThread(r); } }; - private static final class CompilerThread extends Thread { + private final class CompilerThread extends Thread { public CompilerThread(Runnable r) { super(r); - this.setName("CompilerThread-" + this.getId()); + this.setName("GraalCompilerThread-" + this.getId()); + this.setDaemon(true); + } + + @Override + public void run() { + Debug.setConfig(debugConfig); + super.run(); } } private ThreadPoolExecutor compileQueue; @@ -100,7 +107,7 @@ } // Create compilation queue. - compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), daemonThreadFactory); + compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), compilerThreadFactory); // Create queue status printing thread. if (GraalOptions.PrintQueue) { @@ -119,6 +126,13 @@ t.setDaemon(true); t.start(); } + + if (GraalOptions.Debug) { + Debug.enable(); + HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter); + System.out.println(hotspotDebugConfig); + this.debugConfig = hotspotDebugConfig; + } } public void bootstrap() throws Throwable { diff -r 249752adcb8d -r 719ac1d92a52 graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java Wed Jan 18 13:54:40 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java Fri Jan 20 14:58:51 2012 +0100 @@ -28,7 +28,6 @@ import com.oracle.max.cri.ri.*; import com.oracle.max.criutils.*; -import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.observer.*; import com.oracle.max.graal.compiler.schedule.*; import com.oracle.max.graal.graph.*; @@ -91,18 +90,16 @@ private void openPrinter(RiResolvedMethod method, boolean error) { assert (context().stream == null && printer() == null); - if ((!TTY.isSuppressed() && GraalOptions.Plot) || (GraalOptions.PlotOnError && error)) { - String name; - if (method != null) { - name = method.holder().name(); - name = name.substring(1, name.length() - 1).replace('/', '.'); - name = name + "." + method.name(); - } else { - name = "null"; - } + String name; + if (method != null) { + name = method.holder().name(); + name = name.substring(1, name.length() - 1).replace('/', '.'); + name = name + "." + method.name(); + } else { + name = "null"; + } - openPrinter(name, method); - } + openPrinter(name, method); } private void openPrinter(String title, RiResolvedMethod method) {