use of org.graalvm.polyglot.Source in project graal by oracle.
the class CompilationOfProfilerNodesTest method testInvalidationsDontPoluteShadowStack.
@Test
@SuppressWarnings("try")
public void testInvalidationsDontPoluteShadowStack() {
// Test assumes that foo will be inlined into bar
try (TruffleCompilerOptions.TruffleOptionsOverrideScope inline = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleFunctionInlining, true)) {
sampler.setStackLimit(3);
sampler.setCollecting(true);
final Source source = Source.create(InstrumentationTestLanguage.ID, defaultSourceForSampling);
context.eval(InstrumentationTestLanguage.ID, source.getCharacters());
Assert.assertFalse(sampler.hasStackOverflowed());
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class NestedContextTest method testRecursiveEval.
@Test
public void testRecursiveEval() throws Exception {
final Source testSource = testSource("ROOT(\n" + " STATEMENT,\n" + " STATEMENT\n" + ")\n");
final Context context = Context.create();
final AtomicInteger suspensionCount = new AtomicInteger(0);
Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent event) {
checkState(event, 3, true, "STATEMENT");
// recursive evaluation should not trigger a suspended event
context.eval(testSource);
suspensionCount.incrementAndGet();
}
})) {
session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
context.eval(testSource);
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class ReenterStackFrameTest method testReenterDeep.
@Test
public void testReenterDeep() throws Throwable {
final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + " STATEMENT(),\n" + " DEFINE(aa, ROOT(\n" + " STATEMENT(EXPRESSION),\n" + " DEFINE(aaa, ROOT(\n" + " STATEMENT(EXPRESSION, EXPRESSION))\n" + " ),\n" + " CALL(aaa))\n" + " ),\n" + " CALL(aa))\n" + "), \n" + "CALL(a))\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
final Exception[] exception = new Exception[1];
final int[] suspendHits = new int[1];
final int[] firstStatementNumJavaFrames = new int[1];
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
event.prepareStepInto(2);
suspendHits[0]++;
firstStatementNumJavaFrames[0] = Thread.currentThread().getStackTrace().length;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT(EXPRESSION, EXPRESSION)", currentFrame.getSourceSection().getCharacters());
Iterator<DebugStackFrame> sfIter = event.getStackFrames().iterator();
// the top one (aaa)
sfIter.next();
// the second one (aa)
event.prepareUnwindFrame(sfIter.next());
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("CALL(aa)", currentFrame.getSourceSection().getCharacters());
// "a"
event.prepareUnwindFrame(event.getStackFrames().iterator().next());
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
event.prepareStepInto(2);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT(EXPRESSION)", currentFrame.getSourceSection().getCharacters());
event.prepareStepInto(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT(EXPRESSION, EXPRESSION)", currentFrame.getSourceSection().getCharacters());
Iterator<DebugStackFrame> sfIter = event.getStackFrames().iterator();
// the top one (aaa)
sfIter.next();
// the second one (aa)
sfIter.next();
// the third one (a)
event.prepareUnwindFrame(sfIter.next());
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
event.prepareStepInto(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
Assert.assertEquals("Same Java depth", firstStatementNumJavaFrames[0], Thread.currentThread().getStackTrace().length);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectDone();
if (exception[0] != null) {
throw exception[0];
}
Assert.assertEquals(8, suspendHits[0]);
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class ReenterStackFrameTest method testVariables.
@Test
public void testVariables() throws Throwable {
// Test that after a re-enter, variables are cleared.
final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + " STATEMENT(),\n" + " VARIABLE(x, 42),\n" + " VARIABLE(n, 100),\n" + " VARIABLE(m, 200),\n" + " STATEMENT()\n" + ")),\n" + "CALL(a))\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
final Exception[] exception = new Exception[1];
final int[] suspendHits = new int[1];
final int numRepeats = 5;
for (int i = numRepeats - 1; i >= 0; i--) {
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", event.getSourceSection().getCharacters());
Assert.assertEquals(2, event.getSourceSection().getStartLine());
checkStack(currentFrame);
event.prepareStepOver(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
final boolean doUnwind = i > 0;
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", event.getSourceSection().getCharacters());
Assert.assertEquals(6, event.getSourceSection().getStartLine());
checkStack(currentFrame, "n", "100", "m", "200", "x", "42");
if (doUnwind) {
event.prepareUnwindFrame(currentFrame);
}
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
if (exception[0] != null) {
throw exception[0];
}
if (!doUnwind) {
break;
}
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
Assert.assertEquals("", frames.next().getName());
Assert.assertFalse(frames.hasNext());
checkStack(currentFrame);
// Enter into "a"
event.prepareStepInto(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
if (exception[0] != null) {
throw exception[0];
}
}
expectDone();
if (exception[0] != null) {
throw exception[0];
}
Assert.assertEquals(3 * numRepeats - 1, suspendHits[0]);
}
}
use of org.graalvm.polyglot.Source in project graal by oracle.
the class ReenterStackFrameTest method testReenterCurrent.
@Test
public void testReenterCurrent() throws Throwable {
final Source source = testSource("ROOT(DEFINE(a, ROOT(\n" + " STATEMENT(),\n" + " STATEMENT(EXPRESSION)\n" + ")),\n" + "CALL(a))\n");
try (DebuggerSession session = startSession()) {
session.suspendNextExecution();
startEval(source);
final Exception[] exception = new Exception[1];
final int[] suspendHits = new int[1];
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
event.prepareStepOver(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT(EXPRESSION)", currentFrame.getSourceSection().getCharacters());
event.prepareUnwindFrame(currentFrame);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("CALL(a)", currentFrame.getSourceSection().getCharacters());
Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
Assert.assertEquals("", frames.next().getName());
Assert.assertFalse(frames.hasNext());
// Enter into "a"
event.prepareStepInto(1);
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectSuspended((SuspendedEvent event) -> {
DebugStackFrame currentFrame = event.getTopStackFrame();
try {
Assert.assertEquals("STATEMENT()", currentFrame.getSourceSection().getCharacters());
suspendHits[0]++;
} catch (Exception ex) {
exception[0] = ex;
}
});
expectDone();
if (exception[0] != null) {
throw exception[0];
}
Assert.assertEquals(4, suspendHits[0]);
}
}
Aggregations