From 9f8c1be30547ea7dca3579a2a6fc5794f1b7b58c Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Mon, 9 Jun 2014 16:00:06 +0200 Subject: [PATCH] 8046025: AccessorProperty.getGetter is not threadsafe Reviewed-by: jlaskey, lagergren --- .../nashorn/internal/runtime/AccessorProperty.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java b/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java index f067742a04f..f19b7a32192 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/AccessorProperty.java @@ -550,8 +550,13 @@ public class AccessorProperty extends Property { "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 @@ public class AccessorProperty extends Property { 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