RFR: 8343962: [REDO] Move getChars to DecimalDigits [v7]
Claes Redestad
redestad at openjdk.org
Sun Jan 19 02:13:49 UTC 2025
On Sat, 18 Jan 2025 21:48:39 GMT, Chen Liang <liach at openjdk.org> wrote:
>> The doc of `Unsafe::putChar()` delegates to the doc of `Unsafe::putInt()` which clearly states that the `Object` and `offset` arguments must locate a variable of the same type as the one of argument `x`, which is not the case here.
>
> This is safe. See https://github.com/openjdk/jdk/blob/3804082cba56e6d26c500880cc5cbe6d4332d8f8/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template#L129-L132, where `MethodHandles.byteArrayViewVarHandle` implementation does getChar/Short/Int/Long on a byte array.
The difference there is the use of `Unsafe.get/putCharUnaligned`. I think `putChar` might work for all current platforms and modes since we're always storing at an index that is divisible by 2 in the byte array, thus aligned up to `char`. That said this might be an abuse of an unspecified behavior and adding `-Unaligned` might be a bit safer.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22023#discussion_r1921350812
More information about the core-libs-dev
mailing list