RFR: 8349503: Consolidate multi-byte access into ByteArray
Paul Sandoz
psandoz at openjdk.org
Thu Feb 6 14:33:11 UTC 2025
On Wed, 5 Feb 2025 23:41:19 GMT, Chen Liang <liach at openjdk.org> wrote:
> `MethodHandles.byteArrayViewVarHandle` exposes checked multi-byte access to byte arrays via VarHandle. This larger access speeds up many operations, yet it cannot be used in early bootstrap, and as a result, people tend to use `Unsafe` which can threaten memory safety of the Java Platform.
>
> To promote the safe use of multi-byte access, I propose to move the checked implementations from VarHandle to ByteArray to allow earlier use and reduce maintenance costs. In addition, ByteArrayLittleEndian is consolidated, and now the access methods are distinguished by BO (byte order) / BE (big endian) / LE (little endian) suffixes to indicate their access features.
This looks reasonable, not looked in detail at all of it. Although i understand the motivation can you please revert the changes to VarHandle. VarHandle is intended to be as thin as possible safe wrapper around unsafe. This PR changes how this is for one particular kind of handle thus differing from the others, and it also creates an indirection with a potential independently moving part.
Also, some guidance in Java on ByteArray would be useful on when to use it e.g., enumerating the cases such as early execution of the JVM etc.
-------------
PR Review: https://git.openjdk.org/jdk/pull/23478#pullrequestreview-2598852813
More information about the core-libs-dev
mailing list