On Sat, 3 Apr 2021 05:40:11 GMT, djelinski <github.com+30433125+djelin...@openjdk.org> wrote:
>> If you synchronize `putIfAbsent` but not `get` you'll still get the possible >> infinite loop described in the SO post. > > Expunging entries is synchronized over an internal data structure, so if you > synchronize puts only, nothing prevents expunge (called from get) from > running in parallel with put. > The original code performed big integer exponentiation inside a synchronized > block, your code doesn't. I expect substantial performance gains even with > synchronization around hash map access, this is why I asked about performance. I finally see that get() is affected by the locking. Expunge seems to not lock the able which could cause multiple threads get ops to corrupt the map. I'll put a ReentrantLock around the put & get. I prefer to not use synchronized() blocks as ReentrantLock maybe better after Project Loom Sure, the performance was largely affected by the math ops in the old code. I wanted to eliminate as much of the performance decelerators as possible ------------- PR: https://git.openjdk.java.net/jdk/pull/3296