7107616: scalability bloker in javax.crypto.JceSecurityManager
authorvaleriep
Fri, 10 Aug 2012 13:08:59 -0700
changeset 13558 3fb57310d83b
parent 13557 f0156a32c08f
child 13559 17445744f2af
7107616: scalability bloker in javax.crypto.JceSecurityManager Summary: Changed the type of field "exemptCache" from HashMap to ConcurrentHashMap. Reviewed-by: weijun, xuelei
jdk/src/share/classes/javax/crypto/JceSecurityManager.java
--- a/jdk/src/share/classes/javax/crypto/JceSecurityManager.java	Fri Aug 10 13:08:23 2012 -0700
+++ b/jdk/src/share/classes/javax/crypto/JceSecurityManager.java	Fri Aug 10 13:08:59 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,8 @@
 import java.security.*;
 import java.net.*;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * The JCE security manager.
@@ -51,8 +53,10 @@
     private static final CryptoAllPermission allPerm;
     private static final Vector<Class<?>> TrustedCallersCache =
             new Vector<>(2);
-    private static final Map<URL, CryptoPermissions> exemptCache =
-            new HashMap<>();
+    private static final ConcurrentMap<URL,CryptoPermissions> exemptCache =
+            new ConcurrentHashMap<>();
+    private static final CryptoPermissions CACHE_NULL_MARK =
+            new CryptoPermissions();
 
     // singleton instance
     static final JceSecurityManager INSTANCE;
@@ -117,17 +121,19 @@
             return defaultPerm;
         }
 
-        CryptoPermissions appPerms;
-        synchronized (this.getClass()) {
-            if (exemptCache.containsKey(callerCodeBase)) {
+        CryptoPermissions appPerms = exemptCache.get(callerCodeBase);
+        if (appPerms == null) {
+            // no match found in cache
+            synchronized (this.getClass()) {
                 appPerms = exemptCache.get(callerCodeBase);
-            } else {
-                appPerms = getAppPermissions(callerCodeBase);
-                exemptCache.put(callerCodeBase, appPerms);
+                if (appPerms == null) {
+                    appPerms = getAppPermissions(callerCodeBase);
+                    exemptCache.putIfAbsent(callerCodeBase,
+                        (appPerms == null? CACHE_NULL_MARK:appPerms));
+                }
             }
         }
-
-        if (appPerms == null) {
+        if (appPerms == null || appPerms == CACHE_NULL_MARK) {
             return defaultPerm;
         }