Search in sources :

Example 21 with TruffleRuntime

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

the class InterfaceChildFieldTest method testChild.

@Test
public void testChild() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildInterface leftChild = new TestLeafNode();
    TestChildInterface rightChild = new TestLeafNode();
    TestChildNode parent = new TestChildNode(leftChild, rightChild);
    TestRootNode rootNode = new TestRootNode(parent);
    CallTarget target = runtime.createCallTarget(rootNode);
    Iterator<Node> iterator = parent.getChildren().iterator();
    Assert.assertEquals(leftChild, iterator.next());
    Assert.assertEquals(rightChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(42, result);
    Assert.assertEquals(4, NodeUtil.countNodes(rootNode));
    Assert.assertEquals(4, 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)

Example 22 with TruffleRuntime

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

the class CallTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    CallTarget foo = runtime.createCallTarget(new ConstantRootNode(20));
    CallTarget bar = runtime.createCallTarget(new ConstantRootNode(22));
    CallTarget main = runtime.createCallTarget(new DualCallNode(foo, bar));
    Object result = main.call();
    Assert.assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 23 with TruffleRuntime

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

the class Target_com_oracle_truffle_api_interop_java_ObjectProxyHandler method cleanup.

@Override
public void cleanup() {
    // clean the cached call target nodes to prevent them from keeping application classes alive
    TruffleRuntime runtime = Truffle.getRuntime();
    if (runtime instanceof SubstrateTruffleRuntime) {
        ((SubstrateTruffleRuntime) runtime).resetNativeImageState();
    } else if (!(runtime instanceof DefaultTruffleRuntime)) {
        throw VMError.shouldNotReachHere("Only SubstrateTruffleRuntime and DefaultTruffleRuntime supported");
    }
    // clean up the language cache
    invokeStaticMethod("com.oracle.truffle.api.vm.LanguageCache", "resetNativeImageState", Collections.emptyList());
    invokeStaticMethod("com.oracle.truffle.api.vm.InstrumentCache", "resetNativeImageState", Collections.emptyList());
    invokeStaticMethod("com.oracle.truffle.api.vm.PolyglotRootNode", "resetNativeImageState", Collections.emptyList());
    invokeStaticMethod("org.graalvm.polyglot.Engine$ImplHolder", "resetPreInitializedEngine", Collections.emptyList());
}
Also used : DefaultTruffleRuntime(com.oracle.truffle.api.impl.DefaultTruffleRuntime) DefaultTruffleRuntime(com.oracle.truffle.api.impl.DefaultTruffleRuntime) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) SubstrateTruffleRuntime(com.oracle.svm.truffle.api.SubstrateTruffleRuntime) SubstrateTruffleRuntime(com.oracle.svm.truffle.api.SubstrateTruffleRuntime)

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