< prev index next >

src/java.base/share/classes/jdk/internal/loader/BootLoader.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.internal.loader;
  26 
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.lang.module.ModuleReference;
  30 import java.lang.reflect.Layer;
  31 import java.lang.reflect.Module;
  32 import java.net.MalformedURLException;
  33 import java.net.URL;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 import java.util.Arrays;
  40 import java.util.Enumeration;
  41 import java.util.Optional;

  42 import java.util.jar.JarInputStream;
  43 import java.util.jar.Manifest;
  44 import java.util.stream.Stream;
  45 
  46 import jdk.internal.misc.JavaLangAccess;
  47 import jdk.internal.misc.SharedSecrets;
  48 import jdk.internal.module.ServicesCatalog;
  49 
  50 /**
  51  * Find resources and packages in modules defined to the boot class loader or
  52  * resources and packages on the "boot class path" specified via -Xbootclasspath/a.
  53  */
  54 
  55 public class BootLoader {
  56     private BootLoader() { }
  57 
  58     // The unnamed module for the boot loader
  59     private static final Module UNNAMED_MODULE;
  60     private static final String JAVA_HOME = System.getProperty("java.home");
  61 
  62     static {
  63         UNNAMED_MODULE
  64             = SharedSecrets.getJavaLangReflectModuleAccess().defineUnnamedModule(null);
  65         setBootLoaderUnnamedModule0(UNNAMED_MODULE);
  66     }
  67 
  68     // ServiceCatalog for the boot class loader
  69     private static final ServicesCatalog SERVICES_CATALOG = new ServicesCatalog();
  70 




  71     /**
  72      * Returns the unnamed module for the boot loader.
  73      */
  74     public static Module getUnnamedModule() {
  75         return UNNAMED_MODULE;
  76     }
  77 
  78     /**
  79      * Returns the ServiceCatalog for modules defined to the boot class loader.
  80      */
  81     public static ServicesCatalog getServicesCatalog() {
  82         return SERVICES_CATALOG;







  83     }
  84 
  85     /**
  86      * Register a module with this class loader so that its classes (and
  87      * resources) become visible via this class loader.
  88      */
  89     public static void loadModule(ModuleReference mref) {
  90         ClassLoaders.bootLoader().loadModule(mref);
  91     }
  92 
  93     /**
  94      * Loads the Class object with the given name defined to the boot loader.
  95      */
  96     public static Class<?> loadClassOrNull(String name) {
  97         return ClassLoaders.bootLoader().loadClassOrNull(name);
  98     }
  99 
 100     /**
 101      * Returns a URL to a resource in a named module defined to the boot loader.
 102      */




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.internal.loader;
  26 
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.lang.module.ModuleReference;
  30 import java.lang.reflect.Layer;
  31 import java.lang.reflect.Module;
  32 import java.net.MalformedURLException;
  33 import java.net.URL;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 import java.util.Arrays;
  40 import java.util.Enumeration;
  41 import java.util.Optional;
  42 import java.util.concurrent.ConcurrentHashMap;
  43 import java.util.jar.JarInputStream;
  44 import java.util.jar.Manifest;
  45 import java.util.stream.Stream;
  46 
  47 import jdk.internal.misc.JavaLangAccess;
  48 import jdk.internal.misc.SharedSecrets;
  49 import jdk.internal.module.ServicesCatalog;
  50 
  51 /**
  52  * Find resources and packages in modules defined to the boot class loader or
  53  * resources and packages on the "boot class path" specified via -Xbootclasspath/a.
  54  */
  55 
  56 public class BootLoader {
  57     private BootLoader() { }
  58 
  59     // The unnamed module for the boot loader
  60     private static final Module UNNAMED_MODULE;
  61     private static final String JAVA_HOME = System.getProperty("java.home");
  62 
  63     static {
  64         UNNAMED_MODULE
  65             = SharedSecrets.getJavaLangReflectModuleAccess().defineUnnamedModule(null);
  66         setBootLoaderUnnamedModule0(UNNAMED_MODULE);
  67     }
  68 
  69     // ServiceCatalog for the boot class loader
  70     private static final ServicesCatalog SERVICES_CATALOG = new ServicesCatalog();
  71 
  72     // ClassLoaderValue map for boot class loader
  73     private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP =
  74         new ConcurrentHashMap<>();
  75 
  76     /**
  77      * Returns the unnamed module for the boot loader.
  78      */
  79     public static Module getUnnamedModule() {
  80         return UNNAMED_MODULE;
  81     }
  82 
  83     /**
  84      * Returns the ServiceCatalog for modules defined to the boot class loader.
  85      */
  86     public static ServicesCatalog getServicesCatalog() {
  87         return SERVICES_CATALOG;
  88     }
  89 
  90     /**
  91      * Returns the ClassLoaderValue map for the boot class loader.
  92      */
  93     public static ConcurrentHashMap<?, ?> getClassLoaderValueMap() {
  94         return CLASS_LOADER_VALUE_MAP;
  95     }
  96 
  97     /**
  98      * Register a module with this class loader so that its classes (and
  99      * resources) become visible via this class loader.
 100      */
 101     public static void loadModule(ModuleReference mref) {
 102         ClassLoaders.bootLoader().loadModule(mref);
 103     }
 104 
 105     /**
 106      * Loads the Class object with the given name defined to the boot loader.
 107      */
 108     public static Class<?> loadClassOrNull(String name) {
 109         return ClassLoaders.bootLoader().loadClassOrNull(name);
 110     }
 111 
 112     /**
 113      * Returns a URL to a resource in a named module defined to the boot loader.
 114      */


< prev index next >