8146986: JDI: Signature lookups for unprepared classes can take a long time
authorsspitsyn
Mon, 25 Mar 2019 19:16:58 -0700
changeset 54270 176e8aec3097
parent 54269 418fbdb1b581
child 54271 44edf64cb206
8146986: JDI: Signature lookups for unprepared classes can take a long time Summary: Do not cache classes if signature is not provided Reviewed-by: sspitsyn, jcbeyler
src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java
--- a/src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java	Mon Mar 25 19:40:25 2019 -0400
+++ b/src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java	Mon Mar 25 19:16:58 2019 -0700
@@ -33,10 +33,11 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.TreeSet;
+import java.util.Set;
 
 import com.sun.jdi.BooleanType;
 import com.sun.jdi.BooleanValue;
@@ -110,7 +111,7 @@
     // tested unsynchronized (since once true, it stays true), but must
     // be set synchronously
     private Map<Long, ReferenceType> typesByID;
-    private TreeSet<ReferenceType> typesBySignature;
+    private Set<ReferenceType> typesBySignature;
     private boolean retrievedAllTypes = false;
 
     private Map<Long, ModuleReference> modulesByID;
@@ -843,14 +844,9 @@
                 throw new InternalException("Invalid reference type tag");
         }
 
-        /*
-         * If a signature was specified, make sure to set it ASAP, to
-         * prevent any needless JDWP command to retrieve it. (for example,
-         * typesBySignature.add needs the signature, to maintain proper
-         * ordering.
-         */
-        if (signature != null) {
-            type.setSignature(signature);
+        if (signature == null && retrievedAllTypes) {
+            // do not cache if signature is not provided
+            return type;
         }
 
         typesByID.put(id, type);
@@ -920,7 +916,7 @@
 
     private void initReferenceTypes() {
         typesByID = new HashMap<>(300);
-        typesBySignature = new TreeSet<>();
+        typesBySignature = new HashSet<>();
     }
 
     ReferenceTypeImpl referenceType(long ref, byte tag) {
@@ -969,6 +965,9 @@
                 if (retType == null) {
                     retType = addReferenceType(id, tag, signature);
                 }
+                if (signature != null) {
+                    retType.setSignature(signature);
+                }
             }
             return retType;
         }