RFR: 8310843: Reimplement ByteArray and ByteArrayLittleEndian with Unsafe

Chen Liang liach at openjdk.org
Sat Jun 24 09:23:04 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.

I recommend documenting that this class is intended to be usable at early startup so we don't accidentally introduce features like lambda into the code.

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

> 33:  * using {@linkplain java.nio.ByteOrder#BIG_ENDIAN big endian order} (aka. "network order").
> 34:  * <p>
> 35:  * All methods in this class will throw an {@linkplain NullPointerException} if {@code null} is

Do the Unsafe methods throw NPE on null array argument?

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

> 41:     }
> 42: 
> 43:     static final Unsafe UNSAFE = Unsafe.getUnsafe();

I recommend documenting the reason to use Unsafe (early startup) and comment that regular users should use VarHandle instead.

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

PR Review: https://git.openjdk.org/jdk/pull/14636#pullrequestreview-1496438253
PR Review Comment: https://git.openjdk.org/jdk/pull/14636#discussion_r1240653787
PR Review Comment: https://git.openjdk.org/jdk/pull/14636#discussion_r1240653425


More information about the core-libs-dev mailing list