Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8058164

final fields in objects need to support inlining optimizations


    • Type: Enhancement
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 9, 10
    • Fix Version/s: tbd_feature
    • Component/s: hotspot
    • Labels:


      A value in an object field cannot be constant-folded even when the field is marked 'final' and the enclosing object itself can be determined at compile time. This is because 'final' fields are not enforced by the JVM.

      The long term fix for this is to properly optimize the common case of any field which is set in an object constructor and then never changed, not even by reflection or JNI.

      This is a performance issue for various system data structures, which is patched for specific classes like method handle combinators and strings. We need general-purpose logic, since the number of performance-affecting final fields is trending upward.

      The fix for the previous bug JDK-6912065 includes an experimental JVM flag -XX:+TrustFinalNonStaticFields for performance experiments. But that is not a general fix, because it does not check for store-to-final events caused by reflection, JNI, Unsafe, deserialization, etc.

      I think the hard part is convincing ourselves that we have found all the places where the surprising store-to-final could occur. The straightforward part is putting a little interlock in each of those places to discard code blocs (n-methods) that rely on the field suffering the store.

      We would create a new JIT dependency for registering which code blobs speculate against store-to-final. It can be made nicely granular, by indexing on the class containing the final, rather than having a global "panic button". We also need a record of which finals had been "spoiled" in this way; this can be a bit on the containing class.

      Deserialization of objects with finals might create false positives; it is moderately likely that this is worth special-casing. For example, the final field java.util.Arrays.ArrayList.a is both deserialized and performance-affecting.

        Issue Links


          vlivanov Vladimir Ivanov (Inactive) added a comment -
          vlivanov Vladimir Ivanov (Inactive) added a comment - Initial prototype(hotspot + jdk):    http://cr.openjdk.java.net/~vlivanov/8058164/webrev.00 Related discussion on hotspot-compiler-dev:    http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2015-June/018342.html


            • Assignee:
              vlivanov Vladimir Ivanov (Inactive)
              jrose John Rose
            • Votes:
              1 Vote for this issue
              5 Start watching this issue


              • Created: