On Thu, 8 Jun 2023 22:06:56 GMT, Man Cao <m...@openjdk.org> wrote: > Hi all, > > Could anyone review this small fix for a data race in > java.io.ClassCache$CacheRef? This fix makes the code safer by making the code > data-race-free.
I think the race is benign also but the change maintains the essential semantics. The use of AtomicRef will have a very slight performance impact. The semantic is that at-least-one caller gets the reference before it can become "only" soft-referenced and might be reclaimed. The use of AtomicReference changes the semantic to be exactly-one caller gets the initial hard reference; other callers will be able to get the value from the soft-reference as long as the first caller holds the reference and perhaps beyond depending on memory pressure. ClassCaches are used by serialization to provide ObjectStreamClass descriptors. It is quite possible that multiple threads may be serializing the same classes. ------------- PR Comment: https://git.openjdk.org/jdk/pull/14386#issuecomment-1584941066