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