Search in sources :

Example 1 with TruffleRuntime

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

the class ReplaceTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    UnresolvedNode leftChild = new UnresolvedNode("20");
    UnresolvedNode rightChild = new UnresolvedNode("22");
    TestRootNode rootNode = new TestRootNode(new ValueNode[] { leftChild, rightChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    assertEquals(rootNode, leftChild.getParent());
    assertEquals(rootNode, rightChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(leftChild, iterator.next());
    Assert.assertEquals(rightChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    assertEquals(42, result);
    assertEquals(42, target.call());
    iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
    Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
    Assert.assertFalse(iterator.hasNext());
    iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(rootNode, iterator.next().getParent());
    Assert.assertEquals(rootNode, iterator.next().getParent());
    Assert.assertFalse(iterator.hasNext());
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 2 with TruffleRuntime

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

the class ChildrenNodesTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildNode firstChild = new TestChildNode();
    TestChildNode secondChild = new TestChildNode();
    TestRootNode rootNode = new TestRootNode(new TestChildNode[] { firstChild, secondChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    Assert.assertEquals(rootNode, firstChild.getParent());
    Assert.assertEquals(rootNode, secondChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(firstChild, iterator.next());
    Assert.assertEquals(secondChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 3 with TruffleRuntime

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

the class FinalFieldTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestRootNode rootNode = new TestRootNode(new TestChildNode[] { new TestChildNode(20), new TestChildNode(22) });
    CallTarget target = runtime.createCallTarget(rootNode);
    Object result = target.call();
    Assert.assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 4 with TruffleRuntime

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

the class FrameTest method framesCanBeMaterialized.

@Test
public void framesCanBeMaterialized() {
    final TruffleRuntime runtime = Truffle.getRuntime();
    class FrameRootNode extends RootNode {

        FrameRootNode() {
            super(null);
        }

        @Override
        public Object execute(VirtualFrame frame) {
            FrameInstance frameInstance = runtime.getCurrentFrame();
            Frame readWrite = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
            Frame materialized = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
            assertTrue("Really materialized: " + materialized, materialized instanceof MaterializedFrame);
            assertEquals("It's my frame", frame, readWrite);
            return this;
        }
    }
    FrameRootNode frn = new FrameRootNode();
    Object ret = Truffle.getRuntime().createCallTarget(frn).call();
    assertEquals("Returns itself", frn, ret);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 5 with TruffleRuntime

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

the class InterfaceChildFieldTest method testChildren.

@Test
public void testChildren() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildInterface[] children = new TestChildInterface[5];
    for (int i = 0; i < children.length; i++) {
        children[i] = new TestLeafNode();
    }
    TestChildrenNode parent = new TestChildrenNode(children);
    TestRootNode rootNode = new TestRootNode(parent);
    CallTarget target = runtime.createCallTarget(rootNode);
    Iterator<Node> iterator = parent.getChildren().iterator();
    for (int i = 0; i < children.length; i++) {
        Assert.assertEquals(children[i], iterator.next());
    }
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(105, result);
    Assert.assertEquals(2 + children.length, NodeUtil.countNodes(rootNode));
    Assert.assertEquals(2 + children.length, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode)));
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Aggregations

TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)23 Test (org.junit.Test)19 CallTarget (com.oracle.truffle.api.CallTarget)15 RootNode (com.oracle.truffle.api.nodes.RootNode)9 DefaultTruffleRuntime (com.oracle.truffle.api.impl.DefaultTruffleRuntime)6 Node (com.oracle.truffle.api.nodes.Node)6 SubstrateTruffleRuntime (com.oracle.svm.truffle.api.SubstrateTruffleRuntime)3 Frame (com.oracle.truffle.api.frame.Frame)3 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)3 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 Alias (com.oracle.svm.core.annotate.Alias)2 Delete (com.oracle.svm.core.annotate.Delete)2 NeverInline (com.oracle.svm.core.annotate.NeverInline)2 RecomputeFieldValue (com.oracle.svm.core.annotate.RecomputeFieldValue)2 Kind (com.oracle.svm.core.annotate.RecomputeFieldValue.Kind)2 TargetClass (com.oracle.svm.core.annotate.TargetClass)2 Deoptimizer (com.oracle.svm.core.deopt.Deoptimizer)2