7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck

Changed Provider class to use ConcurrentHashMap and default providers to use putService()

Reviewed-by: weijun, mullan
This commit is contained in:
Valerie Peng 2018-12-13 01:15:21 +00:00
parent f47bd19cbc
commit 0b05ebed2e
8 changed files with 1019 additions and 1152 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2018, 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
@ -29,7 +29,6 @@ import java.util.*;
import java.security.*;
import sun.security.action.PutAllAction;
import static sun.security.util.SecurityConstants.PROVIDER_VER;
/**
@ -46,17 +45,24 @@ public final class SunRsaSign extends Provider {
public SunRsaSign() {
super("SunRsaSign", PROVIDER_VER, "Sun RSA signature provider");
// if there is no security manager installed, put directly into
// the provider. Otherwise, create a temporary map and use a
// doPrivileged() call at the end to transfer the contents
Provider p = this;
Iterator<Provider.Service> serviceIter = new SunRsaSignEntries(p).iterator();
if (System.getSecurityManager() == null) {
SunRsaSignEntries.putEntries(this);
putEntries(serviceIter);
} else {
// use LinkedHashMap to preserve the order of the PRNGs
Map<Object, Object> map = new HashMap<>();
SunRsaSignEntries.putEntries(map);
AccessController.doPrivileged(new PutAllAction(this, map));
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
putEntries(serviceIter);
return null;
}
});
}
}
void putEntries(Iterator<Provider.Service> i) {
while (i.hasNext()) {
putService(i.next());
}
}
}