< prev index next >

src/java.base/share/classes/java/net/URLClassLoader.java

Print this page
rev 15833 : 8168073: Speed up URI creation during module bootstrap
Reviewed-by: alanb


  34 import java.security.AccessController;
  35 import java.security.CodeSigner;
  36 import java.security.CodeSource;
  37 import java.security.Permission;
  38 import java.security.PermissionCollection;
  39 import java.security.PrivilegedAction;
  40 import java.security.PrivilegedExceptionAction;
  41 import java.security.SecureClassLoader;
  42 import java.util.Enumeration;
  43 import java.util.List;
  44 import java.util.NoSuchElementException;
  45 import java.util.Set;
  46 import java.util.WeakHashMap;
  47 import java.util.jar.Attributes;
  48 import java.util.jar.Attributes.Name;
  49 import java.util.jar.JarFile;
  50 import java.util.jar.Manifest;
  51 
  52 import jdk.internal.loader.Resource;
  53 import jdk.internal.loader.URLClassPath;
  54 import jdk.internal.misc.JavaNetAccess;
  55 import jdk.internal.misc.SharedSecrets;
  56 import jdk.internal.perf.PerfCounter;
  57 import sun.net.www.ParseUtil;
  58 import sun.security.util.SecurityConstants;
  59 
  60 /**
  61  * This class loader is used to load classes and resources from a search
  62  * path of URLs referring to both JAR files and directories. Any {@code jar:}
  63  * scheme URL (see {@link java.net.JarURLConnection}) is assumed to refer to a
  64  * JAR file.  Any {@code file:} scheme URL that ends with a '/' is assumed to
  65  * refer to a directory. Otherwise, the URL is assumed to refer to a JAR file
  66  * which will be opened as needed.
  67  * <p>
  68  * The AccessControlContext of the thread that created the instance of
  69  * URLClassLoader will be used when subsequently loading classes and
  70  * resources.
  71  * <p>
  72  * The classes that are loaded are by default granted permission only to
  73  * access the URLs specified when the URLClassLoader was created.
  74  *
  75  * @author  David Connelly


 750      * loading the class.
 751      *
 752      * @param urls the URLs to search for classes and resources
 753      * @exception  NullPointerException if {@code urls} is {@code null}.
 754      * @return the resulting class loader
 755      */
 756     public static URLClassLoader newInstance(final URL[] urls) {
 757         // Save the caller's context
 758         final AccessControlContext acc = AccessController.getContext();
 759         // Need a privileged block to create the class loader
 760         URLClassLoader ucl = AccessController.doPrivileged(
 761             new PrivilegedAction<>() {
 762                 public URLClassLoader run() {
 763                     return new FactoryURLClassLoader(urls, acc);
 764                 }
 765             });
 766         return ucl;
 767     }
 768 
 769     static {
 770         SharedSecrets.setJavaNetAccess(
 771             new JavaNetAccess() {
 772                 public URLClassPath getURLClassPath(URLClassLoader u) {
 773                     return u.ucp;
 774                 }
 775             }
 776         );
 777         ClassLoader.registerAsParallelCapable();
 778     }
 779 }
 780 
 781 final class FactoryURLClassLoader extends URLClassLoader {
 782 
 783     static {
 784         ClassLoader.registerAsParallelCapable();
 785     }
 786 
 787     FactoryURLClassLoader(URL[] urls, ClassLoader parent,
 788                           AccessControlContext acc) {
 789         super(urls, parent, acc);
 790     }
 791 
 792     FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
 793         super(urls, acc);
 794     }
 795 
 796     public final Class<?> loadClass(String name, boolean resolve)


  34 import java.security.AccessController;
  35 import java.security.CodeSigner;
  36 import java.security.CodeSource;
  37 import java.security.Permission;
  38 import java.security.PermissionCollection;
  39 import java.security.PrivilegedAction;
  40 import java.security.PrivilegedExceptionAction;
  41 import java.security.SecureClassLoader;
  42 import java.util.Enumeration;
  43 import java.util.List;
  44 import java.util.NoSuchElementException;
  45 import java.util.Set;
  46 import java.util.WeakHashMap;
  47 import java.util.jar.Attributes;
  48 import java.util.jar.Attributes.Name;
  49 import java.util.jar.JarFile;
  50 import java.util.jar.Manifest;
  51 
  52 import jdk.internal.loader.Resource;
  53 import jdk.internal.loader.URLClassPath;


  54 import jdk.internal.perf.PerfCounter;
  55 import sun.net.www.ParseUtil;
  56 import sun.security.util.SecurityConstants;
  57 
  58 /**
  59  * This class loader is used to load classes and resources from a search
  60  * path of URLs referring to both JAR files and directories. Any {@code jar:}
  61  * scheme URL (see {@link java.net.JarURLConnection}) is assumed to refer to a
  62  * JAR file.  Any {@code file:} scheme URL that ends with a '/' is assumed to
  63  * refer to a directory. Otherwise, the URL is assumed to refer to a JAR file
  64  * which will be opened as needed.
  65  * <p>
  66  * The AccessControlContext of the thread that created the instance of
  67  * URLClassLoader will be used when subsequently loading classes and
  68  * resources.
  69  * <p>
  70  * The classes that are loaded are by default granted permission only to
  71  * access the URLs specified when the URLClassLoader was created.
  72  *
  73  * @author  David Connelly


 748      * loading the class.
 749      *
 750      * @param urls the URLs to search for classes and resources
 751      * @exception  NullPointerException if {@code urls} is {@code null}.
 752      * @return the resulting class loader
 753      */
 754     public static URLClassLoader newInstance(final URL[] urls) {
 755         // Save the caller's context
 756         final AccessControlContext acc = AccessController.getContext();
 757         // Need a privileged block to create the class loader
 758         URLClassLoader ucl = AccessController.doPrivileged(
 759             new PrivilegedAction<>() {
 760                 public URLClassLoader run() {
 761                     return new FactoryURLClassLoader(urls, acc);
 762                 }
 763             });
 764         return ucl;
 765     }
 766 
 767     static {







 768         ClassLoader.registerAsParallelCapable();
 769     }
 770 }
 771 
 772 final class FactoryURLClassLoader extends URLClassLoader {
 773 
 774     static {
 775         ClassLoader.registerAsParallelCapable();
 776     }
 777 
 778     FactoryURLClassLoader(URL[] urls, ClassLoader parent,
 779                           AccessControlContext acc) {
 780         super(urls, parent, acc);
 781     }
 782 
 783     FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
 784         super(urls, acc);
 785     }
 786 
 787     public final Class<?> loadClass(String name, boolean resolve)
< prev index next >