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());
}
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();
}
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);
}
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);
}
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 }));
}
Aggregations