[lworld] Javac should not generate a loadable descriptor for null restricted value fields

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • repo-valhalla
    • Affects Version/s: repo-valhalla
    • Component/s: tools

      For test case:

      import jdk.internal.vm.annotation.NullRestricted;
      import jdk.internal.vm.annotation.Strict;

      public class NRTest {
          static value class Value { int i = 0; }

          @Strict
          @NullRestricted
          Value v = new Value();
          
          public static void main(String[] args) {
              var t = new NRTest();
          }
      }

      javac adds the type of field v to the LoadableDescriptors attribute:

      LoadableDescriptors:
        LNRTest$Value;

      The presence of the field's type in the LoadableDescriptors attribute is not an error, but it is useless and in fact triggers more work in the JVM. Types of non-static null-restricted (an by consequence strict) fields are automatically loaded by the JVM without consulting the LoadableDescriptors attribute. The presence of this type in the attribute will trigger another attempt to load the type at class link time, which is a waste of time because the type is already present in the system dictionary at this time.

      Note that non-static null-restricted fields are the only ones currently having their type automatically loaded by the JVM, for all other types from static fields and method arguments, the presence in the LoadableDescriptors attribute is required to guarantee layout and calling convention optimizations.

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: