eclipse-vertx / vert.x

Vert.x is a tool-kit for building reactive applications on the JVM
http://vertx.io
Other
14.26k stars 2.07k forks source link

AccessMode.CONCURRENT should use a static final VarHandle to access its array #5216

Closed franz1981 closed 4 months ago

franz1981 commented 4 months ago

https://github.com/eclipse-vertx/vert.x/blob/d21c6b5b6a9e2cb02110769fa635958fc2bccb34/src/main/java/io/vertx/core/spi/context/storage/AccessMode.java#L27 in theory is used on the CONCURRENT instance which is stored in a static final-like (in term of semantic) field within AccessMode, but still IDK if the JIT trust transitively the final fields within the CONCURRENT class, so, this can cause a severe performance penalty while using its VarHandle.

It means it would be better to have a JMH benchmark to prove that everything it's fine there OR at just move VarHandle LOCALS_UPDATER into some proper static final declaration. See https://shipilev.net/jvm/anatomy-quarks/17-trust-nonstatic-final-fields/#_observations which is indeed related VarHandle.