Search in sources :

Example 1 with FrameInstanceVisitor

use of com.oracle.truffle.api.frame.FrameInstanceVisitor 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 2 with FrameInstanceVisitor

use of com.oracle.truffle.api.frame.FrameInstanceVisitor 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)

Aggregations

CallTarget (com.oracle.truffle.api.CallTarget)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2 FrameInstanceVisitor (com.oracle.truffle.api.frame.FrameInstanceVisitor)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)2 Test (org.junit.Test)2 Frame (com.oracle.truffle.api.frame.Frame)1 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1