42 * loaders. It also creates the class loader that is used to locate resources
43 * in modules defined to the boot class loader.
44 */
45
46 public class ClassLoaders {
47
48 private ClassLoaders() { }
49
50 private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
51
52 // the built-in class loaders
53 private static final BootClassLoader BOOT_LOADER;
54 private static final PlatformClassLoader PLATFORM_LOADER;
55 private static final AppClassLoader APP_LOADER;
56
57 // Creates the built-in class loaders.
58 static {
59 // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
60 String append = VM.getSavedProperty("jdk.boot.class.path.append");
61 BOOT_LOADER =
62 new BootClassLoader((append != null && append.length() > 0)
63 ? new URLClassPath(append, true)
64 : null);
65 PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
66
67 // A class path is required when no initial module is specified.
68 // In this case the class path defaults to "", meaning the current
69 // working directory. When an initial module is specified, on the
70 // contrary, we drop this historic interpretation of the empty
71 // string and instead treat it as unspecified.
72 String cp = System.getProperty("java.class.path");
73 if (cp == null || cp.length() == 0) {
74 String initialModuleName = System.getProperty("jdk.module.main");
75 cp = (initialModuleName == null) ? "" : null;
76 }
77 URLClassPath ucp = new URLClassPath(cp, false);
78 APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
79 }
80
81 /**
82 * Returns the class loader that is used to find resources in modules
83 * defined to the boot class loader.
84 *
85 * @apiNote This method is not public, it should instead be used via
86 * the BootLoader class that provides a restricted API to this class
87 * loader.
88 */
89 static BuiltinClassLoader bootLoader() {
90 return BOOT_LOADER;
91 }
92
93 /**
|
42 * loaders. It also creates the class loader that is used to locate resources
43 * in modules defined to the boot class loader.
44 */
45
46 public class ClassLoaders {
47
48 private ClassLoaders() { }
49
50 private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
51
52 // the built-in class loaders
53 private static final BootClassLoader BOOT_LOADER;
54 private static final PlatformClassLoader PLATFORM_LOADER;
55 private static final AppClassLoader APP_LOADER;
56
57 // Creates the built-in class loaders.
58 static {
59 // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
60 String append = VM.getSavedProperty("jdk.boot.class.path.append");
61 BOOT_LOADER =
62 new BootClassLoader((append != null && !append.isEmpty())
63 ? new URLClassPath(append, true)
64 : null);
65 PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
66
67 // A class path is required when no initial module is specified.
68 // In this case the class path defaults to "", meaning the current
69 // working directory. When an initial module is specified, on the
70 // contrary, we drop this historic interpretation of the empty
71 // string and instead treat it as unspecified.
72 String cp = System.getProperty("java.class.path");
73 if (cp == null || cp.isEmpty()) {
74 String initialModuleName = System.getProperty("jdk.module.main");
75 cp = (initialModuleName == null) ? "" : null;
76 }
77 URLClassPath ucp = new URLClassPath(cp, false);
78 APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
79 }
80
81 /**
82 * Returns the class loader that is used to find resources in modules
83 * defined to the boot class loader.
84 *
85 * @apiNote This method is not public, it should instead be used via
86 * the BootLoader class that provides a restricted API to this class
87 * loader.
88 */
89 static BuiltinClassLoader bootLoader() {
90 return BOOT_LOADER;
91 }
92
93 /**
|