Review Request: JDK-8193159: Reduce the number of classes loaded due to NativeLibrary

Martin Buchholz martinrb at google.com
Thu Dec 7 02:08:49 UTC 2017


Google decided that LinkedList is almost never the best choice, so any use
of LinkedList is discouraged.

ArrayDeque's backing array never shrinks, so you might want to give it an
explicit initial size.

On Wed, Dec 6, 2017 at 4:33 PM, mandy chung <mandy.chung at oracle.com> wrote:

> A tiny startup fix - useArrayDeque instead of LinkedList for
> ClassLoader.NativeLibrary which is typically loaded at startup for example
> when loading a JAR file.
>
> Thanks
> Mandy
>
> diff --git a/src/java.base/share/classes/java/lang/ClassLoader.java
> b/src/java.base/share/classes/java/lang/ClassLoader.java
> --- a/src/java.base/share/classes/java/lang/ClassLoader.java
> +++ b/src/java.base/share/classes/java/lang/ClassLoader.java
> @@ -38,6 +38,7 @@
>  import java.security.PrivilegedAction;
>  import java.security.ProtectionDomain;
>  import java.security.cert.Certificate;
> +import java.util.ArrayDeque;
>  import java.util.Arrays;
>  import java.util.Collections;
>  import java.util.Deque;
> @@ -45,7 +46,6 @@
>  import java.util.HashMap;
>  import java.util.HashSet;
>  import java.util.Hashtable;
> -import java.util.LinkedList;
>  import java.util.Map;
>  import java.util.NoSuchElementException;
>  import java.util.Objects;
> @@ -2496,7 +2496,7 @@
>          }
>
>          // native libraries being loaded
> -        static Deque<NativeLibrary> nativeLibraryContext = new
> LinkedList<>();
> +        static Deque<NativeLibrary> nativeLibraryContext = new
> ArrayDeque<>();
>
>          /*
>           * The run() method will be invoked when this class loader becomes
>


More information about the core-libs-dev mailing list