< prev index next >
src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
Print this page
*** 34,43 ****
--- 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.
*** 52,71 ****
// 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 {
// -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
// contrary, we drop this historic interpretation of the empty
// string and instead treat it as unspecified.
--- 53,101 ----
// 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
// contrary, we drop this historic interpretation of the empty
// string and instead treat it as unspecified.
*** 73,83 ****
--- 103,119 ----
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
* defined to the boot class loader.
*** 142,152 ****
static {
if (!ClassLoader.registerAsParallelCapable())
throw new InternalError();
}
! final URLClassPath ucp;
AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
super("app", parent, ucp);
this.ucp = ucp;
}
--- 178,192 ----
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;
}
*** 188,197 ****
--- 228,242 ----
* 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.
*
< prev index next >