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

C1 should fold arraylength for constant/trusted arrays

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • hotspot
    • b110

      The golden example is String.length() over static final Strings:

          static final String TEST_STRING = "Foo";

          @Benchmark
          public int string_length() {
              return TEST_STRING.length();
          }

      C2 folds the underlying (byte[].length >> coder) fine, because it both trusts the final String.value/coder, and folds arraylength.
      C1 trusts String.value/coder after JDK-8149813, but does not fold arraylength yet.

      Sample benchmark + generated code:
       http://cr.openjdk.java.net/~shade/8150102/FoldArrayLength.java

      Proof-of-concept webrev:
       http://cr.openjdk.java.net/~shade/8150102/webrev.00

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: