From fb6cadb4a29ec71517dad91ad1bdf4fcb1668479 Mon Sep 17 00:00:00 2001 From: valeriep Date: Fri, 10 Aug 2012 13:08:59 -0700 Subject: [PATCH] 7107616: scalability bloker in javax.crypto.JceSecurityManager Summary: Changed the type of field "exemptCache" from HashMap to ConcurrentHashMap. Reviewed-by: weijun, xuelei --- .../javax/crypto/JceSecurityManager.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/share/classes/javax/crypto/JceSecurityManager.java b/src/share/classes/javax/crypto/JceSecurityManager.java index c05a20080..d4818acc8 100644 --- a/src/share/classes/javax/crypto/JceSecurityManager.java +++ b/src/share/classes/javax/crypto/JceSecurityManager.java @@ -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 @@ package javax.crypto; 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 @@ final class JceSecurityManager extends SecurityManager { 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 @@ final class JceSecurityManager extends SecurityManager { 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; } -- GitLab