author | mchung |
Mon, 10 Oct 2016 15:46:14 -0700 | |
changeset 41414 | 7fd4548e9733 |
parent 41114 | f83e9aebbab4 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
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; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
29 |
import java.io.PrintStream; |
36511 | 30 |
import java.lang.module.Configuration; |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
31 |
import java.lang.module.ModuleDescriptor; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
32 |
import java.lang.module.ModuleFinder; |
36511 | 33 |
import java.lang.module.ModuleReference; |
34 |
import java.lang.module.ResolvedModule; |
|
35 |
import java.lang.reflect.Layer; |
|
36 |
import java.lang.reflect.Module; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
37 |
import java.net.URI; |
36511 | 38 |
import java.nio.file.Path; |
39 |
import java.nio.file.Paths; |
|
40 |
import java.util.Collections; |
|
41 |
import java.util.HashMap; |
|
42 |
import java.util.HashSet; |
|
43 |
import java.util.Map; |
|
44 |
import java.util.Optional; |
|
45 |
import java.util.Set; |
|
46 |
import java.util.function.Function; |
|
47 |
||
48 |
import jdk.internal.loader.BootLoader; |
|
49 |
import jdk.internal.loader.BuiltinClassLoader; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
50 |
import jdk.internal.misc.SharedSecrets; |
36511 | 51 |
import jdk.internal.perf.PerfCounter; |
52 |
||
53 |
/** |
|
54 |
* Initializes/boots the module system. |
|
55 |
* |
|
56 |
* The {@link #boot() boot} method is called early in the startup to initialize |
|
57 |
* the module system. In summary, the boot method creates a Configuration by |
|
58 |
* resolving a set of module names specified via the launcher (or equivalent) |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
59 |
* -m and --add-modules options. The modules are located on a module path that |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
60 |
* is constructed from the upgrade module path, system modules, and application |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
61 |
* module path. The Configuration is instantiated as the boot Layer with each |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
62 |
* module in the the configuration defined to one of the built-in class loaders. |
36511 | 63 |
*/ |
64 |
||
65 |
public final class ModuleBootstrap { |
|
66 |
private ModuleBootstrap() { } |
|
67 |
||
68 |
private static final String JAVA_BASE = "java.base"; |
|
69 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
70 |
private static final String JAVA_SE = "java.se"; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
71 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
72 |
// the token for "all default modules" |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
73 |
private static final String ALL_DEFAULT = "ALL-DEFAULT"; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
74 |
|
36511 | 75 |
// the token for "all unnamed modules" |
76 |
private static final String ALL_UNNAMED = "ALL-UNNAMED"; |
|
77 |
||
78 |
// the token for "all system modules" |
|
79 |
private static final String ALL_SYSTEM = "ALL-SYSTEM"; |
|
80 |
||
81 |
// the token for "all modules on the module path" |
|
82 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
|
83 |
||
84 |
// ModuleFinder for the initial configuration |
|
85 |
private static ModuleFinder initialFinder; |
|
86 |
||
87 |
/** |
|
88 |
* Returns the ModuleFinder for the initial configuration |
|
89 |
*/ |
|
90 |
public static ModuleFinder finder() { |
|
91 |
assert initialFinder != null; |
|
92 |
return initialFinder; |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Initialize the module system, returning the boot Layer. |
|
97 |
* |
|
98 |
* @see java.lang.System#initPhase2() |
|
99 |
*/ |
|
100 |
public static Layer boot() { |
|
101 |
||
102 |
long t0 = System.nanoTime(); |
|
103 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
104 |
// system modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
105 |
ModuleFinder systemModules = ModuleFinder.ofSystem(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
106 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
107 |
PerfCounters.systemModulesTime.addElapsedTimeFrom(t0); |
36511 | 108 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
109 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
110 |
long t1 = System.nanoTime(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
111 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
112 |
// Once we have the system modules then we define the base module to |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
113 |
// the VM. We do this here so that java.base is defined as early as |
36511 | 114 |
// possible and also that resources in the base module can be located |
115 |
// for error messages that may happen from here on. |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
116 |
ModuleReference base = systemModules.find(JAVA_BASE).orElse(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
117 |
if (base == null) |
36511 | 118 |
throw new InternalError(JAVA_BASE + " not found"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
119 |
URI baseUri = base.location().orElse(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
120 |
if (baseUri == null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
121 |
throw new InternalError(JAVA_BASE + " does not have a location"); |
36511 | 122 |
BootLoader.loadModule(base); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
123 |
Modules.defineModule(null, base.descriptor(), baseUri); |
36511 | 124 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
125 |
PerfCounters.defineBaseTime.addElapsedTimeFrom(t1); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
126 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
127 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
128 |
long t2 = System.nanoTime(); |
36511 | 129 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
130 |
// --upgrade-module-path option specified to launcher |
36511 | 131 |
ModuleFinder upgradeModulePath |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
132 |
= createModulePathFinder("jdk.module.upgrade.path"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
133 |
if (upgradeModulePath != null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
134 |
systemModules = ModuleFinder.compose(upgradeModulePath, systemModules); |
36511 | 135 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
136 |
// --module-path option specified to the launcher |
36511 | 137 |
ModuleFinder appModulePath = createModulePathFinder("jdk.module.path"); |
138 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
139 |
// The module finder: [--upgrade-module-path] system [--module-path] |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
140 |
ModuleFinder finder = systemModules; |
36511 | 141 |
if (appModulePath != null) |
142 |
finder = ModuleFinder.compose(finder, appModulePath); |
|
143 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
144 |
// The root modules to resolve |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
145 |
Set<String> roots = new HashSet<>(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
146 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
147 |
// launcher -m option to specify the main/initial module |
36511 | 148 |
String mainModule = System.getProperty("jdk.module.main"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
149 |
if (mainModule != null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
150 |
roots.add(mainModule); |
36511 | 151 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
152 |
// additional module(s) specified by --add-modules |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
153 |
boolean addAllDefaultModules = false; |
36511 | 154 |
boolean addAllSystemModules = false; |
155 |
boolean addAllApplicationModules = false; |
|
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
156 |
for (String mod: getExtraAddModules()) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
157 |
switch (mod) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
158 |
case ALL_DEFAULT: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
159 |
addAllDefaultModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
160 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
161 |
case ALL_SYSTEM: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
162 |
addAllSystemModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
163 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
164 |
case ALL_MODULE_PATH: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
165 |
addAllApplicationModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
166 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
167 |
default : |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
168 |
roots.add(mod); |
36511 | 169 |
} |
170 |
} |
|
171 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
172 |
// --limit-modules |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
173 |
String propValue = getAndRemoveProperty("jdk.module.limitmods"); |
36511 | 174 |
if (propValue != null) { |
175 |
Set<String> mods = new HashSet<>(); |
|
176 |
for (String mod: propValue.split(",")) { |
|
177 |
mods.add(mod); |
|
178 |
} |
|
179 |
finder = limitFinder(finder, mods, roots); |
|
180 |
} |
|
181 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
182 |
// If there is no initial module specified then assume that the initial |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
183 |
// module is the unnamed module of the application class loader. This |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
184 |
// is implemented by resolving "java.se" and all (non-java.*) modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
185 |
// that export an API. If "java.se" is not observable then all java.* |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
186 |
// modules are resolved. |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
187 |
if (mainModule == null || addAllDefaultModules) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
188 |
boolean hasJava = false; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
189 |
if (systemModules.find(JAVA_SE).isPresent()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
190 |
// java.se is a system module |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
191 |
if (finder == systemModules || finder.find(JAVA_SE).isPresent()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
192 |
// java.se is observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
193 |
hasJava = true; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
194 |
roots.add(JAVA_SE); |
36511 | 195 |
} |
196 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
197 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
198 |
for (ModuleReference mref : systemModules.findAll()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
199 |
String mn = mref.descriptor().name(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
200 |
if (hasJava && mn.startsWith("java.")) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
201 |
continue; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
202 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
203 |
// add as root if observable and exports at least one package |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
204 |
if ((finder == systemModules || finder.find(mn).isPresent())) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
205 |
ModuleDescriptor descriptor = mref.descriptor(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
206 |
for (ModuleDescriptor.Exports e : descriptor.exports()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
207 |
if (!e.isQualified()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
208 |
roots.add(mn); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
209 |
break; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
210 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
211 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
212 |
} |
36511 | 213 |
} |
214 |
} |
|
215 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
216 |
// If `--add-modules ALL-SYSTEM` is specified then all observable system |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
217 |
// modules will be resolved. |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
218 |
if (addAllSystemModules) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
219 |
ModuleFinder f = finder; // observable modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
220 |
systemModules.findAll() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
221 |
.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
222 |
.map(ModuleReference::descriptor) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
223 |
.map(ModuleDescriptor::name) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
224 |
.filter(mn -> f.find(mn).isPresent()) // observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
225 |
.forEach(mn -> roots.add(mn)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
226 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
227 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
228 |
// If `--add-modules ALL-MODULE-PATH` is specified then all observable |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
229 |
// modules on the application module path will be resolved. |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
230 |
if (appModulePath != null && addAllApplicationModules) { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
231 |
ModuleFinder f = finder; // observable modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
232 |
appModulePath.findAll() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
233 |
.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
234 |
.map(ModuleReference::descriptor) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
235 |
.map(ModuleDescriptor::name) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
236 |
.filter(mn -> f.find(mn).isPresent()) // observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
237 |
.forEach(mn -> roots.add(mn)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
238 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
239 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
240 |
PerfCounters.optionsAndRootsTime.addElapsedTimeFrom(t2); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
241 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
242 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
243 |
long t3 = System.nanoTime(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
244 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
245 |
// determine if post resolution checks are needed |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
246 |
boolean needPostResolutionChecks = true; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
247 |
if (baseUri.getScheme().equals("jrt") // toLowerCase not needed here |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
248 |
&& (upgradeModulePath == null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
249 |
&& (appModulePath == null) |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
250 |
&& (!ModulePatcher.isBootLayerPatched())) { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
251 |
needPostResolutionChecks = false; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
252 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
253 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
254 |
PrintStream traceOutput = null; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
255 |
if (Boolean.getBoolean("jdk.launcher.traceResolver")) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
256 |
traceOutput = System.out; |
36511 | 257 |
|
258 |
// run the resolver to create the configuration |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
259 |
Configuration cf = SharedSecrets.getJavaLangModuleAccess() |
36511 | 260 |
.resolveRequiresAndUses(finder, |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
261 |
roots, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
262 |
needPostResolutionChecks, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
263 |
traceOutput); |
36511 | 264 |
|
265 |
// time to create configuration |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
266 |
PerfCounters.resolveTime.addElapsedTimeFrom(t3); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
267 |
|
36511 | 268 |
|
269 |
// mapping of modules to class loaders |
|
270 |
Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf); |
|
271 |
||
272 |
// check that all modules to be mapped to the boot loader will be |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
273 |
// loaded from the runtime image |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
274 |
if (needPostResolutionChecks) { |
36511 | 275 |
for (ResolvedModule resolvedModule : cf.modules()) { |
276 |
ModuleReference mref = resolvedModule.reference(); |
|
277 |
String name = mref.descriptor().name(); |
|
278 |
ClassLoader cl = clf.apply(name); |
|
279 |
if (cl == null) { |
|
280 |
||
281 |
if (upgradeModulePath != null |
|
282 |
&& upgradeModulePath.find(name).isPresent()) |
|
283 |
fail(name + ": cannot be loaded from upgrade module path"); |
|
284 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
285 |
if (!systemModules.find(name).isPresent()) |
36511 | 286 |
fail(name + ": cannot be loaded from application module path"); |
287 |
} |
|
288 |
} |
|
289 |
} |
|
290 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
291 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
292 |
long t4 = System.nanoTime(); |
36511 | 293 |
|
294 |
// define modules to VM/runtime |
|
295 |
Layer bootLayer = Layer.empty().defineModules(cf, clf); |
|
296 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
297 |
PerfCounters.layerCreateTime.addElapsedTimeFrom(t4); |
36511 | 298 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
299 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
300 |
long t5 = System.nanoTime(); |
36511 | 301 |
|
302 |
// define the module to its class loader, except java.base |
|
303 |
for (ResolvedModule resolvedModule : cf.modules()) { |
|
304 |
ModuleReference mref = resolvedModule.reference(); |
|
305 |
String name = mref.descriptor().name(); |
|
306 |
ClassLoader cl = clf.apply(name); |
|
307 |
if (cl == null) { |
|
308 |
if (!name.equals(JAVA_BASE)) BootLoader.loadModule(mref); |
|
309 |
} else { |
|
310 |
((BuiltinClassLoader)cl).loadModule(mref); |
|
311 |
} |
|
312 |
} |
|
313 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
314 |
PerfCounters.loadModulesTime.addElapsedTimeFrom(t5); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
315 |
|
36511 | 316 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
317 |
// --add-reads and --add-exports |
36511 | 318 |
addExtraReads(bootLayer); |
319 |
addExtraExports(bootLayer); |
|
320 |
||
321 |
// total time to initialize |
|
322 |
PerfCounters.bootstrapTime.addElapsedTimeFrom(t0); |
|
323 |
||
324 |
// remember the ModuleFinder |
|
325 |
initialFinder = finder; |
|
326 |
||
327 |
return bootLayer; |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Returns a ModuleFinder that limits observability to the given root |
|
332 |
* modules, their transitive dependences, plus a set of other modules. |
|
333 |
*/ |
|
334 |
private static ModuleFinder limitFinder(ModuleFinder finder, |
|
335 |
Set<String> roots, |
|
336 |
Set<String> otherMods) |
|
337 |
{ |
|
338 |
// resolve all root modules |
|
339 |
Configuration cf = Configuration.empty() |
|
340 |
.resolveRequires(finder, |
|
38457
3d019217e322
8152650: ModuleFinder.compose should accept varargs
alanb
parents:
37779
diff
changeset
|
341 |
ModuleFinder.of(), |
36511 | 342 |
roots); |
343 |
||
344 |
// module name -> reference |
|
345 |
Map<String, ModuleReference> map = new HashMap<>(); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
346 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
347 |
// root modules and their transitive dependences |
36511 | 348 |
cf.modules().stream() |
349 |
.map(ResolvedModule::reference) |
|
350 |
.forEach(mref -> map.put(mref.descriptor().name(), mref)); |
|
351 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
352 |
// additional modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
353 |
otherMods.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
354 |
.map(finder::find) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
355 |
.flatMap(Optional::stream) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
356 |
.forEach(mref -> map.putIfAbsent(mref.descriptor().name(), mref)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
357 |
|
36511 | 358 |
// set of modules that are observable |
359 |
Set<ModuleReference> mrefs = new HashSet<>(map.values()); |
|
360 |
||
361 |
return new ModuleFinder() { |
|
362 |
@Override |
|
363 |
public Optional<ModuleReference> find(String name) { |
|
364 |
return Optional.ofNullable(map.get(name)); |
|
365 |
} |
|
366 |
@Override |
|
367 |
public Set<ModuleReference> findAll() { |
|
368 |
return mrefs; |
|
369 |
} |
|
370 |
}; |
|
371 |
} |
|
372 |
||
373 |
/** |
|
374 |
* Creates a finder from the module path that is the value of the given |
|
375 |
* system property. |
|
376 |
*/ |
|
377 |
private static ModuleFinder createModulePathFinder(String prop) { |
|
378 |
String s = System.getProperty(prop); |
|
379 |
if (s == null) { |
|
380 |
return null; |
|
381 |
} else { |
|
382 |
String[] dirs = s.split(File.pathSeparator); |
|
383 |
Path[] paths = new Path[dirs.length]; |
|
384 |
int i = 0; |
|
385 |
for (String dir: dirs) { |
|
386 |
paths[i++] = Paths.get(dir); |
|
387 |
} |
|
388 |
return ModuleFinder.of(paths); |
|
389 |
} |
|
390 |
} |
|
391 |
||
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
392 |
/** |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
393 |
* Returns the set of module names specified via --add-modules options |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
394 |
* on the command line |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
395 |
*/ |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
396 |
private static Set<String> getExtraAddModules() { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
397 |
String prefix = "jdk.module.addmods."; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
398 |
int index = 0; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
399 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
400 |
// the system property is removed after decoding |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
401 |
String value = getAndRemoveProperty(prefix + index); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
402 |
if (value == null) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
403 |
return Collections.emptySet(); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
404 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
405 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
406 |
Set<String> modules = new HashSet<>(); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
407 |
while (value != null) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
408 |
for (String s : value.split(",")) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
409 |
if (s.length() > 0) modules.add(s); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
410 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
411 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
412 |
index++; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
413 |
value = getAndRemoveProperty(prefix + index); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
414 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
415 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
416 |
return modules; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
417 |
} |
36511 | 418 |
|
419 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
420 |
* Process the --add-reads options to add any additional read edges that |
36511 | 421 |
* are specified on the command-line. |
422 |
*/ |
|
423 |
private static void addExtraReads(Layer bootLayer) { |
|
424 |
||
425 |
// decode the command line options |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
426 |
Map<String, Set<String>> map = decode("jdk.module.addreads."); |
36511 | 427 |
|
428 |
for (Map.Entry<String, Set<String>> e : map.entrySet()) { |
|
429 |
||
430 |
// the key is $MODULE |
|
431 |
String mn = e.getKey(); |
|
432 |
Optional<Module> om = bootLayer.findModule(mn); |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
433 |
if (!om.isPresent()) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
434 |
warn("Unknown module: " + mn); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
435 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
436 |
} |
36511 | 437 |
Module m = om.get(); |
438 |
||
439 |
// the value is the set of other modules (by name) |
|
440 |
for (String name : e.getValue()) { |
|
441 |
if (ALL_UNNAMED.equals(name)) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
442 |
Modules.addReadsAllUnnamed(m); |
36511 | 443 |
} else { |
444 |
om = bootLayer.findModule(name); |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
445 |
if (om.isPresent()) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
446 |
Modules.addReads(m, om.get()); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
447 |
} else { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
448 |
warn("Unknown module: " + name); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
449 |
} |
36511 | 450 |
} |
451 |
||
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
||
457 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
458 |
* Process the --add-exports options to add any additional read edges that |
36511 | 459 |
* are specified on the command-line. |
460 |
*/ |
|
461 |
private static void addExtraExports(Layer bootLayer) { |
|
462 |
||
463 |
// decode the command line options |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
464 |
Map<String, Set<String>> map = decode("jdk.module.addexports."); |
36511 | 465 |
|
466 |
for (Map.Entry<String, Set<String>> e : map.entrySet()) { |
|
467 |
||
468 |
// the key is $MODULE/$PACKAGE |
|
469 |
String key = e.getKey(); |
|
470 |
String[] s = key.split("/"); |
|
471 |
if (s.length != 2) |
|
472 |
fail("Unable to parse: " + key); |
|
473 |
||
474 |
String mn = s[0]; |
|
475 |
String pn = s[1]; |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
476 |
if (mn.isEmpty() || pn.isEmpty()) |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
477 |
fail("Module and package name must be specified:" + key); |
36511 | 478 |
|
479 |
// The exporting module is in the boot layer |
|
480 |
Module m; |
|
481 |
Optional<Module> om = bootLayer.findModule(mn); |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
482 |
if (!om.isPresent()) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
483 |
warn("Unknown module: " + mn); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
484 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
485 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
486 |
|
36511 | 487 |
m = om.get(); |
488 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
489 |
if (!m.getDescriptor().packages().contains(pn)) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
490 |
warn("package " + pn + " not in " + mn); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
491 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
492 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
493 |
|
36511 | 494 |
// the value is the set of modules to export to (by name) |
495 |
for (String name : e.getValue()) { |
|
496 |
boolean allUnnamed = false; |
|
497 |
Module other = null; |
|
498 |
if (ALL_UNNAMED.equals(name)) { |
|
499 |
allUnnamed = true; |
|
500 |
} else { |
|
501 |
om = bootLayer.findModule(name); |
|
502 |
if (om.isPresent()) { |
|
503 |
other = om.get(); |
|
504 |
} else { |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
505 |
warn("Unknown module: " + name); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
506 |
continue; |
36511 | 507 |
} |
508 |
} |
|
509 |
if (allUnnamed) { |
|
510 |
Modules.addExportsToAllUnnamed(m, pn); |
|
511 |
} else { |
|
512 |
Modules.addExports(m, pn, other); |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
} |
|
517 |
||
518 |
||
519 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
520 |
* Decodes the values of --add-reads or --add-exports options |
36511 | 521 |
* |
522 |
* The format of the options is: $KEY=$MODULE(,$MODULE)* |
|
523 |
*/ |
|
524 |
private static Map<String, Set<String>> decode(String prefix) { |
|
525 |
int index = 0; |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
526 |
// the system property is removed after decoding |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
527 |
String value = getAndRemoveProperty(prefix + index); |
36511 | 528 |
if (value == null) |
529 |
return Collections.emptyMap(); |
|
530 |
||
531 |
Map<String, Set<String>> map = new HashMap<>(); |
|
532 |
||
533 |
while (value != null) { |
|
534 |
||
535 |
int pos = value.indexOf('='); |
|
536 |
if (pos == -1) |
|
537 |
fail("Unable to parse: " + value); |
|
538 |
if (pos == 0) |
|
539 |
fail("Missing module name in: " + value); |
|
540 |
||
541 |
// key is <module> or <module>/<package> |
|
542 |
String key = value.substring(0, pos); |
|
543 |
||
544 |
String rhs = value.substring(pos+1); |
|
545 |
if (rhs.isEmpty()) |
|
546 |
fail("Unable to parse: " + value); |
|
547 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
548 |
Set<String> values = map.computeIfAbsent(key, k -> new HashSet<>()); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
549 |
for (String s : rhs.split(",")) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
550 |
if (s.length() > 0) values.add(s); |
36511 | 551 |
} |
552 |
||
553 |
index++; |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
554 |
value = getAndRemoveProperty(prefix + index); |
36511 | 555 |
} |
556 |
||
557 |
return map; |
|
558 |
} |
|
559 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
560 |
/** |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
561 |
* Gets and remove the named system property |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
562 |
*/ |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
563 |
private static String getAndRemoveProperty(String key) { |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
564 |
return (String)System.getProperties().remove(key); |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
565 |
} |
36511 | 566 |
|
567 |
/** |
|
568 |
* Throws a RuntimeException with the given message |
|
569 |
*/ |
|
570 |
static void fail(String m) { |
|
571 |
throw new RuntimeException(m); |
|
572 |
} |
|
573 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
574 |
static void warn(String m) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
575 |
System.err.println("WARNING: " + m); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
576 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
577 |
|
36511 | 578 |
static class PerfCounters { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
579 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
580 |
static PerfCounter systemModulesTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
581 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.systemModulesTime"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
582 |
static PerfCounter defineBaseTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
583 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.defineBaseTime"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
584 |
static PerfCounter optionsAndRootsTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
585 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.optionsAndRootsTime"); |
36511 | 586 |
static PerfCounter resolveTime |
587 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.resolveTime"); |
|
588 |
static PerfCounter layerCreateTime |
|
589 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.layerCreateTime"); |
|
590 |
static PerfCounter loadModulesTime |
|
591 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.loadModulesTime"); |
|
592 |
static PerfCounter bootstrapTime |
|
593 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.totalTime"); |
|
594 |
} |
|
595 |
} |