Search in sources :

Example 1 with MonitorStackInfo

use of com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo in project graal by oracle.

the class DebuggerController method captureCallFramesBeforeBlocking.

public CallFrame[] captureCallFramesBeforeBlocking(Object guestThread) {
    List<CallFrame> callFrames = new ArrayList<>();
    Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<>() {

        @Override
        public Object visitFrame(FrameInstance frameInstance) {
            KlassRef klass;
            MethodRef method;
            RootNode root = getRootNode(frameInstance);
            if (root == null) {
                return null;
            }
            method = getContext().getMethodFromRootNode(root);
            if (method == null) {
                return null;
            }
            klass = method.getDeclaringKlassRef();
            long klassId = ids.getIdAsLong(klass);
            long methodId = ids.getIdAsLong(method);
            byte typeTag = TypeTag.getKind(klass);
            Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
            // for bytecode-based languages (Espresso) we can read the precise bci from the
            // frame
            long codeIndex = -1;
            try {
                codeIndex = context.readBCIFromFrame(root, frame);
            } catch (Throwable t) {
                JDWP.LOGGER.fine(() -> "Unable to read current BCI from frame in method: " + klass.getNameAsString() + "." + method.getNameAsString());
            }
            if (codeIndex == -1) {
                // fall back to start of the method then
                codeIndex = 0;
            }
            // check if current bci is higher than the first index on the last line,
            // in which case we must report the last line index instead
            long lastLineBCI = method.getBCIFromLine(method.getLastLine());
            if (codeIndex > lastLineBCI) {
                codeIndex = lastLineBCI;
            }
            Node currentNode = frameInstance.getCallNode();
            if (currentNode == null) {
                CallTarget callTarget = frameInstance.getCallTarget();
                if (callTarget instanceof RootCallTarget) {
                    currentNode = ((RootCallTarget) callTarget).getRootNode();
                }
            }
            if (currentNode instanceof RootNode) {
                currentNode = context.getInstrumentableNode((RootNode) currentNode);
            }
            callFrames.add(new CallFrame(context.getIds().getIdAsLong(guestThread), typeTag, klassId, method, methodId, codeIndex, frame, currentNode, root, null, context));
            return null;
        }
    });
    CallFrame[] result = callFrames.toArray(new CallFrame[callFrames.size()]);
    // collect monitor info
    MonitorStackInfo[] ownedMonitorInfos = context.getOwnedMonitors(result);
    HashMap<Object, Integer> entryCounts = new HashMap<>(ownedMonitorInfos.length);
    for (MonitorStackInfo ownedMonitorInfo : ownedMonitorInfos) {
        Object monitor = ownedMonitorInfo.getMonitor();
        entryCounts.put(monitor, context.getMonitorEntryCount(monitor));
    }
    suspendedInfos.put(guestThread, new SuspendedInfo(context, result, guestThread, entryCounts));
    return result;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) Frame(com.oracle.truffle.api.frame.Frame) HashMap(java.util.HashMap) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) ArrayList(java.util.ArrayList) MonitorStackInfo(com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 2 with MonitorStackInfo

use of com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo in project graal by oracle.

the class JDWPContextImpl method getOwnedMonitors.

@Override
public MonitorStackInfo[] getOwnedMonitors(CallFrame[] callFrames) {
    List<MonitorStackInfo> result = new ArrayList<>();
    int stackDepth = 0;
    for (CallFrame callFrame : callFrames) {
        RootNode rootNode = callFrame.getRootNode();
        if (rootNode instanceof EspressoRootNode) {
            EspressoRootNode espressoRootNode = (EspressoRootNode) rootNode;
            if (espressoRootNode.usesMonitors()) {
                StaticObject[] monitors = espressoRootNode.getMonitorsOnFrame(callFrame.getFrame());
                for (StaticObject monitor : monitors) {
                    if (monitor != null) {
                        result.add(new MonitorStackInfo(monitor, stackDepth));
                    }
                }
            }
        }
        stackDepth++;
    }
    return result.toArray(new MonitorStackInfo[result.size()]);
}
Also used : EspressoRootNode(com.oracle.truffle.espresso.nodes.EspressoRootNode) RootNode(com.oracle.truffle.api.nodes.RootNode) ArrayList(java.util.ArrayList) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) MonitorStackInfo(com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo) EspressoRootNode(com.oracle.truffle.espresso.nodes.EspressoRootNode)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)2 CallFrame (com.oracle.truffle.espresso.jdwp.api.CallFrame)2 MonitorStackInfo (com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo)2 ArrayList (java.util.ArrayList)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1 Node (com.oracle.truffle.api.nodes.Node)1 KlassRef (com.oracle.truffle.espresso.jdwp.api.KlassRef)1 MethodRef (com.oracle.truffle.espresso.jdwp.api.MethodRef)1 EspressoRootNode (com.oracle.truffle.espresso.nodes.EspressoRootNode)1 HashMap (java.util.HashMap)1