changeset 1215:78f82d897305

8075006: Threads spinning infinitely in WeakHashMap.get running test262parallel Reviewed-by: lagergren, attila
author hannesw
date Fri, 13 Mar 2015 18:40:07 +0100
parents b2b332e64b7b
children ce9cf6c2d3f5
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java
diffstat 1 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java	Thu Mar 12 21:14:04 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java	Fri Mar 13 18:40:07 2015 +0100
@@ -330,12 +330,15 @@
      * Indicate that proto itself has changed in hierarchy somewhere.
      */
     synchronized void invalidateAllProtoGetSwitchPoints() {
-        if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) {
-            if (Context.DEBUG) {
-                protoInvalidations += protoGetSwitches.size();
+        if (protoGetSwitches != null) {
+            final int size = protoGetSwitches.size();
+            if (size > 0) {
+                if (Context.DEBUG) {
+                    protoInvalidations += size;
+                }
+                SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[size]));
+                protoGetSwitches.clear();
             }
-            SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()]));
-            protoGetSwitches.clear();
         }
     }
 
@@ -375,7 +378,8 @@
         }
     }
 
-    // Update the free slots bitmap for a property that has been deleted and/or added.
+    // Update the free slots bitmap for a property that has been deleted and/or added. This method is not synchronized
+    // as it is always invoked on a newly created instance.
     private void updateFreeSlots(final Property oldProperty, final Property newProperty) {
         // Free slots bitset is possibly shared with parent map, so we must clone it before making modifications.
         boolean freeSlotsCloned = false;
@@ -425,7 +429,7 @@
      *
      * @return New {@link PropertyMap} with {@link Property} added.
      */
-    public PropertyMap addProperty(final Property property) {
+    public synchronized PropertyMap addProperty(final Property property) {
         if (listeners != null) {
             listeners.propertyAdded(property);
         }
@@ -434,9 +438,9 @@
         if (newMap == null) {
             final PropertyHashMap newProperties = properties.immutableAdd(property);
             newMap = new PropertyMap(this, newProperties);
-            addToHistory(property, newMap);
             newMap.updateFlagsAndBoundaries(property);
             newMap.updateFreeSlots(null, property);
+            addToHistory(property, newMap);
         }
 
         return newMap;
@@ -449,7 +453,7 @@
      *
      * @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found.
      */
-    public PropertyMap deleteProperty(final Property property) {
+    public synchronized PropertyMap deleteProperty(final Property property) {
         if (listeners != null) {
             listeners.propertyDeleted(property);
         }
@@ -881,8 +885,7 @@
      * @param newProto New prototype object to replace oldProto.
      * @return New {@link PropertyMap} with prototype changed.
      */
-    public PropertyMap changeProto(final ScriptObject newProto) {
-
+    public synchronized PropertyMap changeProto(final ScriptObject newProto) {
         final PropertyMap nextMap = checkProtoHistory(newProto);
         if (nextMap != null) {
             return nextMap;