RFR: 8376406: Avoid loading ArrayDeque in jdk.internal.loader.NativeLibraries [v2]
Jaikiran Pai
jpai at openjdk.org
Fri Feb 20 13:12:36 UTC 2026
On Mon, 26 Jan 2026 21:16:41 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:
>> Please review this PR which replaces `ArrayDeque` with `ArrayList` for the native library context stack in `jdk.internal.loader.NativeLibraries.NativeLibraryContext`.
>>
>> With this follow-up to similar changes in #29288 and #29430, a simple JAR-based "hello world" program no longer loads the `ArrayDeque` class during startup.
>>
>> The change here is mostly a straightforward replacement. The existing processing was a FIFO stack, which it still is after this PR, just backed by ArrayList instead.
>>
>> Since ArrayList is null-friendly, I added an explicit `Objects.requireNullNull` before pushing to the stack.
>>
>> Pure refactoring, no tests updated, `noreg-cleanup`.
>
> Eirik Bjørsnøs has updated the pull request incrementally with one additional commit since the last revision:
>
> Update copyright year
src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java line 479:
> 477:
> 478: // Maps thread object to the native library context stack, maintained by each thread
> 479: private static Map<Thread, List<NativeLibraryImpl>> nativeLibraryThreadContext =
This field can be made `final`.
src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java line 488:
> 486: new Function<>() {
> 487: public List<NativeLibraryImpl> apply(Thread t) {
> 488: return new ArrayList<>(8);
The `ArrayDeque()` constructor takes the number of "elements" whereas `ArrayList()` constructor takes the initial capacity. Having said that, I can't see why this `8` was used in the first place. It was introduced in https://bugs.openjdk.org/browse/JDK-8228336 and the review thread https://mail.openjdk.org/pipermail/core-libs-dev/2020-March/065194.html doesn't make a mention of it, so this initial number of elements may not be too critical in this code. If we are going to change this to an ArrayList, maybe we should just change this to `new ArrayList<>()`.
It would be good to hear from Alan @AlanBateman about this proposed change.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29432#discussion_r2833133016
PR Review Comment: https://git.openjdk.org/jdk/pull/29432#discussion_r2833122765
More information about the core-libs-dev
mailing list