RFR: 8310843: Reimplement ByteArray and ByteArrayLittleEndian with Unsafe

Chen Liang liach at openjdk.org
Sat Jun 24 09:16:16 UTC 2023


On Sat, 24 Jun 2023 06:42:18 GMT, Glavo <duke at openjdk.org> wrote:

> `ByteArray` and `ByteArrayLittleEndian` are very useful tool classes that can be used in many places to performance tuning.
> 
> Currently they are implemented by `VarHandle`, so using them may have some impact on startup time.
> 
> This PR reimplements them using `Unsafe`, which reduces the impact on startup time.

Changes requested by liach (Author).

The reimplementation allows parts that invoke package depend on to utilize faster byte array access, namely bytecode generation and Classfile API; which IMO is more important than the reduction on startup time.

Created an issue at https://bugs.openjdk.org/browse/JDK-8310843.
I look forward to this improvement, for it can potentially be used by the Classfile API to speed up Classfile parsing and writing.

src/java.base/share/classes/jdk/internal/util/ByteArray.java line 47:

> 45: 
> 46:     private static final BiFunction<String, List<Number>, ArrayIndexOutOfBoundsException>
> 47:             OOBEF = Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new);

Can't this be replaced by `Preconditions.AIOBBE_FORMATTER`? And this lambda expression prevents this class to be used before java.lang.invoke initialization.

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

PR Review: https://git.openjdk.org/jdk/pull/14636#pullrequestreview-1496433457
PR Comment: https://git.openjdk.org/jdk/pull/14636#issuecomment-1605319678
PR Comment: https://git.openjdk.org/jdk/pull/14636#issuecomment-1605325374
PR Review Comment: https://git.openjdk.org/jdk/pull/14636#discussion_r1240649846


More information about the core-libs-dev mailing list