Search in sources :

Example 1 with FrameInstance

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

the class StackTraceTest method assertInvariants.

private static void assertInvariants(StackTrace stack) {
    if (stack.frames.size() == 0) {
        Assert.assertNull(stack.currentFrame);
    } else {
        Assert.assertNotNull(stack.currentFrame);
    }
    if (stack.frames.size() <= 1) {
        Assert.assertNull(stack.callerFrame);
    } else {
        Assert.assertNotNull(stack.callerFrame);
    }
    for (int i = 0; i < stack.frames.size(); i++) {
        FrameInstance frame = stack.frames.get(i);
        if (i == 0) {
            assertFrameEquals(stack.currentFrame, frame);
        } else if (i == 1) {
            assertFrameEquals(stack.callerFrame, frame);
        }
        Assert.assertNotNull(frame.getCallTarget());
        // # does not crash
        Assert.assertNotNull(frame.toString());
    }
}
Also used : FrameInstance(com.oracle.truffle.api.frame.FrameInstance)

Example 2 with FrameInstance

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

the class FrameTest method framesCanBeMaterialized.

@Test
public void framesCanBeMaterialized() {
    final TruffleRuntime runtime = Truffle.getRuntime();
    class FrameRootNode extends RootNode {

        FrameRootNode() {
            super(null);
        }

        @Override
        public Object execute(VirtualFrame frame) {
            FrameInstance frameInstance = runtime.getCurrentFrame();
            Frame readWrite = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
            Frame materialized = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
            assertTrue("Really materialized: " + materialized, materialized instanceof MaterializedFrame);
            assertEquals("It's my frame", frame, readWrite);
            return this;
        }
    }
    FrameRootNode frn = new FrameRootNode();
    Object ret = Truffle.getRuntime().createCallTarget(frn).call();
    assertEquals("Returns itself", frn, ret);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 3 with FrameInstance

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

the class SLHelloEqualsWorldBuiltin method change.

@Specialization
@TruffleBoundary
public String change() {
    FrameInstance frameInstance = Truffle.getRuntime().getCallerFrame();
    Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE);
    FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello");
    frame.setObject(slot, "world");
    return "world";
}
Also used : Frame(com.oracle.truffle.api.frame.Frame) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with FrameInstance

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

the class SLGraalRuntimeBuiltin method findCallsTo.

/**
 * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in
 * the caller function.
 */
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(OptimizedCallTarget originalCallTarget) {
    FrameInstance frame = Truffle.getRuntime().getCallerFrame();
    RootNode root = frame.getCallNode().getRootNode();
    return findCallsTo(root, originalCallTarget);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 5 with FrameInstance

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

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