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