# HG changeset patch # User Doug Simon # Date 1337776796 -7200 # Node ID 50598118cd0a61440de0b28b1bd1014ca1e10330 # Parent 0bd1ba69db2a7c2d759e0df04fee3bf33a5f670c added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method diff -r 0bd1ba69db2a -r 50598118cd0a graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java Wed May 23 12:11:27 2012 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java Wed May 23 14:39:56 2012 +0200 @@ -22,16 +22,24 @@ */ package com.oracle.graal.debug; -public final class DebugDumpScope { +public class DebugDumpScope { + + public final String name; - private final String name; + /** + * Specifies if this scope decorates an inner scope. + * A hierarchical or tree representation of nested scopes may choose to represent + * a decorator scope at the same level as the scope it decorates. + */ + public final boolean decorator; public DebugDumpScope(String name) { - this.name = name; + this(name, false); } - public String getName() { - return name; + public DebugDumpScope(String name, boolean decorator) { + this.name = name; + this.decorator = decorator; } @Override diff -r 0bd1ba69db2a -r 50598118cd0a graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed May 23 12:11:27 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed May 23 14:39:56 2012 +0200 @@ -111,7 +111,7 @@ CiTargetMethod result = null; TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); try { - result = Debug.scope("Compiling", new Callable() { + result = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true), new Callable() { @Override public CiTargetMethod call() throws Exception { @@ -148,7 +148,7 @@ } private void installMethod(final CiTargetMethod tm) { - Debug.scope("CodeInstall", new Object[] {compiler.getCompiler(), method}, new Runnable() { + Debug.scope("CodeInstall", new Object[] {new DebugDumpScope(String.valueOf(id), true), compiler.getCompiler(), method}, new Runnable() { @Override public void run() { final RiCodeInfo[] info = Debug.isDumpEnabled() ? new RiCodeInfo[1] : null; diff -r 0bd1ba69db2a -r 50598118cd0a graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed May 23 12:11:27 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed May 23 14:39:56 2012 +0200 @@ -47,6 +47,7 @@ private CFGPrinter cfgPrinter; private RiResolvedMethod curMethod; + private List curDecorators = Collections.emptyList(); @Override public void dump(Object object, String message) { @@ -57,14 +58,37 @@ } } - private static RiResolvedMethod lookupMethod() { - RiResolvedMethod method = Debug.contextLookup(RiResolvedMethod.class); - if (method != null) { - return method; + /** + * Looks for the outer most method and its {@link DebugDumpScope#decorator}s + * in the current debug scope and opens a new compilation scope if this pair + * does not match the current method and decorator pair. + */ + private void checkMethodScope() { + RiResolvedMethod method = null; + ArrayList decorators = new ArrayList<>(); + for (Object o : Debug.context()) { + if (o instanceof RiResolvedMethod) { + method = (RiResolvedMethod) o; + decorators.clear(); + } else if (o instanceof StructuredGraph) { + StructuredGraph graph = (StructuredGraph) o; + assert graph != null && graph.method() != null : "cannot find method context for CFG dump"; + method = graph.method(); + decorators.clear(); + } else if (o instanceof DebugDumpScope) { + DebugDumpScope debugDumpScope = (DebugDumpScope) o; + if (debugDumpScope.decorator) { + decorators.add(debugDumpScope.name); + } + } } - StructuredGraph graph = Debug.contextLookup(StructuredGraph.class); - assert graph != null && graph.method() != null : "cannot find method context for CFG dump"; - return graph.method(); + + if (method != curMethod || !curDecorators.equals(decorators)) { + cfgPrinter.printCompilation(method); + TTY.println("CFGPrinter: Dumping method %s", method); + curMethod = method; + curDecorators = decorators; + } } public void dumpSandboxed(Object object, String message) { @@ -84,13 +108,7 @@ TTY.println("CFGPrinter: Output to file %s", file); } - RiResolvedMethod newMethod = lookupMethod(); - - if (newMethod != curMethod) { - cfgPrinter.printCompilation(newMethod); - TTY.println("CFGPrinter: Dumping method %s", newMethod); - curMethod = newMethod; - } + checkMethodScope(); cfgPrinter.target = compiler.target; if (object instanceof LIR) { diff -r 0bd1ba69db2a -r 50598118cd0a graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java Wed May 23 12:11:27 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java Wed May 23 14:39:56 2012 +0200 @@ -123,7 +123,7 @@ for (int i = 0; i < inlineContext.size(); ++i) { if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) { for (int j = i; j < inlineContext.size(); ++j) { - openScope(inlineContext.get(j)); + openScope(inlineContext.get(j), j == 0); } break; } @@ -153,14 +153,19 @@ result.add(CiUtil.format("%H::%n(%p)", method)); } else if (o instanceof DebugDumpScope) { DebugDumpScope debugDumpScope = (DebugDumpScope) o; - result.add(debugDumpScope.getName()); + if (debugDumpScope.decorator && !result.isEmpty()) { + result.set(result.size() - 1, debugDumpScope.name + ":" + result.get(result.size() - 1)); + } else { + result.add(debugDumpScope.name); + } } } return result; } - private void openScope(String name) { - printer.beginGroup(Thread.currentThread().getName() + ":" + name, name, Debug.contextLookup(RiResolvedMethod.class), -1); + private void openScope(String name, boolean showThread) { + String prefix = showThread ? Thread.currentThread().getName() + ":" : ""; + printer.beginGroup(prefix + name, name, Debug.contextLookup(RiResolvedMethod.class), -1); } private void closeScope() {