RFR: 8198540: Dynalink leaks memory when generating type converters [v5]

Peter Levart plevart at openjdk.java.net
Fri Jan 8 19:00:57 UTC 2021


On Fri, 8 Jan 2021 16:50:24 GMT, Attila Szegedi <attila at openjdk.org> wrote:

>> I checked the code of ClassValue and it can be assumed that it publishes associated values safely. The proof is that it keeps values that it publishes assigned to the final field `java.lang.ClassValue.Entry#value`.
>
> So, are you saying the solution where I kept the fields volatile and initialized them with `Map.of()` is safe? If so, that'd be good news; I'm inclined these days to write as much null-free code as possible :-)

Yes, the pre-initialized fields to Map.of() are safe regardless of whether they are volatile or not (so I would keep them non-volatile to optimize fast-path). Because the BiClassValues instance is published safely to other threads via ClassValue and because you never assign null to the fields later on.

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

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


More information about the core-libs-dev mailing list