Search in sources :

Example 46 with VirtualFrame

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

the class StackTraceTest method testFrameAccess.

@Test
public void testFrameAccess() {
    CallTarget callTarget = createCallTarget(new TestCallWithCallTargetNode(null));
    CallTarget indirect = createCallTarget(new TestCallWithIndirectTargetNode(callTarget));
    CallTarget direct = createCallTarget(new TestCallWithDirectTargetNode(indirect));
    CallTarget test = createCallTarget(new TestCallNode(null) {

        @Override
        Object execute(VirtualFrame frame) {
            Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {

                @SuppressWarnings("deprecation")
                public Object visitFrame(FrameInstance frameInstance) {
                    Assert.assertNull(frameInstance.getFrame(FrameAccess.NONE));
                    Frame readOnlyFrame = frameInstance.getFrame(FrameAccess.READ_ONLY);
                    FrameSlot slot = readOnlyFrame.getFrameDescriptor().findFrameSlot("demo");
                    Assert.assertEquals(42, readOnlyFrame.getValue(slot));
                    Frame readWriteFrame = frameInstance.getFrame(FrameAccess.READ_WRITE);
                    Assert.assertEquals(42, readWriteFrame.getValue(slot));
                    readWriteFrame.setObject(slot, 43);
                    Frame materializedFrame = frameInstance.getFrame(FrameAccess.MATERIALIZE);
                    Assert.assertEquals(43, materializedFrame.getValue(slot));
                    materializedFrame.setObject(slot, 44);
                    Assert.assertEquals(44, readOnlyFrame.getValue(slot));
                    Assert.assertEquals(44, readWriteFrame.getValue(slot));
                    return null;
                }
            });
            return null;
        }
    });
    findTestCallNode(callTarget).setNext(test);
    direct.call();
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameInstanceVisitor(com.oracle.truffle.api.frame.FrameInstanceVisitor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 47 with VirtualFrame

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

the class StackTraceTest method testStackTraversal.

@Test
public void testStackTraversal() {
    CallTarget callTarget = createCallTarget(new TestCallWithCallTargetNode(null));
    CallTarget indirect = createCallTarget(new TestCallWithIndirectTargetNode(callTarget));
    CallTarget direct = createCallTarget(new TestCallWithDirectTargetNode(indirect));
    CallTarget test = createCallTarget(new TestCallNode(null) {

        int visitCount = 0;

        @Override
        Object execute(VirtualFrame frame) {
            Object result = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {

                public Object visitFrame(FrameInstance frameInstance) {
                    visitCount++;
                    return "foobar";
                }
            });
            Assert.assertEquals(1, visitCount);
            Assert.assertEquals("foobar", result);
            visitCount = 0;
            result = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {

                public Object visitFrame(FrameInstance frameInstance) {
                    visitCount++;
                    if (visitCount == 2) {
                        return "foobar";
                    } else {
                        // continue traversing
                        return null;
                    }
                }
            });
            Assert.assertEquals(2, visitCount);
            Assert.assertEquals("foobar", result);
            return null;
        }
    });
    findTestCallNode(callTarget).setNext(test);
    direct.call();
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameInstanceVisitor(com.oracle.truffle.api.frame.FrameInstanceVisitor) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 48 with VirtualFrame

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

the class UnitLexicalScope method createInitializationBlock.

@Override
BlockNode createInitializationBlock() {
    VirtualFrame unitFrame = PascalLanguage.INSTANCE.createUnitFrame(this.getName(), this.getFrameDescriptor());
    List<StatementNode> initializationNodes = this.generateInitializationNodes(unitFrame);
    initializationNodes.addAll(this.scopeInitializationNodes);
    return new BlockNode(initializationNodes.toArray(new StatementNode[initializationNodes.size()]));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) BlockNode(cz.cuni.mff.d3s.trupple.language.nodes.statement.BlockNode) StatementNode(cz.cuni.mff.d3s.trupple.language.nodes.statement.StatementNode)

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