RFR: JDK-8311009: Long.toUnsignedString(long, int) doesn't have to create a BigInteger

Tingjun Yuan duke at openjdk.org
Wed Jun 28 03:43:06 UTC 2023


This PR changes the implementation of `Long.toUnsignedString(long, int)` for "default" radices, which avoids creating a `BigInteger` and makes use of `Long.divideUnsigned` and `Long.remainderUnsigned`.

I've run the test on `test/jdk/java/lang/Long/Unsigned.java` and it works correctly. I believe that there is no need to add more test cases.

I've add a benchmark case to `test/micro/org/openjdk/bench/java/lang/Longs.java` for this method. Here is the benchmark result tested on my machine:

Before (JDK 20.0.1):


Benchmark                       (size)  Mode  Cnt     Score    Error  Units
Longs.toUnsignedStringNegative     500  avgt   15  6428.711 ± 63.142  us/op


After:


Benchmark                       (size)  Mode  Cnt     Score     Error  Units
Longs.toUnsignedStringNegative     500  avgt   15  3823.655 ± 146.171  us/op


I've submitted a bug report for this to the [Java Bug Database](https://bugs.java.com/bugdatabase/). No CSR needed since the behavior is not changed.

-------------

Commit messages:
 - Typo: indices -> radices
 - Merge branch 'optimize-unsigned-string' of https://github.com/yuantj/jdk-pr into optimize-unsigned-string
 - Merge branch 'openjdk:master' into optimize-unsigned-string
 - Merge branch 'openjdk:master' into optimize-unsigned-string
 - Add benchmark
 - Update Long.java

Changes: https://git.openjdk.org/jdk/pull/14654/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14654&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8311009
  Stats: 21 lines in 2 files changed: 20 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/14654.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14654/head:pull/14654

PR: https://git.openjdk.org/jdk/pull/14654


More information about the core-libs-dev mailing list