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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 15
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      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.

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

              Created:
              Updated:
              Resolved: