提交 fb6cadb4 编写于 作者: V valeriep

7107616: scalability bloker in javax.crypto.JceSecurityManager

Summary: Changed the type of field "exemptCache" from HashMap to ConcurrentHashMap.
Reviewed-by: weijun, xuelei
上级 8cafc773
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,8 @@ package javax.crypto; ...@@ -28,6 +28,8 @@ package javax.crypto;
import java.security.*; import java.security.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* The JCE security manager. * The JCE security manager.
...@@ -51,8 +53,10 @@ final class JceSecurityManager extends SecurityManager { ...@@ -51,8 +53,10 @@ final class JceSecurityManager extends SecurityManager {
private static final CryptoAllPermission allPerm; private static final CryptoAllPermission allPerm;
private static final Vector<Class<?>> TrustedCallersCache = private static final Vector<Class<?>> TrustedCallersCache =
new Vector<>(2); new Vector<>(2);
private static final Map<URL, CryptoPermissions> exemptCache = private static final ConcurrentMap<URL,CryptoPermissions> exemptCache =
new HashMap<>(); new ConcurrentHashMap<>();
private static final CryptoPermissions CACHE_NULL_MARK =
new CryptoPermissions();
// singleton instance // singleton instance
static final JceSecurityManager INSTANCE; static final JceSecurityManager INSTANCE;
...@@ -117,17 +121,19 @@ final class JceSecurityManager extends SecurityManager { ...@@ -117,17 +121,19 @@ final class JceSecurityManager extends SecurityManager {
return defaultPerm; return defaultPerm;
} }
CryptoPermissions appPerms; CryptoPermissions appPerms = exemptCache.get(callerCodeBase);
synchronized (this.getClass()) { if (appPerms == null) {
if (exemptCache.containsKey(callerCodeBase)) { // no match found in cache
synchronized (this.getClass()) {
appPerms = exemptCache.get(callerCodeBase); appPerms = exemptCache.get(callerCodeBase);
} else { if (appPerms == null) {
appPerms = getAppPermissions(callerCodeBase); appPerms = getAppPermissions(callerCodeBase);
exemptCache.put(callerCodeBase, appPerms); exemptCache.putIfAbsent(callerCodeBase,
(appPerms == null? CACHE_NULL_MARK:appPerms));
}
} }
} }
if (appPerms == null || appPerms == CACHE_NULL_MARK) {
if (appPerms == null) {
return defaultPerm; return defaultPerm;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册