8046025: AccessorProperty.getGetter is not threadsafe
authorattila
Mon, 09 Jun 2014 16:00:06 +0200
changeset 24880 cac5f6a0a40c
parent 24879 d316854e4249
child 24881 67cf2d94e00a
8046025: AccessorProperty.getGetter is not threadsafe Reviewed-by: jlaskey, lagergren
nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Fri Jun 06 16:51:53 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java	Mon Jun 09 16:00:06 2014 +0200
@@ -550,8 +550,13 @@
                 "invalid getter type " + type + " for " + getKey();
 
         //all this does is add a return value filter for object fields only
-        if (GETTER_CACHE[i] == null) {
-            GETTER_CACHE[i] = debug(
+        final MethodHandle[] getterCache = GETTER_CACHE;
+        final MethodHandle cachedGetter = getterCache[i];
+        final MethodHandle getter;
+        if (cachedGetter != null) {
+            getter = cachedGetter;
+        } else {
+            getter = debug(
                 createGetter(
                     getCurrentType(),
                     type,
@@ -561,9 +566,10 @@
                 getCurrentType(),
                 type,
                 "get");
+            getterCache[i] = getter;
        }
-       assert GETTER_CACHE[i].type().returnType() == type && GETTER_CACHE[i].type().parameterType(0) == Object.class;
-       return GETTER_CACHE[i];
+       assert getter.type().returnType() == type && getter.type().parameterType(0) == Object.class;
+       return getter;
     }
 
     @Override