8169961: Memory leak after debugging session
authorshshahma
Fri, 18 Aug 2017 04:34:16 -0700
changeset 46889 f0fd7a278d72
parent 46887 27d6560ebe9f
child 46890 136ed8eef97b
8169961: Memory leak after debugging session Summary: 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
jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/TargetVM.java
--- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/TargetVM.java	Sun Aug 20 20:36:12 2017 -0700
+++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/TargetVM.java	Fri Aug 18 04:34:16 2017 -0700
@@ -41,7 +41,7 @@
 
 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 @@
 
         // 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 @@
 
     private EventController eventController() {
         if (eventController == null) {
-            eventController = new EventController(vm);
+            eventController = new EventController();
         }
         return eventController;
     }
@@ -326,13 +329,11 @@
         } 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 @@
                 synchronized(this) {
                     while (controlRequest == 0) {
                         try {wait();} catch (InterruptedException e) {}
+                        if (!shouldListen) {
+                           return;
+                        }
                     }
                     currentRequest = controlRequest;
                     controlRequest = 0;