< prev index next >
src/java.base/share/classes/java/lang/ClassValue.java
Print this page
@ rev 60626 : 8251397: NPE on ClassValue.ClassValueMap.cacheArray
| Reviewed-by: aph
~
@@ -27,10 +27,12 @@
import java.util.WeakHashMap;
import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicInteger;
+import jdk.internal.misc.Unsafe;
+
import static java.lang.ClassValue.ClassValueMap.probeHomeLocation;
import static java.lang.ClassValue.ClassValueMap.probeBackupLocations;
/**
* Lazily associate a computed value with (potentially) every type.
@@ -409,15 +411,19 @@
* It would be pointless to make this much smaller than the Class and ClassValueMap objects themselves.
* Must be a power of 2.
*/
private static final int INITIAL_ENTRIES = 32;
+ private static final Unsafe UNSAFE = Unsafe.getUnsafe();
+
/** Build a backing map for ClassValues.
* Also, create an empty cache array and install it on the class.
*/
ClassValueMap() {
sizeCache(INITIAL_ENTRIES);
+ // Trailing release fence to get safe publication
+ UNSAFE.storeFence();
}
Entry<?>[] getCache() { return cacheArray; }
/** Initiate a query. Store a promise (placeholder) if there is no value yet. */
< prev index next >