Mercurial > hg > truffle
diff graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java @ 4369:efc430d943c0
Drafted regexp filters. Rewrote logging statements of floating read phase.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 26 Jan 2012 18:33:58 +0100 |
parents | 7462c3600c3a |
children | a04feadb1d47 |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java Thu Jan 26 17:26:42 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java Thu Jan 26 18:33:58 2012 +0100 @@ -44,7 +44,6 @@ private DebugValueMap valueMap; private String qualifiedName; - public static final DebugScope DEFAULT_CONTEXT = new DebugScope("DEFAULT", "DEFAULT", null); private static final char SCOPE_SEP = '.'; private boolean logEnabled; @@ -55,7 +54,7 @@ public static DebugScope getInstance() { DebugScope result = instanceTL.get(); if (result == null) { - instanceTL.set(new DebugScope("DEFAULT", "DEFAULT", null)); + instanceTL.set(new DebugScope("", "", null)); return instanceTL.get(); } else { return result; @@ -107,6 +106,8 @@ } } + private static Object lock = new Object(); + public <T> T scope(String newName, Runnable runnable, Callable<T> callable, boolean sandbox, Object[] newContext) { DebugScope oldContext = getInstance(); DebugConfig oldConfig = getConfig(); @@ -118,15 +119,30 @@ newChild = oldContext.createChild(newName, newContext); } instanceTL.set(newChild); - T result = null; newChild.updateFlags(); - newChild.log("Starting scope %s", newChild.getQualifiedName()); try { + if (logEnabled || dumpEnabled) { + synchronized (lock) { + return executeScope(runnable, callable); + } + } else { + return executeScope(runnable, callable); + } + } finally { + newChild.deactivate(); + instanceTL.set(oldContext); + setConfig(oldConfig); + } + } + + private <T> T executeScope(Runnable runnable, Callable<T> callable) { + try { + instanceTL.get().log("Starting scope %s", instanceTL.get().getQualifiedName()); if (runnable != null) { runnable.run(); } if (callable != null) { - result = call(callable); + return call(callable); } } catch (RuntimeException e) { if (e == lastExceptionThrownTL.get()) { @@ -136,12 +152,8 @@ lastExceptionThrownTL.set(newException); throw newException; } - } finally { - newChild.deactivate(); - instanceTL.set(oldContext); - setConfig(oldConfig); } - return result; + return null; } private void updateFlags() { @@ -195,7 +207,10 @@ } private DebugScope createChild(String newName, Object[] newContext) { - String newQualifiedName = this.qualifiedName + SCOPE_SEP + newName; + String newQualifiedName = newName; + if (this.qualifiedName.length() > 0) { + newQualifiedName = this.qualifiedName + SCOPE_SEP + newName; + } DebugScope result = new DebugScope(newName, newQualifiedName, this, newContext); if (children == null) { children = new ArrayList<>(4);