# HG changeset patch # User Thomas Wuerthinger # Date 1332328061 -3600 # Node ID 4eb9895d9afe45440bfe1e98c7121953948e01c6 # Parent 09f638813477a6d01e7f96ae0460e5caa2d4b185 Refactoring of the debug framework. Move compiler thread implementation to its own file. diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Wed Mar 21 12:07:41 2012 +0100 @@ -84,7 +84,7 @@ throw new CiBailout("No OSR supported"); } - return Debug.scope(createScopeName(method), new Object[] {graph, method, this}, new Callable() { + return Debug.scope("GraalCompiler", new Object[] {graph, method, this}, new Callable() { public CiTargetMethod call() { final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null; final LIR lir = Debug.scope("FrontEnd", new Callable() { @@ -106,23 +106,6 @@ }); } - private static String createScopeName(RiResolvedMethod method) { - if (Debug.isEnabled()) { - return String.format("[%s::%s]", createSimpleName(method.holder()), method.name()); - } else { - return null; - } - } - - private static String createSimpleName(RiResolvedType holder) { - String base = holder.name(); - int slashIndex = base.lastIndexOf('/'); - if (slashIndex == -1) { - slashIndex = 0; - } - return base.substring(slashIndex + 1, base.length() - 1); - } - /** * Builds the graph, optimizes it. */ diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Wed Mar 21 12:07:41 2012 +0100 @@ -110,7 +110,9 @@ // Debug settings: public static boolean Debug = true; + public static boolean PerThreadDebugValues = ____; public static boolean SummarizeDebugValues = ____; + public static boolean SummarizePerPhase = ____; public static String Dump = null; public static String Meter = null; public static String Time = null; diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Wed Mar 21 12:07:41 2012 +0100 @@ -33,6 +33,9 @@ public class CanonicalizerPhase extends Phase { private static final int MAX_ITERATION_PER_NODE = 10; + private static final DebugMetric METRIC_CANONICALIZED_NODES = Debug.metric("CanonicalizedNodes"); + private static final DebugMetric METRIC_CANONICALIZATION_CONSIDERED_NODES = Debug.metric("CanonicalizationConsideredNodes"); + private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes"); private boolean newNodes; private final CiTarget target; @@ -64,7 +67,9 @@ graph.trackInputChange(nodeWorkList); Tool tool = new Tool(nodeWorkList, runtime, target, assumptions); for (Node node : nodeWorkList) { + METRIC_PROCESSED_NODES.increment(); if (node instanceof Canonicalizable) { + METRIC_CANONICALIZATION_CONSIDERED_NODES.increment(); Debug.log("Canonicalizer: work on %s", node); graph.mark(); ValueNode canonical = ((Canonicalizable) node).canonical(tool); @@ -81,6 +86,7 @@ // -------------------------------------------- // X: must not happen (checked with assertions) if (canonical != node) { + METRIC_CANONICALIZED_NODES.increment(); if (node instanceof FloatingNode) { if (canonical == null) { // case 1 @@ -116,6 +122,7 @@ nodeWorkList.addAll(graph.getNewNodes()); } } else if (node instanceof Simplifiable) { + METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment(); ((Simplifiable) node).simplify(tool); } } diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/Phase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/Phase.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/Phase.java Wed Mar 21 12:07:41 2012 +0100 @@ -28,6 +28,8 @@ public abstract class Phase { private String name; + private static final DebugMetric metricPhaseRuns = Debug.metric("Runs"); + protected static final DebugMetric METRIC_PROCESSED_NODES = Debug.metric("ProcessedNodes"); protected Phase() { this.name = this.getClass().getSimpleName(); @@ -52,6 +54,7 @@ Debug.scope(name, this, new Runnable() { public void run() { Phase.this.run(graph); + metricPhaseRuns.increment(); if (dumpGraph) { Debug.dump(graph, "After phase %s", name); } diff -r 09f638813477 -r 4eb9895d9afe 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 Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Wed Mar 21 12:07:41 2012 +0100 @@ -41,7 +41,6 @@ private DebugValueMap valueMap; private String qualifiedName; - private String name; private static final char SCOPE_SEP = '.'; @@ -67,11 +66,23 @@ } private DebugScope(String name, String qualifiedName, DebugScope parent, Object... context) { - this.name = name; this.parent = parent; this.context = context; this.qualifiedName = qualifiedName; assert context != null; + + if (parent != null) { + for (DebugValueMap child : parent.getValueMap().getChildren()) { + if (child.getName().equals(name)) { + this.valueMap = child; + return; + } + } + this.valueMap = new DebugValueMap(name); + parent.getValueMap().addChild(this.valueMap); + } else { + this.valueMap = new DebugValueMap(name); + } } public boolean isDumpEnabled() { @@ -123,9 +134,6 @@ try (TimerCloseable a = scopeTime.start()) { return executeScope(runnable, callable); } finally { - if (!sandbox && newChild.hasValueMap()) { - getValueMap().addChild(newChild.getValueMap()); - } newChild.context = null; instanceTL.set(oldContext); setConfig(oldConfig); @@ -133,6 +141,7 @@ } private T executeScope(Runnable runnable, Callable callable) { + try { if (runnable != null) { runnable.run(); @@ -191,16 +200,9 @@ } private DebugValueMap getValueMap() { - if (valueMap == null) { - valueMap = new DebugValueMap(name); - } return valueMap; } - private boolean hasValueMap() { - return valueMap != null; - } - long getCurrentValue(int index) { return getValueMap().getCurrentValue(index); } diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValue.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValue.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValue.java Wed Mar 21 12:07:41 2012 +0100 @@ -22,7 +22,7 @@ */ package com.oracle.graal.debug.internal; -public class DebugValue { +public abstract class DebugValue { private String name; private int index; @@ -59,4 +59,6 @@ public String getName() { return name; } + + public abstract String toString(long value); } diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java Wed Mar 21 12:07:41 2012 +0100 @@ -46,6 +46,12 @@ return values[index]; } + public void clearChildren() { + if (children != null) { + children.clear(); + } + } + private void ensureSize(int index) { if (values == null) { values = new long[index + 1]; diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java Wed Mar 21 12:07:41 2012 +0100 @@ -39,4 +39,9 @@ super.addToCurrentValue(value); } } + + @Override + public String toString(long value) { + return Long.toString(value); + } } diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java Wed Mar 21 12:07:41 2012 +0100 @@ -32,6 +32,8 @@ } }; + private ThreadLocal valueToSubstract = new ThreadLocal<>(); + public TimerImpl(String name) { super(name); } @@ -39,16 +41,29 @@ @Override public TimerCloseable start() { if (Debug.isTimeEnabled()) { - final long startTime = System.currentTimeMillis(); - return new TimerCloseable() { + final long startTime = System.nanoTime(); + if (valueToSubstract.get() == null) { + valueToSubstract.set(0L); + } + final long previousValueToSubstract = valueToSubstract.get(); + TimerCloseable result = new TimerCloseable() { @Override public void close() { - long timeSpan = System.currentTimeMillis() - startTime; - TimerImpl.this.addToCurrentValue(timeSpan); + long timeSpan = System.nanoTime() - startTime; + long oldValueToSubstract = valueToSubstract.get(); + valueToSubstract.set(timeSpan + previousValueToSubstract); + TimerImpl.this.addToCurrentValue(timeSpan - oldValueToSubstract); } }; + valueToSubstract.set(0L); + return result; } else { return VOID_CLOSEABLE; } } + + @Override + public String toString(long value) { + return String.format("%d.%d ms", value / 1000000, (value / 100000) % 10); + } } diff -r 09f638813477 -r 4eb9895d9afe graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java Wed Mar 21 12:07:41 2012 +0100 @@ -0,0 +1,56 @@ +/* + * 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.graal.hotspot; + +import java.util.concurrent.*; + +import com.oracle.graal.compiler.*; +import com.oracle.graal.debug.*; + + +public final class CompilerThread extends Thread { + + public static final ThreadFactory FACTORY = new ThreadFactory() { + + @Override + public Thread newThread(Runnable r) { + return new CompilerThread(r); + } + }; + + private CompilerThread(Runnable r) { + super(r); + this.setName("GraalCompilerThread-" + this.getId()); + this.setDaemon(true); + } + + @Override + public void run() { + if (GraalOptions.Debug) { + Debug.enable(); + HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter); + Debug.setConfig(hotspotDebugConfig); + } + super.run(); + } +} diff -r 09f638813477 -r 4eb9895d9afe 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 Mon Mar 19 13:33:49 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Mar 21 12:07:41 2012 +0100 @@ -63,33 +63,6 @@ public final HotSpotTypePrimitive typeLong; public final HotSpotTypePrimitive typeVoid; - ThreadFactory compilerThreadFactory = new ThreadFactory() { - - @Override - public Thread newThread(Runnable r) { - return new CompilerThread(r); - } - }; - - private final class CompilerThread extends Thread { - - public CompilerThread(Runnable r) { - super(r); - this.setName("GraalCompilerThread-" + this.getId()); - this.setDaemon(true); - } - - @Override - public void run() { - if (GraalOptions.Debug) { - Debug.enable(); - HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter); - Debug.setConfig(hotspotDebugConfig); - } - super.run(); - } - } - private ThreadPoolExecutor compileQueue; public VMToCompilerImpl(Compiler compiler) { @@ -119,6 +92,7 @@ final HotSpotRuntime runtime = (HotSpotRuntime) compiler.getCompiler().runtime; if (GraalOptions.Intrinsify) { Debug.scope("InstallSnippets", new DebugDumpScope("InstallSnippets"), new Runnable() { + @Override public void run() { VMToCompilerImpl.this.intrinsifyArrayCopy = new IntrinsifyArrayCopyPhase(runtime); @@ -132,7 +106,7 @@ } // Create compilation queue. - compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), compilerThreadFactory); + compileQueue = new ThreadPoolExecutor(GraalOptions.Threads, GraalOptions.Threads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), CompilerThread.FACTORY); // Create queue status printing thread. if (GraalOptions.PrintQueue) { @@ -198,8 +172,6 @@ } public void shutdownCompiler() throws Throwable { - // compiler.getCompiler().context.print(); - // TODO (thomaswue): Print context results. compileQueue.shutdown(); if (Debug.isEnabled()) { @@ -208,13 +180,29 @@ if (debugValues.size() > 0) { if (GraalOptions.SummarizeDebugValues) { printSummary(topLevelMaps, debugValues); - } else { + } else if (GraalOptions.PerThreadDebugValues) { for (DebugValueMap map : topLevelMaps) { TTY.println("Showing the results for thread: " + map.getName()); map.group(); map.normalize(); printMap(map, debugValues, 0); } + } else { + DebugValueMap globalMap = new DebugValueMap("Global"); + for (DebugValueMap map : topLevelMaps) { + if (GraalOptions.SummarizePerPhase) { + flattenChildren(map, globalMap); + } else { + for (DebugValueMap child : map.getChildren()) { + globalMap.addChild(child); + } + } + } + if (!GraalOptions.SummarizePerPhase) { + globalMap.group(); + } + globalMap.normalize(); + printMap(globalMap, debugValues, 0); } } } @@ -224,6 +212,14 @@ } } + private void flattenChildren(DebugValueMap map, DebugValueMap globalMap) { + globalMap.addChild(map); + for (DebugValueMap child : map.getChildren()) { + flattenChildren(child, globalMap); + } + map.clearChildren(); + } + private void printCompilationStatistics() { TTY.println("Accumulated compilation statistics"); TTY.println(" Compiled methods : %d", compiledMethodCount); @@ -256,16 +252,15 @@ return total; } - private static void printMap(DebugValueMap map, List debugValues, int level) { printIndent(level); - TTY.println(map.getName()); + TTY.println("%s", map.getName()); for (DebugValue value : debugValues) { long l = map.getCurrentValue(value.getIndex()); if (l != 0) { printIndent(level + 1); - TTY.println(value.getName() + "=" + l); + TTY.println(value.getName() + "=" + value.toString(l)); } } @@ -313,6 +308,7 @@ long nanoTime; try { result = Debug.scope("Compiling", new Callable() { + @Override public CiTargetMethod call() throws Exception { return compiler.getCompiler().compileMethod(method, -1, plan); @@ -323,8 +319,8 @@ nanoTime = System.nanoTime() - startTime; totalCompilationTime += nanoTime; if (printCompilation) { - TTY.println(String.format("Graal %4d %-70s %-45s %-50s | %3d.%dms %4dnodes %5dB", index, "", "", "", nanoTime / 1000000, nanoTime % 1000000, 0, (result != null ? result.targetCodeSize() - : -1))); + TTY.println(String.format("Graal %4d %-70s %-45s %-50s | %3d.%dms %4dnodes %5dB", index, "", "", "", nanoTime / 1000000, nanoTime % 1000000, 0, + (result != null ? result.targetCodeSize() : -1))); } } compiler.getRuntime().installMethod(method, result);