mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 20:44:41 +02:00
7107613: scalability bloker in javax.crypto.CryptoPermissions
Changed the type of field "perms" from Hashtable to ConcurrentHashMap. Reviewed-by: weijun, xuelei
This commit is contained in:
parent
6a5d4204af
commit
21f7aaed74
1 changed files with 52 additions and 19 deletions
|
@ -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.
|
* 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
|
||||||
|
@ -30,10 +30,16 @@ import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ObjectStreamField;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectInputStream.GetField;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.ObjectOutputStream.PutField;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,15 +67,24 @@ implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4946547168093391015L;
|
private static final long serialVersionUID = 4946547168093391015L;
|
||||||
|
|
||||||
// This class is similar to java.security.Permissions
|
/**
|
||||||
private Hashtable<String, PermissionCollection> perms;
|
* @serialField perms java.util.Hashtable
|
||||||
|
*/
|
||||||
|
private static final ObjectStreamField[] serialPersistentFields = {
|
||||||
|
new ObjectStreamField("perms", Hashtable.class),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Switched from Hashtable to ConcurrentHashMap to improve scalability.
|
||||||
|
// To maintain serialization compatibility, this field is made transient
|
||||||
|
// and custom readObject/writeObject methods are used.
|
||||||
|
private transient ConcurrentHashMap<String,PermissionCollection> perms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new CryptoPermissions object containing
|
* Creates a new CryptoPermissions object containing
|
||||||
* no CryptoPermissionCollections.
|
* no CryptoPermissionCollections.
|
||||||
*/
|
*/
|
||||||
CryptoPermissions() {
|
CryptoPermissions() {
|
||||||
perms = new Hashtable<String, PermissionCollection>(7);
|
perms = new ConcurrentHashMap<>(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,9 +147,7 @@ implements Serializable {
|
||||||
getPermissionCollection(cryptoPerm);
|
getPermissionCollection(cryptoPerm);
|
||||||
pc.add(cryptoPerm);
|
pc.add(cryptoPerm);
|
||||||
String alg = cryptoPerm.getAlgorithm();
|
String alg = cryptoPerm.getAlgorithm();
|
||||||
if (!perms.containsKey(alg)) {
|
perms.putIfAbsent(alg, pc);
|
||||||
perms.put(alg, pc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,11 +390,9 @@ implements Serializable {
|
||||||
PermissionCollection getPermissionCollection(String alg) {
|
PermissionCollection getPermissionCollection(String alg) {
|
||||||
// If this CryptoPermissions includes CryptoAllPermission,
|
// If this CryptoPermissions includes CryptoAllPermission,
|
||||||
// we should return CryptoAllPermission.
|
// we should return CryptoAllPermission.
|
||||||
if (perms.containsKey(CryptoAllPermission.ALG_NAME)) {
|
PermissionCollection pc = perms.get(CryptoAllPermission.ALG_NAME);
|
||||||
return perms.get(CryptoAllPermission.ALG_NAME);
|
if (pc == null) {
|
||||||
}
|
pc = perms.get(alg);
|
||||||
|
|
||||||
PermissionCollection pc = perms.get(alg);
|
|
||||||
|
|
||||||
// If there isn't a PermissionCollection for
|
// If there isn't a PermissionCollection for
|
||||||
// the given algorithm,we should return the
|
// the given algorithm,we should return the
|
||||||
|
@ -390,6 +401,7 @@ implements Serializable {
|
||||||
if (pc == null) {
|
if (pc == null) {
|
||||||
pc = perms.get(CryptoPermission.ALG_NAME_WILDCARD);
|
pc = perms.get(CryptoPermission.ALG_NAME_WILDCARD);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,6 +426,28 @@ implements Serializable {
|
||||||
}
|
}
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readObject(ObjectInputStream s)
|
||||||
|
throws IOException, ClassNotFoundException {
|
||||||
|
ObjectInputStream.GetField fields = s.readFields();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Hashtable<String,PermissionCollection> permTable =
|
||||||
|
(Hashtable<String,PermissionCollection>)
|
||||||
|
(fields.get("perms", null));
|
||||||
|
if (permTable != null) {
|
||||||
|
perms = new ConcurrentHashMap<>(permTable);
|
||||||
|
} else {
|
||||||
|
perms = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeObject(ObjectOutputStream s) throws IOException {
|
||||||
|
Hashtable<String,PermissionCollection> permTable =
|
||||||
|
new Hashtable<>(perms);
|
||||||
|
ObjectOutputStream.PutField fields = s.putFields();
|
||||||
|
fields.put("perms", permTable);
|
||||||
|
s.writeFields();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class PermissionsEnumerator implements Enumeration<Permission> {
|
final class PermissionsEnumerator implements Enumeration<Permission> {
|
||||||
|
@ -456,7 +490,6 @@ final class PermissionsEnumerator implements Enumeration<Permission> {
|
||||||
} else {
|
} else {
|
||||||
throw new NoSuchElementException("PermissionsEnumerator");
|
throw new NoSuchElementException("PermissionsEnumerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Enumeration<Permission> getNextEnumWithMore() {
|
private Enumeration<Permission> getNextEnumWithMore() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue