8169961: Memory leak after debugging session

TargetVM gets an EventController which is a daemon thread, but don't see the thread having a way of stopping so added code to exit as soon as TargetVM thread stops listening.

Reviewed-by: clanger, dcubed, sspitsyn
This commit is contained in:
Shafi Ahmad 2017-08-18 04:34:16 -07:00
parent d46142923c
commit 87b57deb8f

View File

@ -41,7 +41,7 @@ import com.sun.jdi.event.EventSet;
public class TargetVM implements Runnable {
private Map<String, Packet> waitingQueue = new HashMap<>(32,0.75f);
private boolean shouldListen = true;
private volatile boolean shouldListen = true;
private List<EventQueue> eventQueues = Collections.synchronizedList(new ArrayList<>(2));
private VirtualMachineImpl vm;
private Connection connection;
@ -179,6 +179,9 @@ public class TargetVM implements Runnable {
// 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
@ -237,7 +240,7 @@ public class TargetVM implements Runnable {
private EventController eventController() {
if (eventController == null) {
eventController = new EventController(vm);
eventController = new EventController();
}
return eventController;
}
@ -326,13 +329,11 @@ public class TargetVM implements Runnable {
} catch (IOException ioe) { }
}
static private class EventController extends Thread {
VirtualMachineImpl vm;
private class EventController extends Thread {
int controlRequest = 0;
EventController(VirtualMachineImpl vm) {
EventController() {
super(vm.threadGroupForJDI(), "JDI Event Control Thread");
this.vm = vm;
setDaemon(true);
setPriority((MAX_PRIORITY + NORM_PRIORITY)/2);
super.start();
@ -354,6 +355,9 @@ public class TargetVM implements Runnable {
synchronized(this) {
while (controlRequest == 0) {
try {wait();} catch (InterruptedException e) {}
if (!shouldListen) {
return;
}
}
currentRequest = controlRequest;
controlRequest = 0;