RFR: 8262316: Reducing locks in RSA Blinding [v2]

Florent Guillaume github.com+592810+efge at openjdk.java.net
Sat Apr 3 01:10:17 UTC 2021


On Fri, 2 Apr 2021 23:12:21 GMT, Anthony Scarpino <ascarpino at openjdk.org> wrote:

>> According to SO, unsynchronized writes to a map can lead to lock up, see here:
>> https://stackoverflow.com/a/1003237
>> Or here:
>> https://mailinator.blogspot.com/2009/06/beautiful-race-condition.html?m=1
>> What's the performance impact of adding synchronization on the hash map only?
>
> Ok, thanks for pointing that out, I didn't realize that limitation.  However using synchronizedMap is overkill as it locks every operation.  As I read it, only structural changes like adding and removing keys from the map causes problems.  Getting a value from the map does not.  Therefore I would only need to synchronize the putIfAbsent() at 449, which is pretty minor.  The expunging of the map is already synchronized in WeakHashMap.
> 
> The original code was half the performance of this one.

If you synchronize `putIfAbsent` but not `get` you'll still get the possible infinite loop described in the SO post.

-------------

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



More information about the security-dev mailing list