Skip to content

Commit

Permalink
Await thread suspended state before returning from jdwp suspendAll co…
Browse files Browse the repository at this point in the history
…mmand
  • Loading branch information
javeleon committed Feb 23, 2021
1 parent b70d900 commit 3f59410
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ public boolean resume(Object thread, boolean sessionClosed) {
suspendedInfos.put(thread, null);

JDWPLogger.log("Waking up thread: %s", JDWPLogger.LogLevel.THREAD, getThreadName(thread));
threadSuspension.removeHardSuspendedThread(thread);
lock.release();
lock.notifyAll();
threadSuspension.removeHardSuspendedThread(thread);
return true;
} else {
JDWPLogger.log("Not resuming thread: %s with suspension count: %d", JDWPLogger.LogLevel.THREAD, getThreadName(thread), threadSuspension.getSuspensionCount(thread));
Expand Down Expand Up @@ -423,8 +423,7 @@ public void suspend(Object guestThread) {

// quite often the Debug API will not call back the onSuspend method in time,
// even if the guestThread is executing. If the guestThread is blocked or waiting we
// still need
// to suspend it, thus we manage this with a hard suspend mechanism
// still need to suspend it, thus we manage this with a hard suspend mechanism
threadSuspension.addHardSuspendedThread(guestThread);
if (suspendedInfos.get(guestThread) == null) {
// if already set, we have captured a blocking suspendedInfo already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {

PacketStream reply = new PacketStream().replyPacket().id(packet.id);
controller.suspendAll();

// give threads time to suspend before returning
for (Object guestThread : controller.getContext().getAllGuestThreads()) {
SuspendedInfo info = controller.getSuspendedInfo(guestThread);
if (info instanceof UnknownSuspendedInfo) {
awaitSuspendedInfo(controller, guestThread, info);
}
}
return new CommandResult(reply);
}
}
Expand Down

0 comments on commit 3f59410

Please sign in to comment.