author | alanb |
Fri, 10 Feb 2017 09:04:39 +0000 | |
changeset 43712 | 5dfd0950317c |
parent 42774 | 74bcf37d15d8 |
child 43713 | 2a4f42ec3ceb |
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; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
29 |
import java.io.IOException; |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
30 |
import java.io.PrintStream; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
31 |
import java.io.UncheckedIOException; |
36511 | 32 |
import java.lang.module.Configuration; |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
33 |
import java.lang.module.ModuleDescriptor; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
34 |
import java.lang.module.ModuleFinder; |
36511 | 35 |
import java.lang.module.ModuleReference; |
36 |
import java.lang.module.ResolvedModule; |
|
37 |
import java.lang.reflect.Layer; |
|
38 |
import java.lang.reflect.Module; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
39 |
import java.net.URI; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
40 |
import java.nio.file.Files; |
36511 | 41 |
import java.nio.file.Path; |
42 |
import java.nio.file.Paths; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
43 |
import java.util.ArrayList; |
36511 | 44 |
import java.util.Collections; |
45 |
import java.util.HashMap; |
|
46 |
import java.util.HashSet; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
47 |
import java.util.List; |
36511 | 48 |
import java.util.Map; |
49 |
import java.util.Optional; |
|
50 |
import java.util.Set; |
|
51 |
import java.util.function.Function; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
52 |
import java.util.stream.Stream; |
36511 | 53 |
|
54 |
import jdk.internal.loader.BootLoader; |
|
55 |
import jdk.internal.loader.BuiltinClassLoader; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
56 |
import jdk.internal.misc.SharedSecrets; |
36511 | 57 |
import jdk.internal.perf.PerfCounter; |
58 |
||
59 |
/** |
|
60 |
* Initializes/boots the module system. |
|
61 |
* |
|
62 |
* The {@link #boot() boot} method is called early in the startup to initialize |
|
63 |
* the module system. In summary, the boot method creates a Configuration by |
|
64 |
* 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
|
65 |
* -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
|
66 |
* 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
|
67 |
* 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
|
68 |
* module in the the configuration defined to one of the built-in class loaders. |
36511 | 69 |
*/ |
70 |
||
71 |
public final class ModuleBootstrap { |
|
72 |
private ModuleBootstrap() { } |
|
73 |
||
74 |
private static final String JAVA_BASE = "java.base"; |
|
75 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
76 |
private static final String JAVA_SE = "java.se"; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
77 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
78 |
// the token for "all default modules" |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
79 |
private static final String ALL_DEFAULT = "ALL-DEFAULT"; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
80 |
|
36511 | 81 |
// the token for "all unnamed modules" |
82 |
private static final String ALL_UNNAMED = "ALL-UNNAMED"; |
|
83 |
||
84 |
// the token for "all system modules" |
|
85 |
private static final String ALL_SYSTEM = "ALL-SYSTEM"; |
|
86 |
||
87 |
// the token for "all modules on the module path" |
|
88 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
|
89 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
90 |
// The ModulePatcher for the initial configuration |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
91 |
private static final ModulePatcher patcher = initModulePatcher(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
92 |
|
36511 | 93 |
// ModuleFinder for the initial configuration |
94 |
private static ModuleFinder initialFinder; |
|
95 |
||
96 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
97 |
* Returns the ModulePatcher for the initial configuration. |
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 |
public static ModulePatcher patcher() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
100 |
return patcher; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
101 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
102 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
103 |
/** |
36511 | 104 |
* Returns the ModuleFinder for the initial configuration |
105 |
*/ |
|
106 |
public static ModuleFinder finder() { |
|
107 |
assert initialFinder != null; |
|
108 |
return initialFinder; |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Initialize the module system, returning the boot Layer. |
|
113 |
* |
|
114 |
* @see java.lang.System#initPhase2() |
|
115 |
*/ |
|
116 |
public static Layer boot() { |
|
117 |
||
118 |
long t0 = System.nanoTime(); |
|
119 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
120 |
// system modules (may be patched) |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
121 |
ModuleFinder systemModules; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
122 |
if (SystemModules.MODULE_NAMES.length > 0) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
123 |
systemModules = SystemModuleFinder.getInstance(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
124 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
125 |
systemModules = ModuleFinder.ofSystem(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
126 |
} |
37779
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 |
PerfCounters.systemModulesTime.addElapsedTimeFrom(t0); |
36511 | 129 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
130 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
131 |
long t1 = System.nanoTime(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
132 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
133 |
// 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
|
134 |
// the VM. We do this here so that java.base is defined as early as |
36511 | 135 |
// possible and also that resources in the base module can be located |
136 |
// for error messages that may happen from here on. |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
137 |
ModuleReference base = systemModules.find(JAVA_BASE).orElse(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
138 |
if (base == null) |
36511 | 139 |
throw new InternalError(JAVA_BASE + " not found"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
140 |
URI baseUri = base.location().orElse(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
141 |
if (baseUri == null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
142 |
throw new InternalError(JAVA_BASE + " does not have a location"); |
36511 | 143 |
BootLoader.loadModule(base); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
144 |
Modules.defineModule(null, base.descriptor(), baseUri); |
36511 | 145 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
146 |
PerfCounters.defineBaseTime.addElapsedTimeFrom(t1); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
147 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
148 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
149 |
long t2 = System.nanoTime(); |
36511 | 150 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
151 |
// --upgrade-module-path option specified to launcher |
36511 | 152 |
ModuleFinder upgradeModulePath |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
153 |
= createModulePathFinder("jdk.module.upgrade.path"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
154 |
if (upgradeModulePath != null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
155 |
systemModules = ModuleFinder.compose(upgradeModulePath, systemModules); |
36511 | 156 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
157 |
// --module-path option specified to the launcher |
36511 | 158 |
ModuleFinder appModulePath = createModulePathFinder("jdk.module.path"); |
159 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
160 |
// The module finder: [--upgrade-module-path] system [--module-path] |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
161 |
ModuleFinder finder = systemModules; |
36511 | 162 |
if (appModulePath != null) |
163 |
finder = ModuleFinder.compose(finder, appModulePath); |
|
164 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
165 |
// The root modules to resolve |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
166 |
Set<String> roots = new HashSet<>(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
167 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
168 |
// launcher -m option to specify the main/initial module |
36511 | 169 |
String mainModule = System.getProperty("jdk.module.main"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
170 |
if (mainModule != null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
171 |
roots.add(mainModule); |
36511 | 172 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
173 |
// additional module(s) specified by --add-modules |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
174 |
boolean addAllDefaultModules = false; |
36511 | 175 |
boolean addAllSystemModules = false; |
176 |
boolean addAllApplicationModules = false; |
|
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
177 |
for (String mod: getExtraAddModules()) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
178 |
switch (mod) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
179 |
case ALL_DEFAULT: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
180 |
addAllDefaultModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
181 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
182 |
case ALL_SYSTEM: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
183 |
addAllSystemModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
184 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
185 |
case ALL_MODULE_PATH: |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
186 |
addAllApplicationModules = true; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
187 |
break; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
188 |
default : |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
189 |
roots.add(mod); |
36511 | 190 |
} |
191 |
} |
|
192 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
193 |
// --limit-modules |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
194 |
String propValue = getAndRemoveProperty("jdk.module.limitmods"); |
36511 | 195 |
if (propValue != null) { |
196 |
Set<String> mods = new HashSet<>(); |
|
197 |
for (String mod: propValue.split(",")) { |
|
198 |
mods.add(mod); |
|
199 |
} |
|
200 |
finder = limitFinder(finder, mods, roots); |
|
201 |
} |
|
202 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
203 |
// 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
|
204 |
// module is the unnamed module of the application class loader. This |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
205 |
// is implemented by resolving "java.se" and all (non-java.*) modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
206 |
// that export an API. If "java.se" is not observable then all java.* |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
207 |
// modules are resolved. Modules that have the DO_NOT_RESOLVE_BY_DEFAULT |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
208 |
// bit set in their ModuleResolution attribute flags are excluded from |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
209 |
// the default set of roots. |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
210 |
if (mainModule == null || addAllDefaultModules) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
211 |
boolean hasJava = false; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
212 |
if (systemModules.find(JAVA_SE).isPresent()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
213 |
// java.se is a system module |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
214 |
if (finder == systemModules || finder.find(JAVA_SE).isPresent()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
215 |
// java.se is observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
216 |
hasJava = true; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
217 |
roots.add(JAVA_SE); |
36511 | 218 |
} |
219 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
220 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
221 |
for (ModuleReference mref : systemModules.findAll()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
222 |
String mn = mref.descriptor().name(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
223 |
if (hasJava && mn.startsWith("java.")) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
224 |
continue; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
225 |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
226 |
if (ModuleResolution.doNotResolveByDefault(mref)) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
227 |
continue; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
228 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
229 |
// add as root if observable and exports at least one package |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
230 |
if ((finder == systemModules || finder.find(mn).isPresent())) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
231 |
ModuleDescriptor descriptor = mref.descriptor(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
232 |
for (ModuleDescriptor.Exports e : descriptor.exports()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
233 |
if (!e.isQualified()) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
234 |
roots.add(mn); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
235 |
break; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
236 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
237 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
238 |
} |
36511 | 239 |
} |
240 |
} |
|
241 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
242 |
// 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
|
243 |
// modules will be resolved. |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
244 |
if (addAllSystemModules) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
245 |
ModuleFinder f = finder; // observable modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
246 |
systemModules.findAll() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
247 |
.stream() |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
248 |
.filter(mref -> !ModuleResolution.doNotResolveByDefault(mref)) |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
249 |
.map(ModuleReference::descriptor) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
250 |
.map(ModuleDescriptor::name) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
251 |
.filter(mn -> f.find(mn).isPresent()) // observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
252 |
.forEach(mn -> roots.add(mn)); |
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 |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
255 |
// 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
|
256 |
// 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
|
257 |
if (appModulePath != null && addAllApplicationModules) { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
258 |
ModuleFinder f = finder; // observable modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
259 |
appModulePath.findAll() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
260 |
.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
261 |
.map(ModuleReference::descriptor) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
262 |
.map(ModuleDescriptor::name) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
263 |
.filter(mn -> f.find(mn).isPresent()) // observable |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
264 |
.forEach(mn -> roots.add(mn)); |
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 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
267 |
PerfCounters.optionsAndRootsTime.addElapsedTimeFrom(t2); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
268 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
269 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
270 |
long t3 = System.nanoTime(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
271 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
272 |
// determine if post resolution checks are needed |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
273 |
boolean needPostResolutionChecks = true; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
274 |
if (baseUri.getScheme().equals("jrt") // toLowerCase not needed here |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
275 |
&& (upgradeModulePath == null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
276 |
&& (appModulePath == null) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
277 |
&& (patcher.isEmpty())) { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
278 |
needPostResolutionChecks = false; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
279 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
280 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
281 |
PrintStream traceOutput = null; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
282 |
if (Boolean.getBoolean("jdk.launcher.traceResolver")) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
283 |
traceOutput = System.out; |
36511 | 284 |
|
285 |
// run the resolver to create the configuration |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
286 |
Configuration cf = SharedSecrets.getJavaLangModuleAccess() |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
287 |
.resolveAndBind(finder, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
288 |
roots, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
289 |
needPostResolutionChecks, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
290 |
traceOutput); |
36511 | 291 |
|
292 |
// time to create configuration |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
293 |
PerfCounters.resolveTime.addElapsedTimeFrom(t3); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
294 |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
295 |
// check module names and incubating status |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
296 |
checkModuleNamesAndStatus(cf); |
36511 | 297 |
|
298 |
// mapping of modules to class loaders |
|
299 |
Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf); |
|
300 |
||
301 |
// 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
|
302 |
// loaded from the runtime image |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
303 |
if (needPostResolutionChecks) { |
36511 | 304 |
for (ResolvedModule resolvedModule : cf.modules()) { |
305 |
ModuleReference mref = resolvedModule.reference(); |
|
306 |
String name = mref.descriptor().name(); |
|
307 |
ClassLoader cl = clf.apply(name); |
|
308 |
if (cl == null) { |
|
309 |
||
310 |
if (upgradeModulePath != null |
|
311 |
&& upgradeModulePath.find(name).isPresent()) |
|
312 |
fail(name + ": cannot be loaded from upgrade module path"); |
|
313 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
314 |
if (!systemModules.find(name).isPresent()) |
36511 | 315 |
fail(name + ": cannot be loaded from application module path"); |
316 |
} |
|
317 |
} |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
318 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
319 |
// check if module specified in --patch-module is present |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
320 |
for (String mn: patcher.patchedModules()) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
321 |
if (!cf.findModule(mn).isPresent()) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
322 |
warnUnknownModule(PATCH_MODULE, mn); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
323 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
324 |
} |
36511 | 325 |
} |
326 |
||
42770
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
327 |
// if needed check that there are no split packages in the set of |
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
328 |
// resolved modules for the boot layer |
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
329 |
if (SystemModules.hasSplitPackages() || needPostResolutionChecks) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
330 |
Map<String, String> packageToModule = new HashMap<>(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
331 |
for (ResolvedModule resolvedModule : cf.modules()) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
332 |
ModuleDescriptor descriptor = |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
333 |
resolvedModule.reference().descriptor(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
334 |
String name = descriptor.name(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
335 |
for (String p : descriptor.packages()) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
336 |
String other = packageToModule.putIfAbsent(p, name); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
337 |
if (other != null) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
338 |
fail("Package " + p + " in both module " |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
339 |
+ name + " and module " + other); |
42770
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
340 |
} |
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
341 |
} |
d363e7c3584a
8171400: Move checking of duplicate packages in the boot layer to link time
redestad
parents:
42704
diff
changeset
|
342 |
} |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
343 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
344 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
345 |
long t4 = System.nanoTime(); |
36511 | 346 |
|
347 |
// define modules to VM/runtime |
|
348 |
Layer bootLayer = Layer.empty().defineModules(cf, clf); |
|
349 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
350 |
PerfCounters.layerCreateTime.addElapsedTimeFrom(t4); |
36511 | 351 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
352 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
353 |
long t5 = System.nanoTime(); |
36511 | 354 |
|
355 |
// define the module to its class loader, except java.base |
|
356 |
for (ResolvedModule resolvedModule : cf.modules()) { |
|
357 |
ModuleReference mref = resolvedModule.reference(); |
|
358 |
String name = mref.descriptor().name(); |
|
359 |
ClassLoader cl = clf.apply(name); |
|
360 |
if (cl == null) { |
|
361 |
if (!name.equals(JAVA_BASE)) BootLoader.loadModule(mref); |
|
362 |
} else { |
|
363 |
((BuiltinClassLoader)cl).loadModule(mref); |
|
364 |
} |
|
365 |
} |
|
366 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
367 |
PerfCounters.loadModulesTime.addElapsedTimeFrom(t5); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
368 |
|
36511 | 369 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
370 |
// --add-reads, -add-exports/-add-opens |
36511 | 371 |
addExtraReads(bootLayer); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
372 |
addExtraExportsAndOpens(bootLayer); |
36511 | 373 |
|
374 |
// total time to initialize |
|
375 |
PerfCounters.bootstrapTime.addElapsedTimeFrom(t0); |
|
376 |
||
377 |
// remember the ModuleFinder |
|
378 |
initialFinder = finder; |
|
379 |
||
380 |
return bootLayer; |
|
381 |
} |
|
382 |
||
383 |
/** |
|
384 |
* Returns a ModuleFinder that limits observability to the given root |
|
385 |
* modules, their transitive dependences, plus a set of other modules. |
|
386 |
*/ |
|
387 |
private static ModuleFinder limitFinder(ModuleFinder finder, |
|
388 |
Set<String> roots, |
|
389 |
Set<String> otherMods) |
|
390 |
{ |
|
391 |
// resolve all root modules |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
392 |
Configuration cf = Configuration.empty().resolve(finder, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
393 |
ModuleFinder.of(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
394 |
roots); |
36511 | 395 |
|
396 |
// module name -> reference |
|
397 |
Map<String, ModuleReference> map = new HashMap<>(); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
398 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
399 |
// root modules and their transitive dependences |
36511 | 400 |
cf.modules().stream() |
401 |
.map(ResolvedModule::reference) |
|
402 |
.forEach(mref -> map.put(mref.descriptor().name(), mref)); |
|
403 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
404 |
// additional modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
405 |
otherMods.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
406 |
.map(finder::find) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
407 |
.flatMap(Optional::stream) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
408 |
.forEach(mref -> map.putIfAbsent(mref.descriptor().name(), mref)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
409 |
|
36511 | 410 |
// set of modules that are observable |
411 |
Set<ModuleReference> mrefs = new HashSet<>(map.values()); |
|
412 |
||
413 |
return new ModuleFinder() { |
|
414 |
@Override |
|
415 |
public Optional<ModuleReference> find(String name) { |
|
416 |
return Optional.ofNullable(map.get(name)); |
|
417 |
} |
|
418 |
@Override |
|
419 |
public Set<ModuleReference> findAll() { |
|
420 |
return mrefs; |
|
421 |
} |
|
422 |
}; |
|
423 |
} |
|
424 |
||
425 |
/** |
|
426 |
* Creates a finder from the module path that is the value of the given |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
427 |
* system property and optionally patched by --patch-module |
36511 | 428 |
*/ |
429 |
private static ModuleFinder createModulePathFinder(String prop) { |
|
430 |
String s = System.getProperty(prop); |
|
431 |
if (s == null) { |
|
432 |
return null; |
|
433 |
} else { |
|
434 |
String[] dirs = s.split(File.pathSeparator); |
|
435 |
Path[] paths = new Path[dirs.length]; |
|
436 |
int i = 0; |
|
437 |
for (String dir: dirs) { |
|
438 |
paths[i++] = Paths.get(dir); |
|
439 |
} |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
440 |
return ModulePath.of(patcher, paths); |
36511 | 441 |
} |
442 |
} |
|
443 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
444 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
445 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
446 |
* Initialize the module patcher for the initial configuration passed on the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
447 |
* value of the --patch-module options. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
448 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
449 |
private static ModulePatcher initModulePatcher() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
450 |
Map<String, List<String>> map = decode("jdk.module.patch.", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
451 |
File.pathSeparator, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
452 |
false); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
453 |
return new ModulePatcher(map); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
454 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
455 |
|
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
456 |
/** |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
457 |
* 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
|
458 |
* on the command line |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
459 |
*/ |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
460 |
private static Set<String> getExtraAddModules() { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
461 |
String prefix = "jdk.module.addmods."; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
462 |
int index = 0; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
463 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
464 |
// the system property is removed after decoding |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
465 |
String value = getAndRemoveProperty(prefix + index); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
466 |
if (value == null) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
467 |
return Collections.emptySet(); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
468 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
469 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
470 |
Set<String> modules = new HashSet<>(); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
471 |
while (value != null) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
472 |
for (String s : value.split(",")) { |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
473 |
if (s.length() > 0) modules.add(s); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
474 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
475 |
index++; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
476 |
value = getAndRemoveProperty(prefix + index); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
477 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
478 |
|
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
479 |
return modules; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
480 |
} |
36511 | 481 |
|
482 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
483 |
* Process the --add-reads options to add any additional read edges that |
36511 | 484 |
* are specified on the command-line. |
485 |
*/ |
|
486 |
private static void addExtraReads(Layer bootLayer) { |
|
487 |
||
488 |
// decode the command line options |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
489 |
Map<String, List<String>> map = decode("jdk.module.addreads."); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
490 |
if (map.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
491 |
return; |
36511 | 492 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
493 |
for (Map.Entry<String, List<String>> e : map.entrySet()) { |
36511 | 494 |
|
495 |
// the key is $MODULE |
|
496 |
String mn = e.getKey(); |
|
497 |
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
|
498 |
if (!om.isPresent()) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
499 |
warnUnknownModule(ADD_READS, mn); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
500 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
501 |
} |
36511 | 502 |
Module m = om.get(); |
503 |
||
504 |
// the value is the set of other modules (by name) |
|
505 |
for (String name : e.getValue()) { |
|
506 |
if (ALL_UNNAMED.equals(name)) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
507 |
Modules.addReadsAllUnnamed(m); |
36511 | 508 |
} else { |
509 |
om = bootLayer.findModule(name); |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
510 |
if (om.isPresent()) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
511 |
Modules.addReads(m, om.get()); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
512 |
} else { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
513 |
warnUnknownModule(ADD_READS, name); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
514 |
} |
36511 | 515 |
} |
516 |
} |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
521 |
* Process the --add-exports and --add-opens options to export/open |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
522 |
* additional packages specified on the command-line. |
36511 | 523 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
524 |
private static void addExtraExportsAndOpens(Layer bootLayer) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
525 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
526 |
// --add-exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
527 |
String prefix = "jdk.module.addexports."; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
528 |
Map<String, List<String>> extraExports = decode(prefix); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
529 |
if (!extraExports.isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
530 |
addExtraExportsOrOpens(bootLayer, extraExports, false); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
531 |
} |
36511 | 532 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
533 |
// --add-opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
534 |
prefix = "jdk.module.addopens."; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
535 |
Map<String, List<String>> extraOpens = decode(prefix); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
536 |
if (!extraOpens.isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
537 |
addExtraExportsOrOpens(bootLayer, extraOpens, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
538 |
} |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
539 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
540 |
// DEBUG_ADD_OPENS is for debugging purposes only |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
541 |
String home = System.getProperty("java.home"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
542 |
Path file = Paths.get(home, "conf", "DEBUG_ADD_OPENS"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
543 |
if (Files.exists(file)) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
544 |
warn(file + " detected; may break encapsulation"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
545 |
try (Stream<String> lines = Files.lines(file)) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
546 |
lines.map(line -> line.trim()) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
547 |
.filter(line -> (!line.isEmpty() && !line.startsWith("#"))) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
548 |
.forEach(line -> { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
549 |
String[] s = line.split("/"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
550 |
if (s.length != 2) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
551 |
fail("Unable to parse as <module>/<package>: " + line); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
552 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
553 |
String mn = s[0]; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
554 |
String pkg = s[1]; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
555 |
openPackage(bootLayer, mn, pkg); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
556 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
557 |
}); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
558 |
} catch (IOException ioe) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
559 |
throw new UncheckedIOException(ioe); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
560 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
561 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
562 |
} |
36511 | 563 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
564 |
private static void openPackage(Layer bootLayer, String mn, String pkg) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
565 |
if (mn.equals("ALL-RESOLVED") && pkg.equals("ALL-PACKAGES")) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
566 |
bootLayer.modules().stream().forEach(m -> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
567 |
m.getDescriptor().packages().forEach(pn -> openPackage(m, pn))); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
568 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
569 |
bootLayer.findModule(mn) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
570 |
.filter(m -> m.getDescriptor().packages().contains(pkg)) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
571 |
.ifPresent(m -> openPackage(m, pkg)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
572 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
573 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
574 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
575 |
private static void openPackage(Module m, String pn) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
576 |
Modules.addOpensToAllUnnamed(m, pn); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
577 |
warn("Opened for deep reflection: " + m.getName() + "/" + pn); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
578 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
579 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
580 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
581 |
private static void addExtraExportsOrOpens(Layer bootLayer, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
582 |
Map<String, List<String>> map, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
583 |
boolean opens) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
584 |
{ |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
585 |
String option = opens ? ADD_OPENS : ADD_EXPORTS; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
586 |
for (Map.Entry<String, List<String>> e : map.entrySet()) { |
36511 | 587 |
|
588 |
// the key is $MODULE/$PACKAGE |
|
589 |
String key = e.getKey(); |
|
590 |
String[] s = key.split("/"); |
|
591 |
if (s.length != 2) |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
592 |
fail(unableToParse(option, "<module>/<package>", key)); |
36511 | 593 |
|
594 |
String mn = s[0]; |
|
595 |
String pn = s[1]; |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
596 |
if (mn.isEmpty() || pn.isEmpty()) |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
597 |
fail(unableToParse(option, "<module>/<package>", key)); |
36511 | 598 |
|
599 |
// The exporting module is in the boot layer |
|
600 |
Module m; |
|
601 |
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
|
602 |
if (!om.isPresent()) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
603 |
warnUnknownModule(option, mn); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
604 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
605 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
606 |
|
36511 | 607 |
m = om.get(); |
608 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
609 |
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
|
610 |
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
|
611 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
612 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
613 |
|
36511 | 614 |
// the value is the set of modules to export to (by name) |
615 |
for (String name : e.getValue()) { |
|
616 |
boolean allUnnamed = false; |
|
617 |
Module other = null; |
|
618 |
if (ALL_UNNAMED.equals(name)) { |
|
619 |
allUnnamed = true; |
|
620 |
} else { |
|
621 |
om = bootLayer.findModule(name); |
|
622 |
if (om.isPresent()) { |
|
623 |
other = om.get(); |
|
624 |
} else { |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
625 |
warnUnknownModule(option, name); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
626 |
continue; |
36511 | 627 |
} |
628 |
} |
|
629 |
if (allUnnamed) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
630 |
if (opens) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
631 |
Modules.addOpensToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
632 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
633 |
Modules.addExportsToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
634 |
} |
36511 | 635 |
} else { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
636 |
if (opens) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
637 |
Modules.addOpens(m, pn, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
638 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
639 |
Modules.addExports(m, pn, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
640 |
} |
36511 | 641 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
642 |
|
36511 | 643 |
} |
644 |
} |
|
645 |
} |
|
646 |
||
647 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
648 |
* Decodes the values of --add-reads, -add-exports, --add-opens or |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
649 |
* --patch-modules options that are encoded in system properties. |
36511 | 650 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
651 |
* @param prefix the system property prefix |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
652 |
* @praam regex the regex for splitting the RHS of the option value |
36511 | 653 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
654 |
private static Map<String, List<String>> decode(String prefix, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
655 |
String regex, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
656 |
boolean allowDuplicates) { |
36511 | 657 |
int index = 0; |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
658 |
// the system property is removed after decoding |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
659 |
String value = getAndRemoveProperty(prefix + index); |
36511 | 660 |
if (value == null) |
661 |
return Collections.emptyMap(); |
|
662 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
663 |
Map<String, List<String>> map = new HashMap<>(); |
36511 | 664 |
|
665 |
while (value != null) { |
|
666 |
||
667 |
int pos = value.indexOf('='); |
|
668 |
if (pos == -1) |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
669 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 670 |
if (pos == 0) |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
671 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 672 |
|
673 |
// key is <module> or <module>/<package> |
|
674 |
String key = value.substring(0, pos); |
|
675 |
||
676 |
String rhs = value.substring(pos+1); |
|
677 |
if (rhs.isEmpty()) |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
678 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 679 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
680 |
// value is <module>(,<module>)* or <file>(<pathsep><file>)* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
681 |
if (!allowDuplicates && map.containsKey(key)) |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
682 |
fail(key + " specified more than once in " + option(prefix)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
683 |
List<String> values = map.computeIfAbsent(key, k -> new ArrayList<>()); |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
684 |
int ntargets = 0; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
685 |
for (String s : rhs.split(regex)) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
686 |
if (s.length() > 0) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
687 |
values.add(s); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
688 |
ntargets++; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
689 |
} |
36511 | 690 |
} |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
691 |
if (ntargets == 0) |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
692 |
fail("Target must be specified: " + option(prefix) + " " + value); |
36511 | 693 |
|
694 |
index++; |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
695 |
value = getAndRemoveProperty(prefix + index); |
36511 | 696 |
} |
697 |
||
698 |
return map; |
|
699 |
} |
|
700 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
701 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
702 |
* Decodes the values of --add-reads, -add-exports or --add-opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
703 |
* which use the "," to separate the RHS of the option value. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
704 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
705 |
private static Map<String, List<String>> decode(String prefix) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
706 |
return decode(prefix, ",", true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
707 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
708 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
709 |
/** |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
710 |
* Gets and remove the named system property |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
711 |
*/ |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
712 |
private static String getAndRemoveProperty(String key) { |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
713 |
return (String)System.getProperties().remove(key); |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
714 |
} |
36511 | 715 |
|
716 |
/** |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
717 |
* Checks the names and resolution bit of each module in the configuration, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
718 |
* emitting warnings if needed. |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
719 |
*/ |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
720 |
private static void checkModuleNamesAndStatus(Configuration cf) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
721 |
String incubating = null; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
722 |
for (ResolvedModule rm : cf.modules()) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
723 |
ModuleReference mref = rm.reference(); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
724 |
String mn = mref.descriptor().name(); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
725 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
726 |
// emit warning if module name ends with a non-Java letter |
42704 | 727 |
if (!Checks.hasLegalModuleNameLastCharacter(mn)) |
728 |
warn("Module name \"" + mn + "\" may soon be illegal"); |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
729 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
730 |
// emit warning if the WARN_INCUBATING module resolution bit set |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
731 |
if (ModuleResolution.hasIncubatingWarning(mref)) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
732 |
if (incubating == null) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
733 |
incubating = mn; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
734 |
} else { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
735 |
incubating += ", " + mn; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
736 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
737 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
738 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
739 |
if (incubating != null) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
740 |
warn("Using incubator modules: " + incubating); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
741 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
742 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
743 |
/** |
36511 | 744 |
* Throws a RuntimeException with the given message |
745 |
*/ |
|
746 |
static void fail(String m) { |
|
747 |
throw new RuntimeException(m); |
|
748 |
} |
|
749 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
750 |
static void warn(String m) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
751 |
System.err.println("WARNING: " + m); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
752 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
753 |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
754 |
static void warnUnknownModule(String option, String mn) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
755 |
warn("Unknown module: " + mn + " specified in " + option); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
756 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
757 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
758 |
static String unableToParse(String option, String text, String value) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
759 |
return "Unable to parse " + option + " " + text + ": " + value; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
760 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
761 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
762 |
private static final String ADD_MODULES = "--add-modules"; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
763 |
private static final String ADD_EXPORTS = "--add-exports"; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
764 |
private static final String ADD_OPENS = "--add-opens"; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
765 |
private static final String ADD_READS = "--add-reads"; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
766 |
private static final String PATCH_MODULE = "--patch-module"; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
767 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
768 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
769 |
/* |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
770 |
* Returns the command-line option name corresponds to the specified |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
771 |
* system property prefix. |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
772 |
*/ |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
773 |
static String option(String prefix) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
774 |
switch (prefix) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
775 |
case "jdk.module.addexports.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
776 |
return ADD_EXPORTS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
777 |
case "jdk.module.addopens.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
778 |
return ADD_OPENS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
779 |
case "jdk.module.addreads.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
780 |
return ADD_READS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
781 |
case "jdk.module.patch.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
782 |
return PATCH_MODULE; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
783 |
case "jdk.module.addmods.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
784 |
return ADD_MODULES; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
785 |
default: |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
786 |
throw new IllegalArgumentException(prefix); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
787 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
788 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
789 |
|
36511 | 790 |
static class PerfCounters { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
791 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
792 |
static PerfCounter systemModulesTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
793 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.systemModulesTime"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
794 |
static PerfCounter defineBaseTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
795 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.defineBaseTime"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
796 |
static PerfCounter optionsAndRootsTime |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
797 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.optionsAndRootsTime"); |
36511 | 798 |
static PerfCounter resolveTime |
799 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.resolveTime"); |
|
800 |
static PerfCounter layerCreateTime |
|
801 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.layerCreateTime"); |
|
802 |
static PerfCounter loadModulesTime |
|
803 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.loadModulesTime"); |
|
804 |
static PerfCounter bootstrapTime |
|
805 |
= PerfCounter.newPerfCounter("jdk.module.bootstrap.totalTime"); |
|
806 |
} |
|
807 |
} |