Search in sources :

Example 11 with CallTarget

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

the class CachedTest method testGuardWithJustCachedParameter.

@Test
public void testGuardWithJustCachedParameter() {
    TestGuardWithJustCachedParameter.invocations = 0;
    CallTarget root = createCallTarget(TestGuardWithJustCachedParameterFactory.getInstance());
    assertEquals(42, root.call(42));
    assertEquals(42, root.call(43));
    assertEquals(42, root.call(44));
    if (assertionsEnabled()) {
        Assert.assertTrue(TestGuardWithJustCachedParameter.invocations >= 3);
    } else {
        assertEquals(1, TestGuardWithJustCachedParameter.invocations);
    }
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 12 with CallTarget

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

the class CachedTest method testMultipleCaches.

@Test
public void testMultipleCaches() {
    CallTarget root = createCallTarget(TestMultipleCachesFactory.getInstance());
    assertEquals(42, root.call(21));
    assertEquals(42, root.call(22));
    assertEquals(42, root.call(23));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 13 with CallTarget

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

the class CachedTest method testBoundCacheOverflow.

@Test
public void testBoundCacheOverflow() {
    CallTarget root = createCallTarget(BoundCacheOverflowFactory.getInstance());
    assertEquals(42, root.call(42));
    assertEquals(43, root.call(43));
    assertEquals(-1, root.call(44));
    assertEquals(42, root.call(42));
    assertEquals(43, root.call(43));
    assertEquals(-1, 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 14 with CallTarget

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

the class CachedTest method testGuardWithCachedAndDynamicParameter.

@Test
public void testGuardWithCachedAndDynamicParameter() {
    TestGuardWithCachedAndDynamicParameter.cachedMethodInvocations = 0;
    TestGuardWithCachedAndDynamicParameter.dynamicMethodInvocations = 0;
    CallTarget root = createCallTarget(TestGuardWithCachedAndDynamicParameterFactory.getInstance());
    assertEquals(42, root.call(42));
    assertEquals(42, root.call(43));
    assertEquals(42, root.call(44));
    // guards with just cached parameters are just invoked on the slow path
    if (assertionsEnabled()) {
        Assert.assertTrue(TestGuardWithCachedAndDynamicParameter.cachedMethodInvocations >= 3);
    } else {
        assertEquals(1, TestGuardWithCachedAndDynamicParameter.cachedMethodInvocations);
    }
    Assert.assertTrue(TestGuardWithCachedAndDynamicParameter.dynamicMethodInvocations >= 3);
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 15 with CallTarget

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

the class CachedTest method testCacheNodeField.

@Test
public void testCacheNodeField() {
    CallTarget root = createCallTarget(TestCacheNodeFieldFactory.getInstance(), 21);
    assertEquals(21, root.call(42));
    assertEquals(21, root.call(43));
}
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