# HG changeset patch # User valeriep # Date 1344629339 25200 # Node ID 3fb57310d83b72d7c01c54e9074dd3bc7a8e152d # Parent f0156a32c08ffa910a66e0fdf3c482a51ee62ca4 7107616: scalability bloker in javax.crypto.JceSecurityManager Summary: Changed the type of field "exemptCache" from HashMap to ConcurrentHashMap. Reviewed-by: weijun, xuelei diff -r f0156a32c08f -r 3fb57310d83b 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> TrustedCallersCache = new Vector<>(2); - private static final Map exemptCache = - new HashMap<>(); + private static final ConcurrentMap 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; }