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

Integer/Long getChars and stringSize should be more idiomatic

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b96
    • Verification:
      Verified

      Description

      Current (Integer|Long).getChars are using the non-idiomatic constructs, possibly targeted to improve performance, see e.g.:

              for (;;) {
                  q2 = (i2 * 52429) >>> (16+3); // q2 = q2 / 10
                  r = i2 - ((q2 << 3) + (q2 << 1)); // r = i2-(q2*10) ...
                  buf[--charPos] = Integer.digits[r];
                  i2 = q2;
                  if (i2 == 0) break;
              }

      This was apparently done before 1994 (estimate given by Josh Bloch), way before Java optimizing compilers could do strength-reduction on their own, and on some hardware manually replacing multiplications and divisions helped. It does not appear true anymore. Therefore, we need to see if we want a more idiomatic code there.

      Sample benchmark:
       http://cr.openjdk.java.net/~shade/8136500/LongToString.java

      Sample result shows improvement with a very dumb patch:
       http://cr.openjdk.java.net/~shade/8136500/notes.txt

      Other things to do:
       a) Make sure strength-reductions happen at least in C2-optimized code;
       b) Do the same for Integer.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                shade Aleksey Shipilev
                Reporter:
                shade Aleksey Shipilev
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: