< prev index next >
src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java
Print this page
@@ -102,12 +102,11 @@
// parent ClassLoader
private final BuiltinClassLoader parent;
// the URL class path, or null if there is no class path
- private final URLClassPath ucp;
-
+ private @Stable URLClassPath ucp;
/**
* A module defined/loaded by a built-in class loader.
*
* A LoadedModule encapsulates a ModuleReference along with its CodeSource
@@ -154,14 +153,30 @@
}
return url;
}
}
-
// maps package name to loaded module for modules in the boot layer
- private static final Map<String, LoadedModule> packageToModule
- = new ConcurrentHashMap<>(1024);
+ private static final Map<String, LoadedModule> packageToModule;
+ static {
+ ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get();
+ if (archivedClassLoaders != null) {
+ @SuppressWarnings("unchecked")
+ Map<String, LoadedModule> map
+ = (Map<String, LoadedModule>) archivedClassLoaders.packageToModule();
+ packageToModule = map;
+ } else {
+ packageToModule = new ConcurrentHashMap<>(1024);
+ }
+ }
+
+ /**
+ * Invoked by ArchivedClassLoaders to archive the package-to-module map.
+ */
+ static Map<String, ?> packageToModule() {
+ return packageToModule;
+ }
// maps a module name to a module reference
private final Map<String, ModuleReference> nameToModule;
// maps a module reference to a module reader
@@ -184,10 +199,25 @@
this.nameToModule = new ConcurrentHashMap<>(32);
this.moduleToReader = new ConcurrentHashMap<>();
}
/**
+ * Appends to the given file path to the class path.
+ */
+ void appendClassPath(String path) {
+ // assert ucp != null;
+ ucp.addFile(path);
+ }
+
+ /**
+ * Sets the class path, called to reset the class path during -Xshare:dump
+ */
+ void setClassPath(URLClassPath ucp) {
+ this.ucp = ucp;
+ }
+
+ /**
* Returns {@code true} if there is a class path associated with this
* class loader.
*/
boolean hasClassPath() {
return ucp != null;
@@ -1040,6 +1070,11 @@
* checking with java.net.URLClassLoader.
*/
private static URL checkURL(URL url) {
return URLClassPath.checkURL(url);
}
+
+ // Called from VM only, during -Xshare:dump
+ private void resetArchivedStates() {
+ ucp = null;
+ }
}
< prev index next >