use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.
the class UnwindReenterReturnTest method testUnwindReturnOnReturn.
@Test
public void testUnwindReturnOnReturn() throws Exception {
List<CodeAction> actionsUnwind = new ArrayList<>();
List<CodeAction> actionsReenter = new ArrayList<>();
// Unwind at STATEMENT() and Return after pop from CALL(a):
actionsUnwind.add(new CodeAction("STATEMENT()", TestControlFlow.ACTION.UNWIND, "3uw"));
actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.RETURN, 42));
testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_VALUE, actionsUnwind);
testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
int ret = context.eval(lines(CODE2)).asInt();
assertEquals(42, ret);
assertEquals(0, actionsUnwind.size());
assertEquals(0, actionsReenter.size());
assertEquals("[CALL(a), CALL(b), STATEMENT()]", testControlFlow.nodesEntered.toString());
assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
assertEquals("[Null, " + uw + ", " + uw + "]", testControlFlow.returnValuesExceptions.toString());
assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.
the class UnwindReenterReturnTest method testReenterSimpleOnException.
@Test
public void testReenterSimpleOnException() throws Exception {
List<CodeAction> actionsExc = new ArrayList<>();
List<CodeAction> actionsUnwind = new ArrayList<>();
// Throw unwind from return exception and do reenter:
actionsExc.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND));
testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_EXCEPTIONAL, actionsExc);
actionsUnwind.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsUnwind);
String message = null;
try {
run(CODE1_EXC);
fail();
} catch (PolyglotException pe) {
message = pe.getMessage();
assertTrue(message, message.contains("Identifier redefinition not supported"));
}
assertEquals(0, actionsExc.size());
assertEquals(0, actionsUnwind.size());
assertEquals("[CALL(a), CALL(a)]", testControlFlow.nodesEntered.toString());
assertEquals("[CALL(a), CALL(a)]", testControlFlow.nodesReturned.toString());
assertEquals("[" + message + ", " + message + "]", testControlFlow.returnValuesExceptions.toString());
assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
assertEquals("[null]", testControlFlow.unwoundInfos.toString());
}
use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.
the class UnwindReenterReturnTest method testReturnSimpleOnException.
@Test
public void testReturnSimpleOnException() throws Exception {
List<CodeAction> actionsExc = new ArrayList<>();
List<CodeAction> actionsUnwind = new ArrayList<>();
// Throw unwind from return exception and do early return:
actionsExc.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND));
testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_EXCEPTIONAL, actionsExc);
actionsUnwind.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.RETURN, 10));
testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsUnwind);
int ret = context.eval(lines(CODE1_EXC)).asInt();
assertEquals(10, ret);
assertEquals(0, actionsExc.size());
assertEquals(0, actionsUnwind.size());
assertEquals("[CALL(a)]", testControlFlow.nodesEntered.toString());
assertEquals("[CALL(a)]", testControlFlow.nodesReturned.toString());
assertTrue(testControlFlow.returnValuesExceptions.get(0) instanceof IllegalArgumentException);
assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
assertEquals("[null]", testControlFlow.unwoundInfos.toString());
}
use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.
the class UnwindReenterReturnTest method testReturnSimpleOnEnter.
@Test
public void testReturnSimpleOnEnter() throws Exception {
List<CodeAction> actionsEnter = new ArrayList<>();
List<CodeAction> actionsUnwind = new ArrayList<>();
// Throw unwind from enter and do early return:
actionsEnter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND));
testControlFlow.actions.put(TestControlFlow.WHERE.ENTER, actionsEnter);
actionsUnwind.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.RETURN, 10));
testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsUnwind);
int ret = context.eval(lines(CODE1)).asInt();
assertEquals(10, ret);
assertEquals(0, actionsEnter.size());
assertEquals(0, actionsUnwind.size());
assertEquals("[CALL(a)]", testControlFlow.nodesEntered.toString());
assertEquals("[CALL(a)]", testControlFlow.nodesReturned.toString());
// assertEquals("[10]", testControlFlow.returnValuesExceptions.toString());
assertEquals("[com.oracle.truffle.api.instrumentation.UnwindException]", testControlFlow.returnValuesExceptions.toString());
assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
assertEquals("[null]", testControlFlow.unwoundInfos.toString());
}
use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.
the class UnwindReenterReturnTest method testUnwindReturnOnException.
@Test
public void testUnwindReturnOnException() throws Exception {
List<CodeAction> actionsUnwind = new ArrayList<>();
List<CodeAction> actionsReenter = new ArrayList<>();
// Unwind at DEFINE() and Return after pop from CALL(a):
actionsUnwind.add(new CodeAction("STATEMENT(DEFINE(a, ROOT()))", TestControlFlow.ACTION.UNWIND, "3uw"));
actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.RETURN, 42));
testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_EXCEPTIONAL, actionsUnwind);
testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
int ret = context.eval(lines(CODE2_EXC)).asInt();
assertEquals(42, ret);
String message = "java.lang.IllegalArgumentException: Identifier redefinition not supported.";
assertEquals(0, actionsUnwind.size());
assertEquals(0, actionsReenter.size());
assertEquals("[CALL(a), CALL(b), STATEMENT(DEFINE(a, ROOT()))]", testControlFlow.nodesEntered.toString());
assertEquals("[STATEMENT(DEFINE(a, ROOT())), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
assertEquals("[" + message + ", " + uw + ", " + uw + "]", testControlFlow.returnValuesExceptions.toString());
assertEquals("[STATEMENT(DEFINE(a, ROOT())), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
Aggregations