Search in sources :

Example 61 with CallTarget

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

the class SpecializationGroupingTest method testElseConnectionBug1.

@Test
public void testElseConnectionBug1() {
    CallTarget target = TestHelper.createCallTarget(TestElseConnectionBug1Factory.create(new GenericInt()));
    Assert.assertEquals(42, target.call());
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 62 with CallTarget

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

the class SynchronizationTest method testFirstExecutionDoesNotHoldLock.

@Test
public void testFirstExecutionDoesNotHoldLock() throws InterruptedException {
    final Object monitor = new Object();
    final CountDownLatch latch = new CountDownLatch(1);
    final IfNode ifNode = new IfNode();
    // We need a root node to get its lock
    @SuppressWarnings("unused") final CallTarget callTarget = TestHelper.createCallTarget(ifNode);
    Thread waitThread = new Thread(new Runnable() {

        @Override
        public void run() {
            ifNode.waitNode.executeEvaluated(monitor, latch);
        }
    });
    waitThread.start();
    Thread notifyThread = new Thread(new Runnable() {

        @Override
        public void run() {
            ifNode.notifyNode.executeEvaluated(monitor);
        }
    });
    latch.await();
    notifyThread.start();
    waitThread.join();
    notifyThread.join();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 63 with CallTarget

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

the class Interop method testInterop.

@Test
public void testInterop() {
    UseInterop node = UseInteropNodeGen.create(createArguments(2));
    CallTarget target = createTarget(node);
    TruffleObject o1 = new TruffleObject();
    TruffleObject o2 = new TruffleObject();
    TruffleObject o3 = new TruffleObject();
    TruffleObject o4 = new TruffleObject();
    assertEquals(42, target.call(o1, 42));
    assertEquals(43, target.call(o2, 43));
    assertEquals(44, target.call(o3, 44));
    assertEquals(3, node.cached);
    assertEquals(0, node.generic);
    // operation gets generic
    assertEquals(45, target.call(o4, 45));
    assertEquals(42, target.call(o1, 42));
    assertEquals(43, target.call(o2, 43));
    assertEquals(44, target.call(o3, 44));
    assertEquals(3, node.cached);
    assertEquals(4, node.generic);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 64 with CallTarget

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

the class MathPow method testPow.

@Test
public void testPow() {
    MathPowNode node = MathPowNodeGen.create(createArguments(2));
    CallTarget target = createTarget(node);
    // start with doPowCached
    assertEquals(1D, target.call(1D, 1));
    assertEquals(2D, target.call(2D, 1));
    assertEquals(3D, target.call(3D, 1));
    assertEquals(3, node.doPowCached);
    assertEquals(0, node.doPowCachedExponent);
    // transition to doPowCachedExponent
    assertEquals(4D, target.call(4D, 1));
    assertEquals(5D, target.call(5D, 1));
    assertEquals(6D, target.call(6D, 1));
    assertEquals(16D, target.call(4D, 2));
    assertEquals(125D, target.call(5D, 3));
    assertEquals(5, node.doPowCachedExponent);
    assertEquals(0, node.doPowDoubleInt);
    // transition to doPowDoubleInt
    assertEquals(4D * 4D * 4D * 4D, target.call(4D, 4));
    assertEquals(5D * 5D * 5D * 5D * 5D, target.call(5D, 5));
    assertEquals(5, node.doPowCachedExponent);
    assertEquals(2, node.doPowDoubleInt);
    // transition to doPow
    assertEquals(5D, target.call(5D, 1D));
    assertEquals(2D, target.call(2D, 1D));
    assertEquals(3, node.doPowCached);
    assertEquals(5, node.doPowCachedExponent);
    assertEquals(2, node.doPowDoubleInt);
    assertEquals(2, node.doPow);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 65 with CallTarget

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

the class RubyCall method testCall.

@Test
public void testCall() {
    RubyHeadNode node = RubyHeadNodeGen.create(createArguments(4));
    CallTarget nodeTarget = createTarget(node);
    final Object firstArgument = "someArgument";
    // dummyMethod is just going to return the some argument of the function
    final Object testMethodName = "getSomeArgument";
    // implementation returns first argument
    InternalMethod aClassTestMethod = new InternalMethod(ExampleNode.createDummyTarget(3));
    // implementation returns second argument
    InternalMethod bClassTestMethod = new InternalMethod(ExampleNode.createDummyTarget(4));
    // implementation returns third argument
    InternalMethod cClassTestMethod = new InternalMethod(ExampleNode.createDummyTarget(5));
    // defines hierarchy C extends B extends A
    RubyClass aClass = new RubyClass("A", null);
    RubyClass bClass = new RubyClass("B", aClass);
    RubyClass cClass = new RubyClass("C", bClass);
    RubyObject aInstance = new RubyObject(aClass);
    RubyObject bInstance = new RubyObject(bClass);
    RubyObject cInstance = new RubyObject(cClass);
    // undefined method call
    assertEquals(RubyObject.NIL, nodeTarget.call(cInstance, testMethodName, null, new Object[] { firstArgument }));
    // method defined in a
    aClass.addMethod(testMethodName, aClassTestMethod);
    assertEquals(firstArgument, nodeTarget.call(aInstance, testMethodName, null, new Object[] { firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(bInstance, testMethodName, null, new Object[] { firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(cInstance, testMethodName, null, new Object[] { firstArgument }));
    // method redefined in b
    bClass.addMethod(testMethodName, bClassTestMethod);
    assertEquals(firstArgument, nodeTarget.call(aInstance, testMethodName, null, new Object[] { firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(bInstance, testMethodName, null, new Object[] { null, firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(cInstance, testMethodName, null, new Object[] { null, firstArgument }));
    // method redefined in c
    cClass.addMethod(testMethodName, cClassTestMethod);
    assertEquals(firstArgument, nodeTarget.call(aInstance, testMethodName, null, new Object[] { firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(bInstance, testMethodName, null, new Object[] { null, firstArgument }));
    assertEquals(firstArgument, nodeTarget.call(cInstance, testMethodName, null, new Object[] { null, null, firstArgument }));
}
Also used : 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