Search in sources :

Example 6 with FrameInstance

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

FrameInstance (com.oracle.truffle.api.frame.FrameInstance)6 Frame (com.oracle.truffle.api.frame.Frame)3 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)3 Test (org.junit.Test)3 CallTarget (com.oracle.truffle.api.CallTarget)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 FrameInstanceVisitor (com.oracle.truffle.api.frame.FrameInstanceVisitor)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 MaterializedFrame (com.oracle.truffle.api.frame.MaterializedFrame)1