# HG changeset patch # User Thomas Wuerthinger # Date 1327072781 -3600 # Node ID 18b52fec79f1f88cec27c53a421c09163f0af4cc # Parent d203d8b2572119fa610da062697b20e917367a0b Completed exception interception. diff -r d203d8b25721 -r 18b52fec79f1 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 Fri Jan 20 15:43:15 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Fri Jan 20 16:19:41 2012 +0100 @@ -131,7 +131,7 @@ this.registers = target.arch.registers; this.firstVariableNumber = registers.length; - this.variables = new ArrayList<>(ir.numVariables() * 3 / 2); + this.variables = new ArrayList<>(ir.numVariables() * 3 / 2); throw new NullPointerException(); } public static boolean isVariableOrRegister(CiValue value) { diff -r d203d8b25721 -r 18b52fec79f1 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 Fri Jan 20 15:43:15 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java Fri Jan 20 16:19:41 2012 +0100 @@ -25,7 +25,7 @@ import com.oracle.max.graal.debug.internal.DebugScope; import com.oracle.max.graal.debug.internal.MetricImpl; import com.oracle.max.graal.debug.internal.TimerImpl; -import java.util.Collections; +import java.util.*; import java.util.concurrent.*; @@ -97,6 +97,18 @@ } } + public static List contextSnapshot() { + if (ENABLED) { + List result = new ArrayList<>(); + for (Object o : context()) { + result.add(o); + } + return result; + } else { + return Collections.emptyList(); + } + } + public static DebugMetric metric(String name) { if (ENABLED && DebugScope.getInstance().isMeterEnabled()) { return new MetricImpl(name); @@ -111,6 +123,36 @@ } } + public static DebugConfig fixedConfix(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled) { + return new DebugConfig() { + + @Override + public boolean isLogEnabled() { + return isLogEnabled; + } + + @Override + public boolean isMeterEnabled() { + return isMeterEnabled; + } + + @Override + public boolean isDumpEnabled() { + return isDumpEnabled; + } + + @Override + public boolean isTimerEnabled() { + return isTimerEnabled; + } + + @Override + public RuntimeException interceptException(RuntimeException e) { + return e; + } + }; + } + private static final DebugMetric VOID_METRIC = new DebugMetric() { public void increment() { } public void add(int value) { } diff -r d203d8b25721 -r 18b52fec79f1 graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java --- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java Fri Jan 20 15:43:15 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java Fri Jan 20 16:19:41 2012 +0100 @@ -28,4 +28,5 @@ boolean isMeterEnabled(); boolean isDumpEnabled(); boolean isTimerEnabled(); + RuntimeException interceptException(RuntimeException e); } diff -r d203d8b25721 -r 18b52fec79f1 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 Fri Jan 20 15:43:15 2012 +0100 +++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java Fri Jan 20 16:19:41 2012 +0100 @@ -31,8 +31,9 @@ public final class DebugScope { - private static ThreadLocal instance = new ThreadLocal<>(); - private static ThreadLocal config = new ThreadLocal<>(); + private static ThreadLocal instanceTL = new ThreadLocal<>(); + private static ThreadLocal configTL = new ThreadLocal<>(); + private static ThreadLocal lastExceptionThrownTL = new ThreadLocal<>(); private final String name; private final DebugScope parent; @@ -52,17 +53,17 @@ private boolean dumpEnabled; public static DebugScope getInstance() { - DebugScope result = instance.get(); + DebugScope result = instanceTL.get(); if (result == null) { - instance.set(new DebugScope("DEFAULT", "DEFAULT", null)); - return instance.get(); + instanceTL.set(new DebugScope("DEFAULT", "DEFAULT", null)); + return instanceTL.get(); } else { return result; } } public static DebugConfig getConfig() { - return config.get(); + return configTL.get(); } private DebugScope(String name, String qualifiedName, DebugScope parent, Object... context) { @@ -107,7 +108,7 @@ } else { newChild = oldContext.createChild(newName, newContext); } - instance.set(newChild); + instanceTL.set(newChild); T result = null; updateFlags(); log("Starting scope %s", newChild.getQualifiedName()); @@ -119,10 +120,16 @@ result = call(callable); } } catch (RuntimeException e) { - throw interceptException(e); + if (e == lastExceptionThrownTL.get()) { + throw e; + } else { + RuntimeException newException = interceptException(e); + lastExceptionThrownTL.set(newException); + throw newException; + } } finally { newChild.deactivate(); - instance.set(oldContext); + instanceTL.set(oldContext); setConfig(oldConfig); } return result; @@ -147,7 +154,19 @@ context = null; } - private RuntimeException interceptException(RuntimeException e) { + private RuntimeException interceptException(final RuntimeException e) { + final DebugConfig config = getConfig(); + if (config != null) { + return scope("InterceptException", null, new Callable(){ + @Override + public RuntimeException call() throws Exception { + try { + return config.interceptException(e); + } catch (Throwable t) { + return e; + } + }}, false, new Object[]{e}); + } return e; } @@ -230,7 +249,7 @@ } public void setConfig(DebugConfig newConfig) { - config.set(newConfig); + configTL.set(newConfig); updateFlags(); } diff -r d203d8b25721 -r 18b52fec79f1 graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java Fri Jan 20 15:43:15 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java Fri Jan 20 16:19:41 2012 +0100 @@ -24,6 +24,7 @@ import com.oracle.max.cri.ri.*; import com.oracle.max.graal.debug.*; +import com.oracle.max.graal.graph.*; public class HotSpotDebugConfig implements DebugConfig { @@ -98,4 +99,19 @@ sb.append(filter); } } + + @Override + public RuntimeException interceptException(RuntimeException e) { + Debug.setConfig(Debug.fixedConfix(true, true, false, false)); + Debug.log(String.format("Exception occured in scope: %s", Debug.currentScope())); + for (Object o : Debug.context()) { + Debug.log("Context obj %s", o); + if (o instanceof Graph) { + Graph graph = (Graph) o; + Debug.log("Found graph in context: ", graph); + Debug.dump(o, "Exception graph"); + } + } + return e; + } }