Re: <i18n dev> RFR: 8263561: Re-examine uses of LinkedList

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: <i18n dev> RFR: 8263561: Re-examine uses of LinkedList

Yi Yang
On Fri, 26 Feb 2021 10:48:33 GMT, Сергей Цыпанов <[hidden email]> wrote:

> The usage of `LinkedList` is senseless and can be replaced with either `ArrayList` or `ArrayDeque` which are both more compact and effective.
>
> jdk:tier1 and jdk:tier2 are both ok

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java line 220:

> 218:             return Collections.emptyList();
> 219:         }
> 220:         List<IOException> result = new ArrayList<>();

We'd better be cautious about this replacement since its [caller](https://github.com/openjdk/jdk/blob/73029fe10a8a814a8c5f5221f2e667fd14a5b379/src/java.base/share/classes/java/net/URLClassLoader.java#L363) will remove the first element of this array, that's one of the scenarios where LinkedList usually has better performance than ArrayList.

Just IMHO, I suggest replacing them only if there is a performance improvement(e.g. benchmark reports). Changing field types will break users' existing application code, they might reflectively modify these values.

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

PR: https://git.openjdk.java.net/jdk/pull/2744
Reply | Threaded
Open this post in threaded view
|

Re: <i18n dev> RFR: 8263561: Re-examine uses of LinkedList

Сергей Цыпанов-2
On Mon, 15 Mar 2021 06:56:00 GMT, Alan Bateman <[hidden email]> wrote:

>> Nothing outside of the JDK should be hacking into this private field of a non-exposed class, this should not be a concern here.
>
>> @AlanBateman so is it ok to keep `ArrayLists`?
>
> One thing to look out for is usages of 2-arg add method that inserts at a specific position. This shouldn't be a concern in URLClassPath.closeLoaders (assuming this is this usage where the question arises).

@AlanBateman looks like `List.add(o, i)` is not used at all in scope of these changes.

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

PR: https://git.openjdk.java.net/jdk/pull/2744