Search in sources :

Example 1 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testReturnSimpleOnReturn.

@Test
public void testReturnSimpleOnReturn() throws Exception {
    List<CodeAction> actionsReturn = new ArrayList<>();
    List<CodeAction> actionsUnwind = new ArrayList<>();
    // Throw unwind from return value and do early return:
    actionsReturn.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND, "CA"));
    testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_VALUE, actionsReturn);
    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, actionsReturn.size());
    assertEquals(0, actionsUnwind.size());
    assertEquals("[CALL(a), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(), CALL(a)]", testControlFlow.nodesReturned.toString());
    assertEquals("[Null, Null]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[CA]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testReenterSimpleOnEnter.

@Test
public void testReenterSimpleOnEnter() throws Exception {
    List<CodeAction> actionsEnter = new ArrayList<>();
    List<CodeAction> actionsUnwind = new ArrayList<>();
    // Throw unwind from enter and do reenter:
    actionsEnter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND));
    testControlFlow.actions.put(TestControlFlow.WHERE.ENTER, actionsEnter);
    actionsUnwind.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsUnwind);
    run(CODE1);
    assertEquals(0, actionsEnter.size());
    assertEquals(0, actionsUnwind.size());
    assertEquals("[CALL(a), CALL(a), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[CALL(a), STATEMENT(), CALL(a)]", testControlFlow.nodesReturned.toString());
    assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[null]", testControlFlow.unwoundInfos.toString());
    assertNotNull(testControlFlow.returnValuesExceptions.get(0));
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testReenterSimpleOnReturn.

@Test
public void testReenterSimpleOnReturn() throws Exception {
    List<CodeAction> actionsReturn = new ArrayList<>();
    List<CodeAction> actionsUnwind = new ArrayList<>();
    // Throw unwind from return value and do reenter:
    actionsReturn.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.UNWIND, "CA"));
    testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_VALUE, actionsReturn);
    actionsUnwind.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsUnwind);
    run(CODE1);
    assertEquals(0, actionsReturn.size());
    assertEquals(0, actionsUnwind.size());
    assertEquals("[CALL(a), STATEMENT(), CALL(a), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(), CALL(a), STATEMENT(), CALL(a)]", testControlFlow.nodesReturned.toString());
    assertEquals("[Null, Null, Null, Null]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[CA]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testUnwindReenterOnReturn.

@Test
public void testUnwindReenterOnReturn() throws Exception {
    List<CodeAction> actionsUnwind = new ArrayList<>();
    List<CodeAction> actionsReenter = new ArrayList<>();
    // Unwind at STATEMENT() and Reenter after pop from CALL(a):
    actionsUnwind.add(new CodeAction("STATEMENT()", TestControlFlow.ACTION.UNWIND, "3uw"));
    actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
    testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_VALUE, actionsUnwind);
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
    run(CODE2);
    assertEquals(0, actionsUnwind.size());
    assertEquals(0, actionsReenter.size());
    assertEquals("[CALL(a), CALL(b), STATEMENT(), CALL(a), CALL(b), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a), STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
    String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
    assertEquals("[Null, " + uw + ", " + uw + ", Null, Null, Null]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testMultiUnwind.

@Test
public void testMultiUnwind() throws Exception {
    UnwindMultiple unwindMultiple = engine.getInstruments().get("testUnwindMultiple").lookup(UnwindMultiple.class);
    // Unwind on enter: g -> a, e -> d (up to b due to second unwind below), l -> i
    unwindMultiple.submit(true, "CALL(g)", "CALL(a)", "CALL(e)", "CALL(d)", "CALL(l)", "CALL(i)");
    // Unwind on return: g -> c (runs in parralel with g -> a above,
    // e -> c (runs in parralel with e -> d (up to b)) above
    // k -> i (runs right after early return from k below
    unwindMultiple.submit(false, "CALL(g)", "CALL(c)", "CALL(e)", "CALL(c)", "CALL(k)", "CALL(i)");
    List<CodeAction> actionsUnwindE = new ArrayList<>();
    List<CodeAction> actionsUnwindR = new ArrayList<>();
    List<CodeAction> actionsOnUnwind = new ArrayList<>();
    actionsUnwindE.add(new CodeAction("CALL(e)", TestControlFlow.ACTION.UNWIND, "e->b"));
    actionsOnUnwind.add(new CodeAction("CALL(b)", TestControlFlow.ACTION.REENTER));
    actionsUnwindR.add(new CodeAction("CALL(k)", TestControlFlow.ACTION.UNWIND, "k->j"));
    actionsOnUnwind.add(new CodeAction("CALL(j)", TestControlFlow.ACTION.REENTER));
    actionsUnwindE.add(new CodeAction("STATEMENT()", TestControlFlow.ACTION.UNWIND, "s->k"));
    actionsOnUnwind.add(new CodeAction("CALL(k)", TestControlFlow.ACTION.RETURN, 42));
    testControlFlow.actions.put(TestControlFlow.WHERE.ENTER, actionsUnwindE);
    testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_EXCEPTIONAL, actionsUnwindR);
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsOnUnwind);
    String code = createDeepCode(12);
    int ret = context.eval(lines(code)).asInt();
    assertEquals(42, ret);
    assertEquals(0, actionsUnwindE.size());
    assertEquals(0, actionsUnwindR.size());
    assertEquals(0, actionsOnUnwind.size());
    assertEquals(// unwind to b
    "[CALL(a), CALL(b), CALL(c), CALL(d), CALL(e), " + // unwind to a
    "CALL(b), CALL(c), CALL(d), CALL(e), CALL(f), CALL(g), " + "CALL(a), CALL(b), CALL(c), CALL(d), CALL(e), CALL(f), CALL(g), CALL(h), CALL(i), CALL(j), CALL(k), CALL(l), " + // unwound to i
    "CALL(i), CALL(j), CALL(k), CALL(l), CALL(m), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals(// unwind e -> b
    "[CALL(e), CALL(d), CALL(c), CALL(b), " + "CALL(g), CALL(f), CALL(e), CALL(d), CALL(c), CALL(b), CALL(a), " + // unwound g -> a
    "CALL(l), CALL(k), CALL(j), CALL(i), " + // unwind l -> i
    "STATEMENT(), CALL(m), CALL(l), CALL(k), CALL(j), CALL(i), CALL(h), CALL(g), CALL(f), CALL(e), CALL(d), CALL(c), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
    assertEquals(testControlFlow.nodesEntered.size(), testControlFlow.nodesReturned.size());
    String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
    StringBuilder retVals = new StringBuilder("[");
    for (int i = 0; i < 19; i++) {
        retVals.append(uw);
        retVals.append(", ");
    }
    for (int i = 0; i < 10; i++) {
        retVals.append("42, ");
    }
    retVals.replace(retVals.length() - 2, retVals.length(), "]");
    assertEquals(retVals.toString(), testControlFlow.returnValuesExceptions.toString());
    assertEquals(testControlFlow.nodesEntered.size(), testControlFlow.returnValuesExceptions.size());
    assertEquals("[CALL(e), CALL(d), CALL(c), CALL(b), CALL(k), CALL(j), STATEMENT(), CALL(m), CALL(l), CALL(k)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[e->b, e->b, e->b, e->b, k->j, k->j, s->k, s->k, s->k, s->k]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CodeAction (com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction)13 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)13 PolyglotException (org.graalvm.polyglot.PolyglotException)2