< prev index next >

src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -24,14 +24,11 @@
  */
 
 package com.sun.tools.jdi;
 
 import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import com.sun.jdi.ThreadGroupReference;
 import com.sun.jdi.ThreadReference;
 import com.sun.jdi.VirtualMachine;
 

@@ -42,16 +39,14 @@
     private final List<WeakReference<VMListener>> listeners = new ArrayList<>(); // synchronized (this)
     private boolean notifyingListeners = false;  // synchronized (this)
 
     /*
      * Certain information can be cached only when the entire VM is
-     * suspended and there are no pending resumes. The fields below
-     * are used to track whether there are pending resumes. (There
-     * is an assumption that JDWP command ids are increasing over time.)
+     * suspended and there are no pending resumes. The field below
+     * is used to track whether there are pending resumes.
      */
-    private int lastCompletedCommandId = 0;   // synchronized (this)
-    private int lastResumeCommandId = 0;      // synchronized (this)
+    private final Set<Integer> pendingResumeCommands = Collections.synchronizedSet(new HashSet<>());
 
     // This is cached only while the VM is suspended
     private static class Cache {
         List<ThreadGroupReference> groups = null;  // cached Top Level ThreadGroups
         List<ThreadReference> threads = null; // cached Threads

@@ -95,16 +90,16 @@
 
     /*
      * A JDWP command has been completed (reply has been received).
      * Update data that tracks pending resume commands.
      */
-    synchronized void notifyCommandComplete(int id) {
-        lastCompletedCommandId = id;
+    void notifyCommandComplete(int id) {
+        pendingResumeCommands.remove(id);
     }
 
     synchronized void freeze() {
-        if (cache == null && (lastCompletedCommandId >= lastResumeCommandId)) {
+        if (cache == null && (pendingResumeCommands.isEmpty())) {
             /*
              * No pending resumes to worry about. The VM is suspended
              * and additional state can be cached. Notify all
              * interested listeners.
              */

@@ -113,11 +108,11 @@
         }
     }
 
     synchronized PacketStream thawCommand(CommandSender sender) {
         PacketStream stream = sender.send();
-        lastResumeCommandId = stream.id();
+        pendingResumeCommands.add(stream.id());
         thaw();
         return stream;
     }
 
     /**
< prev index next >