79 */ 80 public static Module getUnnamedModule() { 81 return UNNAMED_MODULE; 82 } 83 84 /** 85 * Returns the ServiceCatalog for modules defined to the boot class loader. 86 */ 87 public static ServicesCatalog getServicesCatalog() { 88 return SERVICES_CATALOG; 89 } 90 91 /** 92 * Returns the ClassLoaderValue map for the boot class loader. 93 */ 94 public static ConcurrentHashMap<?, ?> getClassLoaderValueMap() { 95 return CLASS_LOADER_VALUE_MAP; 96 } 97 98 /** 99 * Register a module with this class loader so that its classes (and 100 * resources) become visible via this class loader. 101 */ 102 public static void loadModule(ModuleReference mref) { 103 ClassLoaders.bootLoader().loadModule(mref); 104 } 105 106 /** 107 * Loads the Class object with the given name defined to the boot loader. 108 */ 109 public static Class<?> loadClassOrNull(String name) { 110 return ClassLoaders.bootLoader().loadClassOrNull(name); 111 } 112 113 /** 114 * Loads the Class object with the given name in the given module 115 * defined to the boot loader. Returns {@code null} if not found. 116 */ 117 public static Class<?> loadClass(Module module, String name) { 118 Class<?> c = loadClassOrNull(name); 171 public static Package getDefinedPackage(String pn) { 172 Package pkg = ClassLoaders.bootLoader().getDefinedPackage(pn); 173 if (pkg == null) { 174 String location = getSystemPackageLocation(pn.replace('.', '/')); 175 if (location != null) { 176 pkg = PackageHelper.definePackage(pn.intern(), location); 177 } 178 } 179 return pkg; 180 } 181 182 /** 183 * Returns a stream of the packages defined to the boot loader. 184 */ 185 public static Stream<Package> packages() { 186 return Arrays.stream(getSystemPackageNames()) 187 .map(name -> getDefinedPackage(name.replace('/', '.'))); 188 } 189 190 /** 191 * Returns {@code true} if there is a class path associated with the 192 * BootLoader. 193 */ 194 public static boolean hasClassPath() { 195 return ClassLoaders.bootLoader().hasClassPath(); 196 } 197 198 /** 199 * Helper class to define {@code Package} objects for packages in modules 200 * defined to the boot loader. 201 */ 202 static class PackageHelper { 203 private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); 204 205 /** 206 * Define the {@code Package} with the given name. The specified 207 * location is a jrt URL to a named module in the run-time image, 208 * a file URL to a module in an exploded run-time image, or a file 209 * path to an entry on the boot class path (java agent Boot-Class-Path 210 * or -Xbootclasspath/a. 211 * 212 * <p> If the given location is a JAR file containing a manifest, 213 * the defined Package contains the versioning information from 214 * the manifest, if present. 215 * 216 * @param name package name 217 * @param location location where the package is (jrt URL or file URL 218 * for a named module in the run-time or exploded image; | 79 */ 80 public static Module getUnnamedModule() { 81 return UNNAMED_MODULE; 82 } 83 84 /** 85 * Returns the ServiceCatalog for modules defined to the boot class loader. 86 */ 87 public static ServicesCatalog getServicesCatalog() { 88 return SERVICES_CATALOG; 89 } 90 91 /** 92 * Returns the ClassLoaderValue map for the boot class loader. 93 */ 94 public static ConcurrentHashMap<?, ?> getClassLoaderValueMap() { 95 return CLASS_LOADER_VALUE_MAP; 96 } 97 98 /** 99 * Returns {@code true} if there is a class path associated with the 100 * BootLoader. 101 */ 102 public static boolean hasClassPath() { 103 return ClassLoaders.bootLoader().hasClassPath(); 104 } 105 106 /** 107 * Register a module with this class loader so that its classes (and 108 * resources) become visible via this class loader. 109 */ 110 public static void loadModule(ModuleReference mref) { 111 ClassLoaders.bootLoader().loadModule(mref); 112 } 113 114 /** 115 * Loads the Class object with the given name defined to the boot loader. 116 */ 117 public static Class<?> loadClassOrNull(String name) { 118 return ClassLoaders.bootLoader().loadClassOrNull(name); 119 } 120 121 /** 122 * Loads the Class object with the given name in the given module 123 * defined to the boot loader. Returns {@code null} if not found. 124 */ 125 public static Class<?> loadClass(Module module, String name) { 126 Class<?> c = loadClassOrNull(name); 179 public static Package getDefinedPackage(String pn) { 180 Package pkg = ClassLoaders.bootLoader().getDefinedPackage(pn); 181 if (pkg == null) { 182 String location = getSystemPackageLocation(pn.replace('.', '/')); 183 if (location != null) { 184 pkg = PackageHelper.definePackage(pn.intern(), location); 185 } 186 } 187 return pkg; 188 } 189 190 /** 191 * Returns a stream of the packages defined to the boot loader. 192 */ 193 public static Stream<Package> packages() { 194 return Arrays.stream(getSystemPackageNames()) 195 .map(name -> getDefinedPackage(name.replace('/', '.'))); 196 } 197 198 /** 199 * Helper class to define {@code Package} objects for packages in modules 200 * defined to the boot loader. 201 */ 202 static class PackageHelper { 203 private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); 204 205 /** 206 * Define the {@code Package} with the given name. The specified 207 * location is a jrt URL to a named module in the run-time image, 208 * a file URL to a module in an exploded run-time image, or a file 209 * path to an entry on the boot class path (java agent Boot-Class-Path 210 * or -Xbootclasspath/a. 211 * 212 * <p> If the given location is a JAR file containing a manifest, 213 * the defined Package contains the versioning information from 214 * the manifest, if present. 215 * 216 * @param name package name 217 * @param location location where the package is (jrt URL or file URL 218 * for a named module in the run-time or exploded image; |