Search in sources :

Example 1 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project TrufflePascal by Aspect26.

the class PascalState method createUnitFrame.

public VirtualFrame createUnitFrame(String unitIdentifier, FrameDescriptor frameDescriptor) {
    VirtualFrame unitFrame = Truffle.getRuntime().createVirtualFrame(new Object[0], frameDescriptor);
    this.unitFrames.put(unitIdentifier, unitFrame);
    return unitFrame;
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame)

Example 2 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class EnumPartialEvaluationTest method enumValuesConstant.

@Ignore("Currently only works if compiled with ecj")
@Test
public void enumValuesConstant() {
    AbstractTestNode result = new AbstractTestNode() {

        @Override
        public int execute(VirtualFrame frame) {
            return TestEnum.values()[0].ordinal();
        }
    };
    assertPartialEvalEquals("constant0", new RootTestNode(new FrameDescriptor(), "enumValuesConstant", result));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class EnumPartialEvaluationTest method enumOrdinalConstant.

@Test
public void enumOrdinalConstant() {
    AbstractTestNode result = new AbstractTestNode() {

        @Override
        public int execute(VirtualFrame frame) {
            return TestEnum.Test0.ordinal();
        }
    };
    assertPartialEvalEquals("constant0", new RootTestNode(new FrameDescriptor(), "enumOrdinalConstant", result));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 4 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testNoSplitsDirectCallsBecauseFirstExecution.

@Test
public void testNoSplitsDirectCallsBecauseFirstExecution() {
    final OptimizedCallTarget callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

        @Child
        private OptimizedDirectCallNode callNode = (OptimizedDirectCallNode) runtime.createDirectCallNode(runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroNodeGen.create(new ReturnsArgumentNode()))));

        @Override
        public Object execute(VirtualFrame frame) {
            final Object[] first = { 1 };
            callNode.call(first);
            callNode.call(first);
            // This call turns the node polymorphic
            final Object[] second = { 0 };
            callNode.call(second);
            return null;
        }
    });
    // Multiple call nodes
    runtime.createDirectCallNode(callTarget);
    runtime.createDirectCallNode(callTarget);
    final DirectCallNode directCallNode = runtime.createDirectCallNode(callTarget);
    directCallNode.call(new Object[] { 0 });
    Assert.assertFalse("Target needs split after first execution", getNeedsSplit(callTarget));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) Test(org.junit.Test)

Example 5 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class OptimizedCallTargetTest method testCompilationHeuristics.

/*
     * GR-1328
     */
@Test
@Ignore("Fails non deterministically")
public void testCompilationHeuristics() {
    testInvalidationCounterCompiled = 0;
    testInvalidationCounterInterpreted = 0;
    doInvalidate = false;
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            if (CompilerDirectives.inInterpreter()) {
                testInvalidationCounterInterpreted++;
            } else {
                testInvalidationCounterCompiled++;
            }
            // doInvalidate needs to be volatile otherwise it floats up.
            if (doInvalidate) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
            }
            return null;
        }
    });
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    final int reprofileCount = TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount);
    assertTrue(compilationThreshold >= 2);
    int expectedCompiledCount = 0;
    int expectedInterpreterCount = 0;
    for (int i = 0; i < compilationThreshold; i++) {
        assertNotCompiled(target);
        target.call();
    }
    assertCompiled(target);
    expectedInterpreterCount += compilationThreshold;
    assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
    assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    for (int j = 1; j < 100; j++) {
        target.invalidate(this, "test");
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        doInvalidate = true;
        expectedCompiledCount++;
        target.call();
        assertNotCompiled(target);
        doInvalidate = false;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < compilationThreshold; i++) {
            assertCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedCompiledCount += compilationThreshold;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)48 Test (org.junit.Test)34 RootNode (com.oracle.truffle.api.nodes.RootNode)27 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 CallTarget (com.oracle.truffle.api.CallTarget)11 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)9 RootCallTarget (com.oracle.truffle.api.RootCallTarget)6 EventContext (com.oracle.truffle.api.instrumentation.EventContext)5 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 Node (com.oracle.truffle.api.nodes.Node)4 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)4 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)4 Ignore (org.junit.Ignore)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3