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

Operations on constant List/Set.of(element) instances does not consistently constant fold

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b06

      Description

      For a single-element set, Set.of uses Set12 with the second element set to null. For determining @Stableness, a null value is a proxy for "might not be initialized", which unfortunately means the JIT can't consistently constant fold operations that check e1 == null.

      Since null values are prohibited, and a 2-element Set disallows duplicate entries, we could get around this by storing the same instance to both fields of Set12 in the single-element constructor. This allows operations like set.size() to be properly constant folded, with a modest improvement in targeted microbenchmarks.

        Attachments

          Activity

            People

            • Assignee:
              redestad Claes Redestad
              Reporter:
              redestad Claes Redestad
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: