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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 15
    • None
    • 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.

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

              Created:
              Updated:
              Resolved: