changeset 17628:cbc248de6505

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
author shshahma
date Fri, 18 Aug 2017 04:34:16 -0700
parents 4469f4504558
children 3f515b6a5c99
files src/jdk.jdi/share/classes/com/sun/tools/jdi/TargetVM.java
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jdi/share/classes/com/sun/tools/jdi/TargetVM.java	Sun Aug 20 20:36:12 2017 -0700
+++ b/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;