Mercurial > hg > openjdk > jdk9 > nashorn
changeset 1601:ca4d50be062e
8146274: Thread spinning on WeakHashMap.getEntry() with concurrent use of nashorn
Reviewed-by: mhaupt, attila
author | hannesw |
---|---|
date | Mon, 18 Jan 2016 10:25:36 +0100 |
parents | e56208758885 |
children | 981b353f2f75 |
files | src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties |
diffstat | 2 files changed, 27 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java Thu Jan 14 12:03:53 2016 -0800 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java Mon Jan 18 10:25:36 2016 +0100 @@ -54,7 +54,13 @@ */ PropertyListeners(final PropertyListeners listener) { if (listener != null && listener.listeners != null) { - this.listeners = new WeakHashMap<>(listener.listeners); + this.listeners = new WeakHashMap<>(); + // We need to copy the nested weak sets in order to avoid concurrent modification issues, see JDK-8146274 + synchronized (listener) { + for (final Map.Entry<Object, WeakPropertyMapSet> entry : listener.listeners.entrySet()) { + this.listeners.put(entry.getKey(), new WeakPropertyMapSet(entry.getValue())); + } + } } } @@ -228,7 +234,15 @@ private static class WeakPropertyMapSet { - private final WeakHashMap<PropertyMap, Boolean> map = new WeakHashMap<>(); + private final WeakHashMap<PropertyMap, Boolean> map; + + WeakPropertyMapSet() { + this.map = new WeakHashMap<>(); + } + + WeakPropertyMapSet(final WeakPropertyMapSet set) { + this.map = new WeakHashMap<>(set.map); + } void add(final PropertyMap propertyMap) { map.put(propertyMap, Boolean.TRUE);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties Thu Jan 14 12:03:53 2016 -0800 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties Mon Jan 18 10:25:36 2016 +0100 @@ -24,7 +24,7 @@ Object.isSealed=tells if an object is sealed or not -Object.isFrozen=tells if an object is fronzen or not +Object.isFrozen=tells if an object is frozen or not Object.isExtensible=tells if an object is extensible or not @@ -32,7 +32,7 @@ Object=creates a new script object or converts given value as a script object -Object.prototype.toString=returns a string representing of this object +Object.prototype.toString=returns a string representation of this object Object.prototype.hasOwnProperty=tells whether this object has the specified property or not @@ -42,3 +42,12 @@ Object.bindProperties=binds the source object's properties to the target object (nashorn extension) +Function=creates a new function with the given parameters and function body + +Function.prototype.toString=returns a string representation of this function + +Function.prototype.apply=invokes the function with the given this-reference and arguments array + +Function.prototype.call=invokes the function with the given this-reference and arguments + +Function.prototype.bind=returns a new function with bound this-reference and arguments