# HG changeset patch # User Jaroslav Tulach # Date 1444119922 -7200 # Node ID 141fe31da7a2f415d83766a28803f8ad13f12965 # Parent 371045b1312d412bafa29882e6c3f7bfe6c0f8f1 Avoiding check for current stack depth on the initialization of debugger. Only when debugger is suspended the real check is needed. diff -r 371045b1312d -r 141fe31da7a2 truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java --- a/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java Thu Oct 01 20:32:49 2015 +0200 +++ b/truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java Tue Oct 06 10:25:22 2015 +0200 @@ -510,7 +510,7 @@ @SuppressWarnings("try") private void evalImpl(TruffleLanguage[] fillLang, Source s, Object[] result, Language l, CountDownLatch ready) { - try (Closeable d = SPI.executionStart(this, debugger, s)) { + try (Closeable d = SPI.executionStart(this, -1, debugger, s)) { TruffleLanguage langImpl = l.getImpl(true); fillLang[0] = langImpl; result[0] = SPI.eval(langImpl, s); @@ -527,7 +527,7 @@ executor.execute(new Runnable() { @Override public void run() { - try (final Closeable c = SPI.executionStart(PolyglotEngine.this, debugger, null)) { + try (final Closeable c = SPI.executionStart(PolyglotEngine.this, -1, debugger, null)) { res[0] = ForeignAccess.execute(foreignNode, frame, receiver, ForeignAccess.getArguments(frame).toArray()); } catch (IOException ex) { res[1] = ex; @@ -758,7 +758,7 @@ @SuppressWarnings("try") private void invokeImpl(Object thiz, Object[] args, Object[] res, CountDownLatch done) { - try (final Closeable c = SPI.executionStart(PolyglotEngine.this, debugger, null)) { + try (final Closeable c = SPI.executionStart(PolyglotEngine.this, -1, debugger, null)) { List arr = new ArrayList<>(); if (thiz == null) { if (language != null) { @@ -993,9 +993,9 @@ } @Override - protected Closeable executionStart(Object obj, Debugger debugger, Source s) { + protected Closeable executionStart(Object obj, int currentDepth, Debugger debugger, Source s) { PolyglotEngine vm = (PolyglotEngine) obj; - return super.executionStart(vm, debugger, s); + return super.executionStart(vm, -1, debugger, s); } @Override diff -r 371045b1312d -r 141fe31da7a2 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java Thu Oct 01 20:32:49 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java Tue Oct 06 10:25:22 2015 +0200 @@ -121,8 +121,8 @@ Source.setFileCaching(true); // Initialize execution context stack - debugContext = new DebugExecutionContext(null, null); - prepareContinue(); + debugContext = new DebugExecutionContext(null, null, 0); + debugContext.setStrategy(0, new Continue()); debugContext.contextTrace("START EXEC DEFAULT"); breakpointCallback = new BreakpointCallback() { @@ -197,8 +197,8 @@ * */ @TruffleBoundary - void prepareContinue() { - debugContext.setStrategy(new Continue()); + void prepareContinue(int depth) { + debugContext.setStrategy(depth, new Continue()); } /** @@ -702,12 +702,16 @@ private MaterializedFrame haltedFrame; private DebugExecutionContext(Source executionSource, DebugExecutionContext previousContext) { + this(executionSource, previousContext, -1); + } + + private DebugExecutionContext(Source executionSource, DebugExecutionContext previousContext, int depth) { this.source = executionSource; this.predecessor = previousContext; this.level = previousContext == null ? 0 : previousContext.level + 1; // "Base" is the number of stack frames for all nested (halted) executions. - this.contextStackBase = currentStackDepth(); + this.contextStackBase = depth == -1 ? currentStackDepth() : depth; this.running = true; contextTrace("NEW CONTEXT"); } @@ -718,9 +722,13 @@ * @param stepStrategy */ void setStrategy(StepStrategy stepStrategy) { + setStrategy(currentStackDepth(), stepStrategy); + } + + void setStrategy(int depth, StepStrategy stepStrategy) { if (this.strategy == null) { this.strategy = stepStrategy; - this.strategy.enable(this, currentStackDepth()); + this.strategy.enable(this, depth); if (TRACE) { contextTrace("SET MODE -->" + stepStrategy.getName()); } @@ -832,7 +840,7 @@ } - void executionStarted(Source source) { + void executionStarted(int depth, Source source) { Source execSource = source; if (execSource == null) { execSource = lastSource; @@ -840,8 +848,8 @@ lastSource = execSource; } // Push a new execution context onto stack - debugContext = new DebugExecutionContext(execSource, debugContext); - prepareContinue(); + debugContext = new DebugExecutionContext(execSource, debugContext, depth); + prepareContinue(depth); debugContext.contextTrace("START EXEC "); ACCESSOR.dispatchEvent(vm, new ExecutionEvent(this)); } @@ -863,8 +871,8 @@ private static final class AccessorDebug extends Accessor { @Override - protected Closeable executionStart(Object vm, final Debugger debugger, Source s) { - debugger.executionStarted(s); + protected Closeable executionStart(Object vm, int currentDepth, final Debugger debugger, Source s) { + debugger.executionStarted(currentDepth, s); return new Closeable() { @Override public void close() throws IOException { diff -r 371045b1312d -r 141fe31da7a2 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/ExecutionEvent.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/ExecutionEvent.java Thu Oct 01 20:32:49 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/ExecutionEvent.java Tue Oct 06 10:25:22 2015 +0200 @@ -70,7 +70,7 @@ * */ public void prepareContinue() { - debugger.prepareContinue(); + debugger.prepareContinue(-1); } /** diff -r 371045b1312d -r 141fe31da7a2 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java Thu Oct 01 20:32:49 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java Tue Oct 06 10:25:22 2015 +0200 @@ -128,7 +128,7 @@ * */ public void prepareContinue() { - debugger.prepareContinue(); + debugger.prepareContinue(-1); } /** diff -r 371045b1312d -r 141fe31da7a2 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Thu Oct 01 20:32:49 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Tue Oct 06 10:25:22 2015 +0200 @@ -281,10 +281,11 @@ private static Reference previousVM = new WeakReference<>(null); private static Assumption oneVM = Truffle.getRuntime().createAssumption(); - protected Closeable executionStart(Object vm, Debugger debugger, Source s) { + @SuppressWarnings("unused") + protected Closeable executionStart(Object vm, int currentDepth, Debugger debugger, Source s) { vm.getClass(); - final Closeable debugClose = DEBUG.executionStart(vm, debugger, s); final Object prev = CURRENT_VM.get(); + final Closeable debugClose = DEBUG.executionStart(vm, prev == null ? 0 : -1, debugger, s); if (!(vm == previousVM.get())) { previousVM = new WeakReference<>(vm); oneVM.invalidate();