Search in sources :

Example 81 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class EngineBenchmark method executeCallTarget2.

@Benchmark
public Object executeCallTarget2(CallTargetCallState state) {
    CallTarget callTarget = state.callTarget;
    int result = 0;
    result += (int) callTarget.call(state.internalContext.object, state.intValue);
    result += (int) callTarget.call(state.internalContext.object, state.intValue, state.intValue);
    result += (int) callTarget.call(state.internalContext.object, state.intValue, state.intValue, state.intValue);
    result += (int) callTarget.call(state.internalContext.object, state.intValue, state.intValue, state.intValue, state.intValue);
    return result;
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 82 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class AssumptionsTest method testMethod.

@Test
public void testMethod() {
    CallTarget root = createCallTarget(MethodTestFactory.getInstance());
    MethodTest node = getNode(root);
    assertEquals(42, root.call(42));
    assertEquals(42, root.call(42));
    node.hiddenAssumption.invalidate();
    try {
        root.call(45);
        fail();
    } catch (UnsupportedSpecializationException e) {
    }
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) UnsupportedSpecializationException(com.oracle.truffle.api.dsl.UnsupportedSpecializationException) Test(org.junit.Test)

Example 83 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class AssumptionsTest method testCacheAssumption.

@Test
public void testCacheAssumption() {
    CallTarget root = createCallTarget(CacheAssumptionTestFactory.getInstance());
    CacheAssumptionTest node = getNode(root);
    assertEquals("do1", root.call(42));
    assertEquals("do1", root.call(43));
    assertEquals("do1", root.call(44));
    node.assumptions.get(42).invalidate();
    // clear 42
    node.assumptions.put(42, null);
    node.assumptions.get(43).invalidate();
    node.assumptions.get(44).invalidate();
    // recreates 42
    assertEquals("do1", root.call(42));
    // invalid 43 -> remove -> insert do2
    assertEquals("do2", root.call(43));
    // here is an unfixed bug in the old dsl layout. the new layout gets rid
    // of invalid cached entries earlier, therefore lines are available again.
    // 43 got removed, so there is space for 45
    assertEquals("do1", root.call(45));
    // no more lines can be created.
    assertEquals("do2", root.call(46));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 84 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class AssumptionsTest method testCacheAssumptionLimit.

@Test
public void testCacheAssumptionLimit() {
    CallTarget root = createCallTarget(CacheAssumptionTestFactory.getInstance());
    assertEquals("do1", root.call(42));
    assertEquals("do1", root.call(43));
    assertEquals("do1", root.call(44));
    assertEquals("do2", root.call(45));
    assertEquals("do1", root.call(43));
    assertEquals("do1", root.call(44));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 85 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class AssumptionsTest method testMultipleAssumptions.

@Test
public void testMultipleAssumptions() {
    CallTarget root = createCallTarget(MultipleAssumptionsTestFactory.getInstance());
    MultipleAssumptionsTest node = getNode(root);
    node.assumption1 = Truffle.getRuntime().createAssumption();
    node.assumption2 = Truffle.getRuntime().createAssumption();
    assertEquals("do1", root.call(42));
    node.assumption1.invalidate();
    assertEquals("do2", root.call(42));
    CallTarget root2 = createCallTarget(MultipleAssumptionsTestFactory.getInstance());
    MultipleAssumptionsTest node2 = getNode(root2);
    node2.assumption1 = Truffle.getRuntime().createAssumption();
    node2.assumption2 = Truffle.getRuntime().createAssumption();
    assertEquals("do1", root2.call(42));
    node2.assumption2.invalidate();
    assertEquals("do2", root2.call(42));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Aggregations

CallTarget (com.oracle.truffle.api.CallTarget)128 Test (org.junit.Test)102 TestHelper.createCallTarget (com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget)50 RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)17 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)10 UnsupportedSpecializationException (com.oracle.truffle.api.dsl.UnsupportedSpecializationException)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 Node (com.oracle.truffle.api.nodes.Node)9 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)9 TruffleContext (com.oracle.truffle.api.TruffleContext)6 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)6 Context (org.graalvm.polyglot.Context)6 Theory (org.junit.experimental.theories.Theory)6 TruffleException (com.oracle.truffle.api.TruffleException)5 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)5 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)5 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)5 Source (com.oracle.truffle.api.source.Source)5