RFR: 8359424: Eliminate table lookup in Integer/Long toHexString

Chen Liang liach at openjdk.org
Fri Jun 13 12:07:25 UTC 2025


On Tue, 7 Jan 2025 10:39:18 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> In PR #22928, UUID introduced long-based vectorized hexadecimal to string conversion, which can also be used in Integer::toHexString and Long::toHexString to eliminate table lookups. The benefit of eliminating table lookups is that the performance is better when cache misses occur.

src/java.base/share/classes/java/lang/Integer.java line 312:

> 310:      * this string as a hexadecimal number to form and return a long value.
> 311:      */
> 312:     static long hex8(long i) {

I think we should move this to HexDigits.

src/java.base/share/classes/java/lang/Long.java line 325:

> 323:             if (COMPACT_STRINGS) {
> 324:                 len -= 8;
> 325:                 Unsafe.getUnsafe().putLong(chars, ARRAY_BYTE_BASE_OFFSET + len, Long.reverseBytes(x));

We only need to reverse on small endian platforms right? We can use putLongUnaligned which takes a boolean for big endian so conversion is automatic.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22942#discussion_r1905774332
PR Review Comment: https://git.openjdk.org/jdk/pull/22942#discussion_r1905786538


More information about the core-libs-dev mailing list