hazelcast icon indicating copy to clipboard operation
hazelcast copied to clipboard

`FieldProbe`s should make use of `VarHandle`s

Open JackPGreen opened this issue 2 years ago • 3 comments

          Once the type system is enriched with the other primitive types, you can use a VarHandle and use the same technique to prevent litter as with the MethodProbe.

Originally posted by @pveentjer in https://github.com/hazelcast/hazelcast/pull/25279#discussion_r1336138919

JackPGreen avatar Sep 25 '23 21:09 JackPGreen

Basic implementation started, but performs slower (4.2 vs 1.7ns) than the current reflection implementation.

Raised on Stackoverflow.

JackPGreen avatar Sep 25 '23 22:09 JackPGreen

After further investigation, I'm not sure that VarHandles on their own are a good idea without additional supporting frameworks due to performance concerns.

JackPGreen avatar Sep 29 '23 15:09 JackPGreen

An alternative solution to non-static-final VarHandle slowness would be to add -XX:+TrustFinalNonStaticFields (unrealistic for production) or to keep the var handle in records (not applicable to your usage too), just in case you are interested. https://shipilev.net/jvm/anatomy-quarks/17-trust-nonstatic-final-fields/ https://minborgsjavapot.blogspot.com/2023/09/java-records-are-trusted-and.html

liach avatar May 29 '24 21:05 liach