提交 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.
*
* 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<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 @@ 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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册