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