< prev index next >
src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
Print this page
*** 34,44 ****
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;
/**
* 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.
--- 34,44 ----
import java.util.jar.Manifest;
import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.VM;
! 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,99 ****
// 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) {
// assert VM.getSavedProperty("jdk.boot.class.path.append") == null
! BOOT_LOADER = archivedData.boot_loader;
! PLATFORM_LOADER = archivedData.platform_loader;
} 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())
? new URLClassPath(append, true)
! : null);
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
--- 53,78 ----
// the built-in class loaders
private static final BootClassLoader BOOT_LOADER;
private static final PlatformClassLoader PLATFORM_LOADER;
private static final AppClassLoader APP_LOADER;
// Creates the built-in class loaders.
static {
! ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get();
! if (archivedClassLoaders != null) {
// assert VM.getSavedProperty("jdk.boot.class.path.append") == null
! 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");
! URLClassPath ucp = (append != null && !append.isEmpty())
? new URLClassPath(append, true)
! : 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,118 ****
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;
APP_LOADER.setClassPath(ucp);
} else {
APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
! ArchivedData.archive();
}
}
/**
* Returns the class loader that is used to find resources in modules
--- 82,99 ----
if (cp == null || cp.isEmpty()) {
String initialModuleName = System.getProperty("jdk.module.main");
cp = (initialModuleName == null) ? "" : null;
}
URLClassPath ucp = new URLClassPath(cp, false);
! 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);
! ArchivedClassLoaders.archive();
}
}
/**
* Returns the class loader that is used to find resources in modules
*** 178,196 ****
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) {
super("app", parent, ucp);
- this.ucp = ucp;
}
@Override
protected Class<?> loadClass(String cn, boolean resolve)
throws ClassNotFoundException
--- 159,170 ----
static {
if (!ClassLoader.registerAsParallelCapable())
throw new InternalError();
}
! AppClassLoader(BuiltinClassLoader parent, URLClassPath ucp) {
super("app", parent, ucp);
}
@Override
protected Class<?> loadClass(String cn, boolean resolve)
throws ClassNotFoundException
*** 219,241 ****
* 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);
}
/**
* 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
private void resetArchivedStates() {
! ucp = null;
}
}
/**
* Attempts to convert the given string to a file URL.
--- 193,217 ----
* Called by the VM to support dynamic additions to the class path
*
* @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
*/
void appendToClassPathForInstrumentation(String 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 by the VM, during -Xshare:dump
! */
private void resetArchivedStates() {
! setClassPath(null);
}
}
/**
* Attempts to convert the given string to a file URL.
< prev index next >