RFR: 8376406: Avoid loading ArrayDeque in jdk.internal.loader.NativeLibraries [v2]

Alan Bateman alanb at openjdk.org
Sat Feb 21 08:44:10 UTC 2026


On Fri, 20 Feb 2026 13:22:40 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

>> 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.
>
>> The `ArrayDeque()` constructor takes the number of "elements" whereas `ArrayList()` constructor takes the initial capacity. 
> 
> They both seem to allocate Object arrays to fit elements. ArrayList makes an array for 8 objects, ArrayDeque 8 + 1.
> 
>> Having said that, I can't see why this `8` was used in the first place. 
> 
> 
>> If we are going to change this to an ArrayList, maybe we should just change this to new ArrayList<>().
> 
> Sounds reasonable, that would allow `isEmpty()` checks on an empty list to avoid allocation. If that matters.

> It would be good to hear from Alan @AlanBateman about this proposed change.

It looks okay but fragile in the sense that ArrayDeque is widely used, it's just a question on when rather if it will be loaded. With going work on AOT and in Leyden then I hope we can be less concerned about doing these kinds of changes.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29432#discussion_r2835988721


More information about the core-libs-dev mailing list