RFR: 8262316: Reducing locks in RSA Blinding

Anthony Scarpino ascarpino at openjdk.java.net
Fri Apr 2 17:48:25 UTC 2021

On Fri, 2 Apr 2021 06:36:57 GMT, djelinski <github.com+30433125+djelinski at openjdk.org> wrote:

>> Hi,
>> I need a review of the locking change to the RSA blinding code. The problem was reported that multithreaded performance suffered because there was one global lock on the many blindings operation.  The change reduces locking by using a ConcurrentLinkedQueue to store the different BlindingParameters that other threads maybe using.  The queue size is limited to prevent sudden surges in stored BlindingParameters and a WeakHashMap is still used so the objects can be freed when no longer used.  Performance doubles under high load.
>> thanks
>> Tony
> src/java.base/share/classes/sun/security/rsa/RSACore.java line 66:
>> 64:     // like performance testing.
>> 65:     private static final Map<BigInteger, ConcurrentLinkedQueue<BlindingParameters>>
>> 66:                 blindingCache = new WeakHashMap<>();
> I'd use a synchronizedMap here now

Using a synchronizedMap would only let one thread access the hashmap at a time, which is what I'm trying to reduce.  Get ops do not need to be locked and put ops don't either because the values are objects of random data, losing one is not significant to the operation.


PR: https://git.openjdk.java.net/jdk/pull/3296

More information about the security-dev mailing list