Don't expand LongMap lazily JEP-349-branch
authoregahlin
Wed, 16 Oct 2019 01:16:12 +0200
branchJEP-349-branch
changeset 58640 496bbf554c5c
parent 58578 7b89c53db169
child 58642 38176d1c5ec2
Don't expand LongMap lazily
src/jdk.jfr/share/classes/jdk/jfr/internal/LongMap.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/LongMap.java	Sun Oct 13 16:46:15 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/LongMap.java	Wed Oct 16 01:16:12 2019 +0200
@@ -157,9 +157,6 @@
             // Lazy initialization
             initialize(DEFAULT_SIZE);
         }
-        if (count > 3 * keys.length / 4) {
-            expand(2 * keys.length);
-        }
         if (object == null) {
             object = (T) NULL_OBJECT;
         }
@@ -171,6 +168,12 @@
                 keys[index] = id;
                 objects[index] = object;
                 count++;
+                // Don't expand lazy since it
+                // can cause resize when replacing
+                // an object.
+                if (count > 3 * keys.length / 4) {
+                    expand(2 * keys.length);
+                }
                 return;
             }
             // if it already exists, replace