Search in sources :

Example 66 with CallTarget

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

the class TruffleDirectCallNodeTest method testCanBeClonedWithoutParent.

@Test
public void testCanBeClonedWithoutParent() {
    final RootNode rootNode = new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return 42;
        }

        @Override
        public boolean isCloningAllowed() {
            return true;
        }
    };
    final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    final DirectCallNode callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
    assertTrue(callNode.isCallTargetCloningAllowed());
    assertTrue(callNode.cloneCallTarget());
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Test(org.junit.Test)

Example 67 with CallTarget

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

the class OptimizedOSRLoopNodeTest method testTwoLoopsSilblings.

/*
     * Test that two silbling loops are compiled independently.
     */
@Theory
public void testTwoLoopsSilblings(OSRLoopFactory factory) {
    TwoSilblingLoopNodesTest rootNode = new TwoSilblingLoopNodesTest(factory, new TestRepeatingNode(), new TestRepeatingNode());
    CallTarget target = runtime.createCallTarget(rootNode);
    target.call(OSR_THRESHOLD + 1, 1);
    assertCompiled(rootNode.getOSRTarget());
    assertNotCompiled(rootNode.getOSRTarget2());
    target.call(1, OSR_THRESHOLD + 1);
    assertCompiled(rootNode.getOSRTarget());
    assertCompiled(rootNode.getOSRTarget2());
    Assert.assertTrue(rootNode.getOSRTarget() != rootNode.getOSRTarget2());
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Theory(org.junit.experimental.theories.Theory)

Example 68 with CallTarget

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

the class OptimizedOSRLoopNodeTest method testTransferToInterpreter.

/*
     * Test that calling CompilerDirectives.transferToInterpreter does not invalidate the target.
     */
@Test
public void testTransferToInterpreter() {
    OSRLoopFactory factory = CONFIGURED;
    class TransferToInterpreterTestRepeatingNode extends TestRepeatingNode {

        @Override
        public boolean executeRepeating(VirtualFrame frame) {
            try {
                if (CompilerDirectives.inCompiledCode()) {
                    CompilerDirectives.transferToInterpreter();
                }
                int counter = frame.getInt(param1);
                frame.setInt(param1, counter - 1);
                return counter != 0;
            } catch (FrameSlotTypeException e) {
                return false;
            }
        }
    }
    TestRootNode rootNode = new TestRootNode(factory, new TransferToInterpreterTestRepeatingNode());
    CallTarget target = runtime.createCallTarget(rootNode);
    target.call(OSR_THRESHOLD + 1);
    try {
        // Invalidation is asynchronous.
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(rootNode.getOSRTarget());
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameSlotTypeException(com.oracle.truffle.api.frame.FrameSlotTypeException) RootCallTarget(com.oracle.truffle.api.RootCallTarget) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) DataPoint(org.junit.experimental.theories.DataPoint) Test(org.junit.Test)

Example 69 with CallTarget

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

the class PartialEvaluationTest method assertPartialEvalNoInvokes.

protected void assertPartialEvalNoInvokes(RootNode root, Object[] arguments) {
    CallTarget callTarget = Truffle.getRuntime().createCallTarget(root);
    assertPartialEvalNoInvokes(callTarget, arguments);
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) CallTarget(com.oracle.truffle.api.CallTarget)

Example 70 with CallTarget

use of com.oracle.truffle.api.CallTarget in project sulong by graalvm.

the class InteropTestBase method loadTestBitcodeInternal.

protected static TruffleObject loadTestBitcodeInternal(String name) {
    File dir = new File(testBase, name);
    File file = new File(dir, "O0_MEM2REG.bc");
    Source source;
    try {
        source = Source.newBuilder(file).language("llvm").build();
    } catch (IOException ex) {
        throw new AssertionError(ex);
    }
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) IOException(java.io.IOException) File(java.io.File) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

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