Reopening #22919 as a new PR since the original PR could not be reopened. Changes: - Redirect `radix == 10` in `Integer.parseInt(String, int)` and `Long.parseLong(String, int)` to `parseInt(String)` and `parseLong(String)`, and call `parseInt(s)` / `parseLong(s)` directly from `valueOf(String)` and the deprecated `String` constructors. - Add a Latin1 decimal fast path in `Integer.parseInt(String)` and `Long.parseLong(String)` without using `Unsafe`, parsing two ASCII digits per iteration directly from `String.value()` without `Character.digit` table lookups. - Accumulate up to 9 digits (`int`) / 18 digits (`long`) without overflow checks in the loop, and check overflow once on the last digit (`parseLastDigit`) for 10-digit `int` / 19-digit `long`. `null`, empty strings, UTF-16 strings, and inputs with a valid first character exceeding 10/11 (unsigned/signed `int`) or 19/20 (unsigned/signed `long`) chars fall back to `parseInt0` / `parseLong0`, keeping all existing exception messages unchanged. - Keep `Integer.parseInt(String)` (301 bytes) and `Long.parseLong(String)` (306 bytes) below `FreqInlineSize` (325 bytes). - Add `Longs.parseLong` microbenchmark and expand `Integer/ParsingTest` and `Long/ParsingTest` (covering boundary values, exception messages, non-decimal radices, and both `+CompactStrings` / `-CompactStrings`).
### Benchmark Baseline for `Longs.parseLong` was measured with the same benchmark added on top of baseline. Linux x86_64 (Intel Xeon 6982P-C, `taskset -c 0`, `-f 3 -wi 10 -i 5`): | Benchmark | (size) | Mode | Cnt | Baseline (us/op) | Patch (us/op) | Diff (Speedup) | |---|---:|---|---:|---:|---:|---:| | `Integers.parseInt` | 500 | avgt | 15 | 2.784 ± 0.007 | 2.258 ± 0.006 | -18.9% (1.23x) | | `Longs.parseLong` | 500 | avgt | 15 | 3.027 ± 0.036 | 2.558 ± 0.011 | -15.5% (1.18x) | Linux aarch64 (Orange Pi 6 Plus, `taskset -c 0`, `-f 3 -wi 10 -i 5`): | Benchmark | (size) | Mode | Cnt | Baseline (us/op) | Patch (us/op) | Diff (Speedup) | |---|---:|---|---:|---:|---:|---:| | `Integers.parseInt` | 500 | avgt | 15 | 4.540 ± 0.027 | 3.599 ± 0.016 | -20.7% (1.26x) | | `Longs.parseLong` | 500 | avgt | 15 | 4.857 ± 0.026 | 3.964 ± 0.036 | -18.4% (1.23x) | ### Testing - `test/jdk/java/lang/Integer`, `test/jdk/java/lang/Long`, `test/jdk/java/lang/Byte`, `test/jdk/java/lang/Short`, `test/jdk/com/sun/jdi/JdbExprTest.java` (17/17 passed, including both `-XX:+CompactStrings` and `-XX:-CompactStrings` for `ParsingTest`). --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - Speed up decimal Integer.parseInt and Long.parseLong Changes: https://git.openjdk.org/jdk/pull/34188/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34188&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8347009 Stats: 490 lines in 5 files changed: 459 ins; 15 del; 16 mod Patch: https://git.openjdk.org/jdk/pull/34188.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/34188/head:pull/34188 PR: https://git.openjdk.org/jdk/pull/34188
