# HG changeset patch # User Tom Rodriguez # Date 1430251120 25200 # Node ID 0b221b4ad707ab8ed22aa8b5114691fb689e443c # Parent 2b1228d975256b23b802467842acaa5d34ea7942# Parent 7a62f41ed61081faa758480357063b9256ee6b30 Merge diff -r 7a62f41ed610 -r 0b221b4ad707 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Tue Apr 28 12:58:40 2015 -0700 @@ -172,7 +172,12 @@ } private int getLevel(DebugFilter filter) { - int level = checkDebugFilter(Debug.currentScope(), filter); + int level; + if (filter == null) { + level = 0; + } else { + level = filter.matchLevel(Debug.currentScope()); + } if (level > 0 && !checkMethodFilter()) { level = 0; } @@ -183,14 +188,6 @@ return filter != null && checkMethodFilter(); } - private static int checkDebugFilter(String currentScope, DebugFilter filter) { - if (filter == null) { - return 0; - } else { - return filter.matchLevel(currentScope); - } - } - /** * Extracts a {@link JavaMethod} from an opaque debug context. * diff -r 7a62f41ed610 -r 0b221b4ad707 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java Tue Apr 28 12:58:40 2015 -0700 @@ -76,32 +76,32 @@ static Result wrongClass(Node node, MatchPattern matcher) { MatchResult_WRONG_CLASS.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS; + return Debug.isLogEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS; } static Result namedValueMismatch(Node node, MatchPattern matcher) { MatchResult_NAMED_VALUE_MISMATCH.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH; + return Debug.isLogEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH; } static Result tooManyUsers(Node node, MatchPattern matcher) { MatchResult_TOO_MANY_USERS.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS; + return Debug.isLogEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS; } static Result notInBlock(Node node, MatchPattern matcher) { MatchResult_NOT_IN_BLOCK.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK; + return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK; } static Result notSafe(Node node, MatchPattern matcher) { MatchResult_NOT_SAFE.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE; + return Debug.isLogEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE; } static Result alreadyUsed(Node node, MatchPattern matcher) { MatchResult_ALREADY_USED.increment(); - return Debug.isEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED; + return Debug.isLogEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED; } @Override diff -r 7a62f41ed610 -r 0b221b4ad707 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 Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Tue Apr 28 12:58:40 2015 -0700 @@ -738,8 +738,8 @@ * {@linkplain Indent#close() closed} or null if debugging is disabled */ public static Indent logAndIndent(int logLevel, String msg) { - if (ENABLED) { - return logvAndIndent(logLevel, msg); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, msg); } return null; } @@ -757,8 +757,8 @@ * {@linkplain Indent#close() closed} or null if debugging is disabled */ public static Indent logAndIndent(int logLevel, String format, Object arg) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg); } return null; } @@ -776,8 +776,8 @@ * {@linkplain Indent#close() closed} or null if debugging is disabled */ public static Indent logAndIndent(int logLevel, String format, int arg) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg); } return null; } @@ -790,8 +790,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, int arg1, Object arg2) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); } return null; } @@ -804,8 +804,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); } return null; } @@ -818,8 +818,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); } return null; } @@ -832,8 +832,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2); } return null; } @@ -846,8 +846,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); } return null; } @@ -860,8 +860,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2, int arg3) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); } return null; } @@ -874,8 +874,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2, int arg3) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); } return null; } @@ -888,8 +888,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3, arg4); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4); } return null; } @@ -902,8 +902,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3, arg4, arg5); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5); } return null; } @@ -916,8 +916,8 @@ * @see #logAndIndent(int, String, Object) */ public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - if (ENABLED) { - return logvAndIndent(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); + if (ENABLED && Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); } return null; } @@ -933,13 +933,21 @@ */ public static Indent logvAndIndent(int logLevel, String format, Object... args) { if (ENABLED) { - DebugScope scope = DebugScope.getInstance(); - scope.log(logLevel, format, args); - return scope.pushIndentLogger(); + if (Debug.isLogEnabled(logLevel)) { + return logvAndIndentInternal(logLevel, format, args); + } + return null; } throw new InternalError("Use of Debug.logvAndIndent() must be guarded by a test of Debug.isEnabled()"); } + private static Indent logvAndIndentInternal(int logLevel, String format, Object... args) { + assert ENABLED && Debug.isLogEnabled(logLevel) : "must have checked Debug.isLogEnabled()"; + DebugScope scope = DebugScope.getInstance(); + scope.log(logLevel, format, args); + return scope.pushIndentLogger(); + } + /** * This override exists to catch cases when {@link #logAndIndent(String, Object)} is called with * one argument bound to a varargs method parameter. It will bind to this method instead of the diff -r 7a62f41ed610 -r 0b221b4ad707 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 Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Tue Apr 28 12:58:40 2015 -0700 @@ -47,7 +47,7 @@ if (parentIndent != null) { parentIndent.printScopeName(str); } - str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(qualifiedName).append(System.lineSeparator()); + str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(getQualifiedName()).append(System.lineSeparator()); logScopeName = false; } } @@ -92,8 +92,10 @@ private final Object[] context; - private final DebugValueMap valueMap; - private final String qualifiedName; + private DebugValueMap valueMap; + + private String qualifiedName; + private final String unqualifiedName; private static final char SCOPE_SEP = '.'; @@ -110,9 +112,8 @@ public static DebugScope getInstance() { DebugScope result = instanceTL.get(); if (result == null) { - DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread().getName(), "", null, false); + DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread()); instanceTL.set(topLevelDebugScope); - DebugValueMap.registerTopLevel(topLevelDebugScope.getValueMap()); return topLevelDebugScope; } else { return result; @@ -123,17 +124,23 @@ return configTL.get(); } - private DebugScope(String name, String qualifiedName, DebugScope parent, boolean sandbox, Object... context) { + static final Object[] EMPTY_CONTEXT = new Object[0]; + + private DebugScope(Thread thread) { + this(thread.getName(), null, false); + computeValueMap(thread.getName()); + DebugValueMap.registerTopLevel(getValueMap()); + } + + private DebugScope(String unqualifiedName, DebugScope parent, boolean sandbox, Object... context) { this.parent = parent; this.sandbox = sandbox; this.parentConfig = getConfig(); this.context = context; - this.qualifiedName = qualifiedName; + this.unqualifiedName = unqualifiedName; if (parent != null) { - lastUsedIndent = new IndentImpl(parent.lastUsedIndent); - logScopeName = !parent.qualifiedName.equals(qualifiedName); + logScopeName = !unqualifiedName.equals(""); } else { - lastUsedIndent = new IndentImpl(null); logScopeName = true; } @@ -141,7 +148,9 @@ // set while logging this.output = TTY.cachedOut; assert context != null; + } + private void computeValueMap(String name) { if (parent != null) { for (DebugValueMap child : parent.getValueMap().getChildren()) { if (child.getName().equals(name)) { @@ -240,7 +249,9 @@ } public void log(int logLevel, String msg, Object... args) { - lastUsedIndent.log(logLevel, msg, args); + if (isLogEnabled(logLevel)) { + getLastUsedIndent().log(logLevel, msg, args); + } } public void dump(int dumpLevel, Object object, String formatString, Object... args) { @@ -297,7 +308,7 @@ public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) { DebugScope newScope = null; if (sandboxConfig != null) { - newScope = new DebugScope(name.toString(), name.toString(), this, true, newContextObjects); + newScope = new DebugScope(name.toString(), this, true, newContextObjects); configTL.set(sandboxConfig); } else { newScope = this.createChild(name.toString(), newContextObjects); @@ -371,6 +382,9 @@ } private DebugValueMap getValueMap() { + if (valueMap == null) { + computeValueMap(unqualifiedName); + } return valueMap; } @@ -383,12 +397,7 @@ } private DebugScope createChild(String newName, Object[] newContext) { - String newQualifiedName = newName; - if (this.qualifiedName.length() > 0) { - newQualifiedName = this.qualifiedName + SCOPE_SEP + newName; - } - DebugScope result = new DebugScope(newName, newQualifiedName, this, false, newContext); - return result; + return new DebugScope(newName, this, false, newContext); } public Iterable getCurrentContext() { @@ -451,11 +460,29 @@ } public String getQualifiedName() { + if (qualifiedName == null) { + if (parent == null) { + qualifiedName = unqualifiedName; + } else { + qualifiedName = parent.getQualifiedName() + SCOPE_SEP + unqualifiedName; + } + } return qualifiedName; } public Indent pushIndentLogger() { - lastUsedIndent = lastUsedIndent.indent(); + lastUsedIndent = getLastUsedIndent().indent(); + return lastUsedIndent; + } + + public IndentImpl getLastUsedIndent() { + if (lastUsedIndent == null) { + if (parent != null) { + lastUsedIndent = new IndentImpl(parent.getLastUsedIndent()); + } else { + lastUsedIndent = new IndentImpl(null); + } + } return lastUsedIndent; } } diff -r 7a62f41ed610 -r 0b221b4ad707 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 Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java Tue Apr 28 12:58:40 2015 -0700 @@ -28,8 +28,10 @@ public MetricImpl(String name, boolean conditional) { super(name, conditional); - // Allows for zero-count metrics to be shown - getCurrentValue(); + if (isEnabled()) { + // Allows for zero-count metrics to be shown + getCurrentValue(); + } } public void increment() { diff -r 7a62f41ed610 -r 0b221b4ad707 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Tue Apr 28 12:58:40 2015 -0700 @@ -388,10 +388,14 @@ if (!running) { startThreads(); } + int wakeups = 0; while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { - TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); + if (wakeups % 15 == 0) { + TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); + } try { - threadPool.awaitTermination(15, TimeUnit.SECONDS); + threadPool.awaitTermination(1, TimeUnit.SECONDS); + wakeups++; } catch (InterruptedException e) { } } diff -r 7a62f41ed610 -r 0b221b4ad707 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java Tue Apr 28 12:58:40 2015 -0700 @@ -60,6 +60,30 @@ */ private final DebugMemUseTracker memUseTracker; + private static class LIRPhaseStatistics { + /** + * Records time spent within {@link #apply}. + */ + private final DebugTimer timer; + + /** + * Records memory usage within {@link #apply}. + */ + private final DebugMemUseTracker memUseTracker; + + LIRPhaseStatistics(Class clazz) { + timer = Debug.timer("LIRPhaseTime_%s", clazz); + memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", clazz); + } + } + + private static final ClassValue statisticsClassValue = new ClassValue() { + @Override + protected LIRPhaseStatistics computeValue(Class c) { + return new LIRPhaseStatistics(c); + } + }; + private static final Pattern NAME_PATTERN = Pattern.compile("[A-Z][A-Za-z0-9]+"); private static boolean checkName(String name) { @@ -68,15 +92,17 @@ } public LIRPhase() { - timer = Debug.timer("LIRPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", getClass()); + LIRPhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + memUseTracker = statistics.memUseTracker; } protected LIRPhase(String name) { assert checkName(name); this.name = name; - timer = Debug.timer("LIRPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", getClass()); + LIRPhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + memUseTracker = statistics.memUseTracker; } public final > void apply(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, C context) { diff -r 7a62f41ed610 -r 0b221b4ad707 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Apr 28 18:35:16 2015 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Apr 28 12:58:40 2015 -0700 @@ -69,20 +69,59 @@ return true; } + private static class BasePhaseStatistics { + /** + * Records time spent in {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugTimer timer; + + /** + * Counts calls to {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMetric executionCount; + + /** + * Accumulates the {@linkplain Graph#getNodeCount() live node count} of all graphs sent to + * {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMetric inputNodesCount; + + /** + * Records memory usage within {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMemUseTracker memUseTracker; + + BasePhaseStatistics(Class clazz) { + timer = Debug.timer("PhaseTime_%s", clazz); + executionCount = Debug.metric("PhaseCount_%s", clazz); + memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", clazz); + inputNodesCount = Debug.metric("PhaseNodes_%s", clazz); + } + } + + private static final ClassValue statisticsClassValue = new ClassValue() { + @Override + protected BasePhaseStatistics computeValue(Class c) { + return new BasePhaseStatistics(c); + } + }; + protected BasePhase() { - timer = Debug.timer("PhaseTime_%s", getClass()); - executionCount = Debug.metric("PhaseCount_%s", getClass()); - memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", getClass()); - inputNodesCount = Debug.metric("PhaseNodes_%s", getClass()); + BasePhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + executionCount = statistics.executionCount; + memUseTracker = statistics.memUseTracker; + inputNodesCount = statistics.inputNodesCount; } protected BasePhase(String name) { assert checkName(name); this.name = name; - timer = Debug.timer("PhaseTime_%s", getClass()); - executionCount = Debug.metric("PhaseCount_%s", getClass()); - memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", getClass()); - inputNodesCount = Debug.metric("PhaseNodes_%s", getClass()); + BasePhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + executionCount = statistics.executionCount; + memUseTracker = statistics.memUseTracker; + inputNodesCount = statistics.inputNodesCount; } protected CharSequence getDetailedName() {