Truly Final Fields with Anna Thomas

2,348 views · Published 31 July 2018 · 37:00 · Indexed 29 October 2026

Channel: Java · 2018 · Science & Technology

Watch on YouTube

Final fields in java is defined for static and non-static (instance) fields. Static final fields are always trusted as final except for certain fields in the java.lang.system class as defined in the spec. However, instance final in Java is not actually final because of the multiple ways available to break that property via reflection, JNI, unsafe etc. This makes it inherently hard to correctly implement this optimization and tap on the nice performance gains available through constant folding (and various other optimizations) of final fields in practical applications. Implementing truly final optimization in a JVM requires tracking the finality dependency, optimizing code based on this information and invalidating code if the dependency is no longer true. 

In this talk, I will dive into the details of how we implemented the truly final dependency tracking (and invalidation) in our Zing JVM and the optimizations done for final fields within Falcon, our LLVM based JIT compiler for the Zing JVM. For the latter, I will also give an idea of our callback mechanism in Falcon, which allows us to ask questions to the VM about the finality of a field. We will present specific examples showing the benefit of the truly final optimizations and improvements we plan to do by extending this mechanism to effectively final fields.

More from this channel