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