17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.internal.module;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.lang.module.Configuration;
31 import java.lang.module.ModuleDescriptor;
32 import java.lang.module.ModuleFinder;
33 import java.lang.module.ModuleReference;
34 import java.lang.module.ResolvedModule;
35 import java.net.URI;
36 import java.nio.file.Path;
37 import java.util.ArrayList;
38 import java.util.Collections;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.Iterator;
42 import java.util.LinkedHashMap;
43 import java.util.List;
44 import java.util.Map;
45 import java.util.NoSuchElementException;
46 import java.util.Objects;
47 import java.util.Optional;
48 import java.util.Set;
49 import java.util.function.Function;
50 import java.util.stream.Collectors;
51
52 import jdk.internal.loader.BootLoader;
53 import jdk.internal.loader.BuiltinClassLoader;
54 import jdk.internal.misc.JavaLangAccess;
55 import jdk.internal.misc.JavaLangModuleAccess;
56 import jdk.internal.misc.SharedSecrets;
57 import jdk.internal.misc.VM;
58 import jdk.internal.perf.PerfCounter;
59
60 /**
61 * Initializes/boots the module system.
62 *
63 * The {@link #boot() boot} method is called early in the startup to initialize
64 * the module system. In summary, the boot method creates a Configuration by
65 * resolving a set of module names specified via the launcher (or equivalent)
66 * -m and --add-modules options. The modules are located on a module path that
67 * is constructed from the upgrade module path, system modules, and application
68 * module path. The Configuration is instantiated as the boot layer with each
69 * module in the configuration defined to a class loader.
70 */
71
72 public final class ModuleBootstrap {
73 private ModuleBootstrap() { }
74
75 private static final String JAVA_BASE = "java.base";
76
77 // the token for "all default modules"
526 @Override
527 public Optional<ModuleReference> find(String name) {
528 return Optional.ofNullable(map.get(name));
529 }
530 @Override
531 public Set<ModuleReference> findAll() {
532 return mrefs;
533 }
534 };
535 }
536
537 /**
538 * Creates a finder from the module path that is the value of the given
539 * system property and optionally patched by --patch-module
540 */
541 private static ModuleFinder finderFor(String prop) {
542 String s = System.getProperty(prop);
543 if (s == null) {
544 return null;
545 } else {
546 String[] dirs = s.split(File.pathSeparator);
547 Path[] paths = new Path[dirs.length];
548 int i = 0;
549 for (String dir: dirs) {
550 paths[i++] = Path.of(dir);
551 }
552 return ModulePath.of(patcher, paths);
553 }
554 }
555
556 /**
557 * Initialize the module patcher for the initial configuration passed on the
558 * value of the --patch-module options.
559 */
560 private static ModulePatcher initModulePatcher() {
561 Map<String, List<String>> map = decode("jdk.module.patch.",
562 File.pathSeparator,
563 false);
564 return new ModulePatcher(map);
565 }
566
567 /**
568 * Returns the set of module names specified by --add-module options.
569 */
570 private static Set<String> addModules() {
571 String prefix = "jdk.module.addmods.";
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.internal.module;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.lang.module.Configuration;
31 import java.lang.module.ModuleDescriptor;
32 import java.lang.module.ModuleFinder;
33 import java.lang.module.ModuleReference;
34 import java.lang.module.ResolvedModule;
35 import java.net.URI;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.HashSet;
42 import java.util.Iterator;
43 import java.util.LinkedHashMap;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.NoSuchElementException;
47 import java.util.Objects;
48 import java.util.Optional;
49 import java.util.Set;
50 import java.util.function.Function;
51 import java.util.stream.Collectors;
52
53 import jdk.internal.loader.BootLoader;
54 import jdk.internal.loader.BuiltinClassLoader;
55 import jdk.internal.misc.JavaLangAccess;
56 import jdk.internal.misc.JavaLangModuleAccess;
57 import jdk.internal.misc.SharedSecrets;
58 import jdk.internal.perf.PerfCounter;
59
60 /**
61 * Initializes/boots the module system.
62 *
63 * The {@link #boot() boot} method is called early in the startup to initialize
64 * the module system. In summary, the boot method creates a Configuration by
65 * resolving a set of module names specified via the launcher (or equivalent)
66 * -m and --add-modules options. The modules are located on a module path that
67 * is constructed from the upgrade module path, system modules, and application
68 * module path. The Configuration is instantiated as the boot layer with each
69 * module in the configuration defined to a class loader.
70 */
71
72 public final class ModuleBootstrap {
73 private ModuleBootstrap() { }
74
75 private static final String JAVA_BASE = "java.base";
76
77 // the token for "all default modules"
526 @Override
527 public Optional<ModuleReference> find(String name) {
528 return Optional.ofNullable(map.get(name));
529 }
530 @Override
531 public Set<ModuleReference> findAll() {
532 return mrefs;
533 }
534 };
535 }
536
537 /**
538 * Creates a finder from the module path that is the value of the given
539 * system property and optionally patched by --patch-module
540 */
541 private static ModuleFinder finderFor(String prop) {
542 String s = System.getProperty(prop);
543 if (s == null) {
544 return null;
545 } else {
546 Path[] paths = Paths.pathToStrings(s).stream()
547 .map(Path::of)
548 .toArray(Path[]::new);
549 return ModulePath.of(patcher, paths);
550 }
551 }
552
553 /**
554 * Initialize the module patcher for the initial configuration passed on the
555 * value of the --patch-module options.
556 */
557 private static ModulePatcher initModulePatcher() {
558 Map<String, List<String>> map = decode("jdk.module.patch.",
559 File.pathSeparator,
560 false);
561 return new ModulePatcher(map);
562 }
563
564 /**
565 * Returns the set of module names specified by --add-module options.
566 */
567 private static Set<String> addModules() {
568 String prefix = "jdk.module.addmods.";
|