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

Anthony Scarpino ascarpino at openjdk.java.net
Fri Apr 2 23:15:22 UTC 2021


On Fri, 2 Apr 2021 20:52:42 GMT, djelinski <github.com+30433125+djelinski at openjdk.org> wrote:

>> 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.
>
> 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.

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

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


More information about the security-dev mailing list