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