in src/main/java/com/jetbrains/jdi/TargetVM.java [143:239]
public void run() {
if ((vm.traceFlags & VirtualMachine.TRACE_SENDS) != 0) {
vm.printTrace("Target VM interface thread running");
}
Packet p=null,p2;
String idString;
while (shouldListen) {
boolean done = false;
try {
byte b[] = connection.readPacket();
if (b.length == 0) {
done = true;
} else {
p = Packet.fromByteArray(b);
}
} catch (IOException e) {
done = true;
}
if (done) {
shouldListen = false;
try {
connection.close();
} catch (IOException ioe) { }
break;
}
if ((vm.traceFlags & VirtualMachineImpl.TRACE_RAW_RECEIVES) != 0) {
dumpPacket(p, false);
}
if ((p.flags & Packet.Reply) == 0) {
// It's a command
handleVMCommand(p);
} else {
/*if(p.errorCode != Packet.ReplyNoError) {
System.err.println("Packet " + p.id + " returned failure = " + p.errorCode);
}*/
vm.state().notifyCommandComplete(p.id);
synchronized(waitingQueue) {
p2 = waitingQueue.get(p.id);
}
if (p2 == null) {
// Whoa! a reply without a sender. Problem.
// FIX ME! Need to post an error.
System.err.println("Received reply 0x" + Integer.toHexString(p.id) + " with no sender!");
continue;
}
p2.errorCode = p.errorCode;
p2.data = p.data;
p2.replied = true;
p2.notifyReplied();
// remove late to have more correct isIdle
synchronized(waitingQueue) {
waitingQueue.remove(p.id);
}
}
}
// inform the VM mamager that this VM is history
vm.vmManager.disposeVirtualMachine(vm);
if (eventController != null) {
eventController.release();
}
// close down all the event queues
// Closing a queue causes a VMDisconnectEvent to
// be put onto the queue.
synchronized(eventQueues) {
for (EventQueue eventQueue : eventQueues) {
((EventQueueImpl) eventQueue).close();
}
}
// indirectly throw VMDisconnectedException to
// command requesters.
synchronized(waitingQueue) {
waitingQueue.values().forEach(Packet::notifyReplied);
waitingQueue.clear();
}
// shutdown the executor after invoking all pending packets notifyReplied
if (asyncExecutor != null) {
asyncExecutor.shutdown();
}
if ((vm.traceFlags & VirtualMachine.TRACE_SENDS) != 0) {
vm.printTrace("Target VM interface thread exiting");
}
}