8046025: AccessorProperty.getGetter is not threadsafe
Reviewed-by: jlaskey, lagergren
--- 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