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());
}
}
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);
}
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";
}
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);
}
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();
}
Aggregations