< prev index next >
src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
Print this page
@@ -34,11 +34,11 @@
import java.util.jar.Manifest;
import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.VM;
-import jdk.internal.vm.annotation.Stable;
+import jdk.internal.module.ServicesCatalog;
/**
* Creates and provides access to the built-in platform and application class
* loaders. It also creates the class loader that is used to locate resources
* in modules defined to the boot class loader.
@@ -53,47 +53,26 @@
// the built-in class loaders
private static final BootClassLoader BOOT_LOADER;
private static final PlatformClassLoader PLATFORM_LOADER;
private static final AppClassLoader APP_LOADER;
- static class ArchivedData {
- private final BootClassLoader boot_loader;
- private final PlatformClassLoader platform_loader;
- private final AppClassLoader app_loader;
-
- private ArchivedData() {
- boot_loader = BOOT_LOADER;
- platform_loader = PLATFORM_LOADER;
- app_loader = APP_LOADER;
- }
-
- static void archive() {
- singleton = new ArchivedData();
- }
-
- static ArchivedData get() {
- return singleton;
- }
-
- private static ArchivedData singleton;
- }
-
// Creates the built-in class loaders.
static {
- VM.initializeFromArchive(ArchivedData.class);
- ArchivedData archivedData = ArchivedData.get();
- if (archivedData != null) {
+ ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get();
+ if (archivedClassLoaders != null) {
// assert VM.getSavedProperty("jdk.boot.class.path.append") == null
- BOOT_LOADER = archivedData.boot_loader;
- PLATFORM_LOADER = archivedData.platform_loader;
+ BOOT_LOADER = (BootClassLoader) archivedClassLoaders.bootLoader();
+ PLATFORM_LOADER = (PlatformClassLoader) archivedClassLoaders.platformLoader();
+ ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(PLATFORM_LOADER);
+ ServicesCatalog.putServicesCatalog(PLATFORM_LOADER, catalog);
} else {
// -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
String append = VM.getSavedProperty("jdk.boot.class.path.append");
- BOOT_LOADER =
- new BootClassLoader((append != null && !append.isEmpty())
+ URLClassPath ucp = (append != null && !append.isEmpty())
? new URLClassPath(append, true)
- : null);
+ : null;
+ BOOT_LOADER = new BootClassLoader(ucp);
PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
}
// A class path is required when no initial module is specified.
// In this case the class path defaults to "", meaning the current
// working directory. When an initial module is specified, on the
@@ -103,16 +82,18 @@
if (cp == null || cp.isEmpty()) {
String initialModuleName = System.getProperty("jdk.module.main");
cp = (initialModuleName == null) ? "" : null;
}
URLClassPath ucp = new URLClassPath(cp, false);
- if (archivedData != null) {
- APP_LOADER = archivedData.app_loader;
+ if (archivedClassLoaders != null) {
+ APP_LOADER = (AppClassLoader) archivedClassLoaders.appLoader();
+ ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(APP_LOADER);
+ ServicesCatalog.putServicesCatalog(APP_LOADER, catalog);
APP_LOADER.setClassPath(ucp);
} else {
APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
- ArchivedData.archive();
+ ArchivedClassLoaders.archive();
}
}
/**
* Returns the class loader that is used to find resources in modules
@@ -178,19 +159,12 @@
static {
if (!ClassLoader.registerAsParallelCapable())
throw new InternalError();
}
- @Stable URLClassPath ucp;
- void setClassPath(URLClassPath ucp) {
- super.setClassPath(ucp);
- this.ucp = ucp;
- }
-
- AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
+ AppClassLoader(BuiltinClassLoader parent, URLClassPath ucp) {
super("app", parent, ucp);
- this.ucp = ucp;
}
@Override
protected Class<?> loadClass(String cn, boolean resolve)
throws ClassNotFoundException
@@ -219,23 +193,25 @@
* Called by the VM to support dynamic additions to the class path
*
* @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
*/
void appendToClassPathForInstrumentation(String path) {
- ucp.addFile(path);
+ appendClassPath(path);
}
/**
* Called by the VM to support define package for AppCDS
*/
protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
return super.defineOrCheckPackage(pn, man, url);
}
- // Called from VM only, during -Xshare:dump
+ /**
+ * Called by the VM, during -Xshare:dump
+ */
private void resetArchivedStates() {
- ucp = null;
+ setClassPath(null);
}
}
/**
* Attempts to convert the given string to a file URL.
< prev index next >