On Wed, 5 Feb 2025 23:41:19 GMT, Chen Liang <[email protected]> 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.
What about dropping "BE" from all big-endian method names?
This would reduces the number of files to review in `java.io` to 0 (admittedly,
it's a rather mechanical review).
I know this would be less symmetrical, but...
src/java.base/share/classes/jdk/internal/util/ByteArray.java line 53:
> 51:
> 52: public static char getCharBO(byte[] array, int index, boolean big) {
> 53: Preconditions.checkIndex(index, array.length - Character.BYTES +
> 1, Preconditions.AIOOBE_FORMATTER);
Suggestion:
Preconditions.checkIndex(index, array.length - (Character.BYTES - 1),
Preconditions.AIOOBE_FORMATTER);
Similarly for all cases below.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23478#issuecomment-2639657316
PR Review Comment: https://git.openjdk.org/jdk/pull/23478#discussion_r1944571743