Search in sources :

Example 1 with MaterializedFrame

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

the class DebugStackFrame method getScope.

/**
 * Get the current inner-most scope. The scope remain valid as long as the current stack frame
 * remains valid.
 * <p>
 * Use {@link DebuggerSession#getTopScope(java.lang.String)} to get scopes with global validity.
 * <p>
 * This method is not thread-safe and will throw an {@link IllegalStateException} if called on
 * another thread than it was created with.
 *
 * @return the scope, or <code>null</code> when no language is associated with this frame
 *         location, or when no local scope exists.
 * @since 0.26
 */
public DebugScope getScope() {
    verifyValidState(false);
    SuspendedContext context = getContext();
    RootNode root = findCurrentRoot();
    if (root == null) {
        return null;
    }
    Node node;
    if (currentFrame == null) {
        node = context.getInstrumentedNode();
    } else {
        node = currentFrame.getCallNode();
    }
    if (node.getRootNode().getLanguageInfo() == null) {
        // no language, no scopes
        return null;
    }
    Debugger debugger = event.getSession().getDebugger();
    MaterializedFrame frame = findTruffleFrame();
    Iterable<Scope> scopes = debugger.getEnv().findLocalScopes(node, frame);
    Iterator<Scope> it = scopes.iterator();
    if (!it.hasNext()) {
        return null;
    }
    return new DebugScope(it.next(), it, debugger, event, frame, root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Example 2 with MaterializedFrame

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

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

the class DebuggerSessionSnippets method evalInContext.

/**
 * Evaluates a snippet of code in a halted execution context. Assumes frame is part of the
 * current execution stack, behavior is undefined if not.
 *
 * @param ev event notification where execution is halted
 * @param code text of the code to be executed
 * @param frameInstance frame where execution is halted
 * @return
 * @throws IOException
 */
static Object evalInContext(SuspendedEvent ev, String code, FrameInstance frameInstance) throws IOException {
    try {
        Node node;
        MaterializedFrame frame;
        if (frameInstance == null) {
            node = ev.getContext().getInstrumentedNode();
            frame = ev.getMaterializedFrame();
        } else {
            node = frameInstance.getCallNode();
            frame = frameInstance.getFrame(FrameAccess.MATERIALIZE).materialize();
        }
        return Debugger.ACCESSOR.evalInContext(node, frame, code);
    } catch (KillException kex) {
        throw new IOException("Evaluation was killed.", kex);
    }
}
Also used : ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) IOException(java.io.IOException)

Example 4 with MaterializedFrame

use of com.oracle.truffle.api.frame.MaterializedFrame in project sulong by graalvm.

the class LLVMGlobalWriteNode method slowPrimitiveWrite.

public static void slowPrimitiveWrite(LLVMContext context, LLVMMemory memory, PrimitiveType primitiveType, LLVMGlobal global, Object value) {
    MaterializedFrame frame = context.getGlobalFrame();
    FrameSlot slot = global.getSlot();
    boolean isNative = frame.getValue(slot) instanceof Native;
    long address = isNative ? ((Native) frame.getValue(slot)).getPointer() : 0;
    switch(primitiveType.getPrimitiveKind()) {
        case I1:
            if (isNative) {
                memory.putI1(address, (boolean) value);
            } else {
                frame.setBoolean(slot, (boolean) value);
            }
            return;
        case I8:
            if (isNative) {
                memory.putI8(address, (byte) value);
            } else {
                frame.setByte(slot, (byte) value);
            }
            return;
        case I16:
            if (isNative) {
                memory.putI16(address, (short) value);
            } else {
                frame.setInt(slot, (short) value);
            }
            return;
        case I32:
            if (isNative) {
                memory.putI32(address, (int) value);
            } else {
                frame.setInt(slot, (int) value);
            }
            return;
        case I64:
            if (isNative) {
                memory.putI64(address, (long) value);
            } else {
                frame.setLong(slot, (long) value);
            }
            return;
        case FLOAT:
            if (isNative) {
                memory.putFloat(address, (float) value);
            } else {
                frame.setFloat(slot, (float) value);
            }
            return;
        case DOUBLE:
            if (isNative) {
                memory.putDouble(address, (double) value);
            } else {
                frame.setDouble(slot, (double) value);
            }
            return;
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException();
}
Also used : Native(com.oracle.truffle.llvm.runtime.global.LLVMGlobal.Native) IsNative(com.oracle.truffle.llvm.runtime.global.LLVMGlobal.IsNative) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Aggregations

MaterializedFrame (com.oracle.truffle.api.frame.MaterializedFrame)4 Node (com.oracle.truffle.api.nodes.Node)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 Scope (com.oracle.truffle.api.Scope)1 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)1 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)1 IsNative (com.oracle.truffle.llvm.runtime.global.LLVMGlobal.IsNative)1 Native (com.oracle.truffle.llvm.runtime.global.LLVMGlobal.Native)1 IOException (java.io.IOException)1 Test (org.junit.Test)1