author | alanb |
Tue, 19 Nov 2019 11:35:29 +0000 | |
changeset 59133 | 580fb715b29d |
parent 53018 | 8bf9268df0e2 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
49285
4d2e3f5abb48
8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents:
47471
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, 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; |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
35 |
import java.net.URI; |
36511 | 36 |
import java.nio.file.Path; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
37 |
import java.util.ArrayList; |
36511 | 38 |
import java.util.Collections; |
39 |
import java.util.HashMap; |
|
40 |
import java.util.HashSet; |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
41 |
import java.util.Iterator; |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
42 |
import java.util.LinkedHashMap; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
43 |
import java.util.List; |
36511 | 44 |
import java.util.Map; |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
45 |
import java.util.NoSuchElementException; |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
46 |
import java.util.Objects; |
36511 | 47 |
import java.util.Optional; |
48 |
import java.util.Set; |
|
49 |
import java.util.function.Function; |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
50 |
import java.util.stream.Collectors; |
36511 | 51 |
|
52 |
import jdk.internal.loader.BootLoader; |
|
53 |
import jdk.internal.loader.BuiltinClassLoader; |
|
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51371
diff
changeset
|
54 |
import jdk.internal.access.JavaLangAccess; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51371
diff
changeset
|
55 |
import jdk.internal.access.JavaLangModuleAccess; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
51371
diff
changeset
|
56 |
import jdk.internal.access.SharedSecrets; |
36511 | 57 |
import jdk.internal.perf.PerfCounter; |
58 |
||
59 |
/** |
|
60 |
* Initializes/boots the module system. |
|
61 |
* |
|
62 |
* The {@link #boot() boot} method is called early in the startup to initialize |
|
63 |
* the module system. In summary, the boot method creates a Configuration by |
|
64 |
* resolving a set of module names specified via the launcher (or equivalent) |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
65 |
* -m and --add-modules options. The modules are located on a module path that |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
66 |
* is constructed from the upgrade module path, system modules, and application |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
67 |
* module path. The Configuration is instantiated as the boot layer with each |
47471 | 68 |
* module in the configuration defined to a class loader. |
36511 | 69 |
*/ |
70 |
||
71 |
public final class ModuleBootstrap { |
|
72 |
private ModuleBootstrap() { } |
|
73 |
||
74 |
private static final String JAVA_BASE = "java.base"; |
|
75 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
76 |
// the token for "all default modules" |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
77 |
private static final String ALL_DEFAULT = "ALL-DEFAULT"; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
78 |
|
36511 | 79 |
// the token for "all unnamed modules" |
80 |
private static final String ALL_UNNAMED = "ALL-UNNAMED"; |
|
81 |
||
82 |
// the token for "all system modules" |
|
83 |
private static final String ALL_SYSTEM = "ALL-SYSTEM"; |
|
84 |
||
85 |
// the token for "all modules on the module path" |
|
86 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
|
87 |
||
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
88 |
// access to java.lang/module |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
89 |
private static final JavaLangModuleAccess JLMA |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
90 |
= SharedSecrets.getJavaLangModuleAccess(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
91 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
92 |
// The ModulePatcher for the initial configuration |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
93 |
private static final ModulePatcher patcher = initModulePatcher(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
94 |
|
36511 | 95 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
96 |
* Returns the ModulePatcher for the initial configuration. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
97 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
98 |
public static ModulePatcher patcher() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
99 |
return patcher; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
100 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
101 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
102 |
// ModuleFinders for the initial configuration |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
103 |
private static volatile ModuleFinder unlimitedFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
104 |
private static volatile ModuleFinder limitedFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
105 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
106 |
/** |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
107 |
* Returns the ModuleFinder for the initial configuration before |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
108 |
* observability is limited by the --limit-modules command line option. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
109 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
110 |
* @apiNote Used to support locating modules {@code java.instrument} and |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
111 |
* {@code jdk.management.agent} modules when they are loaded dynamically. |
36511 | 112 |
*/ |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
113 |
public static ModuleFinder unlimitedFinder() { |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
114 |
ModuleFinder finder = unlimitedFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
115 |
if (finder == null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
116 |
return ModuleFinder.ofSystem(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
117 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
118 |
return finder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
119 |
} |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
120 |
} |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
121 |
|
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
122 |
/** |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
123 |
* Returns the ModuleFinder for the initial configuration. |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
124 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
125 |
* @apiNote Used to support "{@code java --list-modules}". |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
126 |
*/ |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
127 |
public static ModuleFinder limitedFinder() { |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
128 |
ModuleFinder finder = limitedFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
129 |
if (finder == null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
130 |
return unlimitedFinder(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
131 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
132 |
return finder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
133 |
} |
36511 | 134 |
} |
135 |
||
136 |
/** |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
137 |
* Initialize the module system, returning the boot layer. |
36511 | 138 |
* |
50700
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
139 |
* @see java.lang.System#initPhase2(boolean, boolean) |
36511 | 140 |
*/ |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
141 |
public static ModuleLayer boot() throws Exception { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
142 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
143 |
// Step 0: Command line options |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
144 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
145 |
long t0 = System.nanoTime(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
146 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
147 |
ModuleFinder upgradeModulePath = finderFor("jdk.module.upgrade.path"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
148 |
ModuleFinder appModulePath = finderFor("jdk.module.path"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
149 |
boolean isPatched = patcher.hasPatches(); |
36511 | 150 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
151 |
String mainModule = System.getProperty("jdk.module.main"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
152 |
Set<String> addModules = addModules(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
153 |
Set<String> limitModules = limitModules(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
154 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
155 |
PrintStream traceOutput = null; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
156 |
String trace = getAndRemoveProperty("jdk.module.showModuleResolution"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
157 |
if (trace != null && Boolean.parseBoolean(trace)) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
158 |
traceOutput = System.out; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
159 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
160 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
161 |
// Step 1: The observable system modules, either all system modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
162 |
// or the system modules pre-generated for the initial module (the |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
163 |
// initial module may be the unnamed module). If the system modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
164 |
// are pre-generated for the initial module then resolution can be |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
165 |
// skipped. |
36511 | 166 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
167 |
long t1 = System.nanoTime(); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
168 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
169 |
SystemModules systemModules = null; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
170 |
ModuleFinder systemModuleFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
171 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
172 |
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
173 |
boolean needResolution = true; |
51371
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
174 |
boolean canArchive = false; |
52872 | 175 |
boolean hasSplitPackages; |
176 |
boolean hasIncubatorModules; |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
177 |
|
50951
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
178 |
// If the java heap was archived at CDS dump time and the environment |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
179 |
// at dump time matches the current environment then use the archived |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
180 |
// system modules and finder. |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
181 |
ArchivedModuleGraph archivedModuleGraph = ArchivedModuleGraph.get(mainModule); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
182 |
if (archivedModuleGraph != null |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
183 |
&& !haveModulePath |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
184 |
&& addModules.isEmpty() |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
185 |
&& limitModules.isEmpty() |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
186 |
&& !isPatched) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
187 |
systemModuleFinder = archivedModuleGraph.finder(); |
52872 | 188 |
hasSplitPackages = archivedModuleGraph.hasSplitPackages(); |
189 |
hasIncubatorModules = archivedModuleGraph.hasIncubatorModules(); |
|
50951
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
190 |
needResolution = (traceOutput != null); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
191 |
} else { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
192 |
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
193 |
systemModules = SystemModuleFinders.systemModules(mainModule); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
194 |
if (systemModules != null && !isPatched) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
195 |
needResolution = (traceOutput != null); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
196 |
canArchive = true; |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
197 |
} |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
198 |
} |
50951
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
199 |
if (systemModules == null) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
200 |
// all system modules are observable |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
201 |
systemModules = SystemModuleFinders.allSystemModules(); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
202 |
} |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
203 |
if (systemModules != null) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
204 |
// images build |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
205 |
systemModuleFinder = SystemModuleFinders.of(systemModules); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
206 |
} else { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
207 |
// exploded build or testing |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
208 |
systemModules = new ExplodedSystemModules(); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
209 |
systemModuleFinder = SystemModuleFinders.ofSystem(); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
50738
diff
changeset
|
210 |
} |
52872 | 211 |
|
212 |
hasSplitPackages = systemModules.hasSplitPackages(); |
|
213 |
hasIncubatorModules = systemModules.hasIncubatorModules(); |
|
214 |
// not using the archived module graph - avoid accidental use |
|
215 |
archivedModuleGraph = null; |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
216 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
217 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
218 |
Counters.add("jdk.module.boot.1.systemModulesTime", t1); |
36511 | 219 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
220 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
221 |
// Step 2: Define and load java.base. This patches all classes loaded |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
222 |
// to date so that they are members of java.base. Once java.base is |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
223 |
// loaded then resources in java.base are available for error messages |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
224 |
// needed from here on. |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
225 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
226 |
long t2 = System.nanoTime(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
227 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
228 |
ModuleReference base = systemModuleFinder.find(JAVA_BASE).orElse(null); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
229 |
if (base == null) |
36511 | 230 |
throw new InternalError(JAVA_BASE + " not found"); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
231 |
URI baseUri = base.location().orElse(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
232 |
if (baseUri == null) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
233 |
throw new InternalError(JAVA_BASE + " does not have a location"); |
36511 | 234 |
BootLoader.loadModule(base); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
235 |
Modules.defineModule(null, base.descriptor(), baseUri); |
36511 | 236 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
237 |
Counters.add("jdk.module.boot.2.defineBaseTime", t2); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
238 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
239 |
|
50700
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
240 |
// Step 2a: Scan all modules when --validate-modules specified |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
241 |
|
47010
d8dd5c878ce5
8186145: tools/launcher/modules/validate/ValidateModulesTest.java fails when launched with -XX:+EnableJVMCI
mchung
parents:
46096
diff
changeset
|
242 |
if (getAndRemoveProperty("jdk.module.validation") != null) { |
50700
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
243 |
int errors = ModulePathValidator.scanAllModules(System.out); |
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
244 |
if (errors > 0) { |
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
245 |
fail("Validation of module path failed"); |
97e9c4f58986
8194937: Inconsistent behavior of --validate-modules when combined with -m and other options
alanb
parents:
49285
diff
changeset
|
246 |
} |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
247 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
248 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
249 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
250 |
// Step 3: If resolution is needed then create the module finder and |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
251 |
// the set of root modules to resolve. |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
252 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
253 |
long t3 = System.nanoTime(); |
36511 | 254 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
255 |
ModuleFinder savedModuleFinder = null; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
256 |
ModuleFinder finder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
257 |
Set<String> roots; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
258 |
if (needResolution) { |
36511 | 259 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
260 |
// upgraded modules override the modules in the run-time image |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
261 |
if (upgradeModulePath != null) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
262 |
systemModuleFinder = ModuleFinder.compose(upgradeModulePath, |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
263 |
systemModuleFinder); |
36511 | 264 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
265 |
// The module finder: [--upgrade-module-path] system [--module-path] |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
266 |
if (appModulePath != null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
267 |
finder = ModuleFinder.compose(systemModuleFinder, appModulePath); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
268 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
269 |
finder = systemModuleFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
270 |
} |
36511 | 271 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
272 |
// The root modules to resolve |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
273 |
roots = new HashSet<>(); |
36511 | 274 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
275 |
// launcher -m option to specify the main/initial module |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
276 |
if (mainModule != null) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
277 |
roots.add(mainModule); |
36511 | 278 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
279 |
// additional module(s) specified by --add-modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
280 |
boolean addAllDefaultModules = false; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
281 |
boolean addAllSystemModules = false; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
282 |
boolean addAllApplicationModules = false; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
283 |
for (String mod : addModules) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
284 |
switch (mod) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
285 |
case ALL_DEFAULT: |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
286 |
addAllDefaultModules = true; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
287 |
break; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
288 |
case ALL_SYSTEM: |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
289 |
addAllSystemModules = true; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
290 |
break; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
291 |
case ALL_MODULE_PATH: |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
292 |
addAllApplicationModules = true; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
293 |
break; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
294 |
default: |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
295 |
roots.add(mod); |
36511 | 296 |
} |
297 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
298 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
299 |
// --limit-modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
300 |
savedModuleFinder = finder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
301 |
if (!limitModules.isEmpty()) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
302 |
finder = limitFinder(finder, limitModules, roots); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
303 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
304 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
305 |
// If there is no initial module specified then assume that the initial |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
306 |
// module is the unnamed module of the application class loader. This |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50700
diff
changeset
|
307 |
// is implemented by resolving all observable modules that export an |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50700
diff
changeset
|
308 |
// API. Modules that have the DO_NOT_RESOLVE_BY_DEFAULT bit set in |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50700
diff
changeset
|
309 |
// their ModuleResolution attribute flags are excluded from the |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50700
diff
changeset
|
310 |
// default set of roots. |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
311 |
if (mainModule == null || addAllDefaultModules) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
312 |
roots.addAll(DefaultRoots.compute(systemModuleFinder, finder)); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
313 |
} |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
314 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
315 |
// If `--add-modules ALL-SYSTEM` is specified then all observable system |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
316 |
// modules will be resolved. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
317 |
if (addAllSystemModules) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
318 |
ModuleFinder f = finder; // observable modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
319 |
systemModuleFinder.findAll() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
320 |
.stream() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
321 |
.map(ModuleReference::descriptor) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
322 |
.map(ModuleDescriptor::name) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
323 |
.filter(mn -> f.find(mn).isPresent()) // observable |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
324 |
.forEach(mn -> roots.add(mn)); |
36511 | 325 |
} |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
326 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
327 |
// If `--add-modules ALL-MODULE-PATH` is specified then all observable |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
328 |
// modules on the application module path will be resolved. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
329 |
if (appModulePath != null && addAllApplicationModules) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
330 |
ModuleFinder f = finder; // observable modules |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
331 |
appModulePath.findAll() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
332 |
.stream() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
333 |
.map(ModuleReference::descriptor) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
334 |
.map(ModuleDescriptor::name) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
335 |
.filter(mn -> f.find(mn).isPresent()) // observable |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
336 |
.forEach(mn -> roots.add(mn)); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
337 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
338 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
339 |
// no resolution case |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
340 |
finder = systemModuleFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
341 |
roots = null; |
36511 | 342 |
} |
343 |
||
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
344 |
Counters.add("jdk.module.boot.3.optionsAndRootsTime", t3); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
345 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
346 |
// Step 4: Resolve the root modules, with service binding, to create |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
347 |
// the configuration for the boot layer. If resolution is not needed |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
348 |
// then create the configuration for the boot layer from the |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
349 |
// readability graph created at link time. |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
350 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
351 |
long t4 = System.nanoTime(); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
352 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
353 |
Configuration cf; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
354 |
if (needResolution) { |
59133
580fb715b29d
8233922: Service binding augments module graph with observable incubator modules
alanb
parents:
53018
diff
changeset
|
355 |
cf = Modules.newBootLayerConfiguration(finder, roots, traceOutput); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
356 |
} else { |
51371
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
357 |
if (archivedModuleGraph != null) { |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
358 |
cf = archivedModuleGraph.configuration(); |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
359 |
} else { |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
360 |
Map<String, Set<String>> map = systemModules.moduleReads(); |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
361 |
cf = JLMA.newConfiguration(systemModuleFinder, map); |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
362 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
363 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
364 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
365 |
// check that modules specified to --patch-module are resolved |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
366 |
if (isPatched) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
367 |
patcher.patchedModules() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
368 |
.stream() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
369 |
.filter(mn -> !cf.findModule(mn).isPresent()) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
370 |
.forEach(mn -> warnUnknownModule(PATCH_MODULE, mn)); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
371 |
} |
36511 | 372 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
373 |
Counters.add("jdk.module.boot.4.resolveTime", t4); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
374 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
375 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
376 |
// Step 5: Map the modules in the configuration to class loaders. |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
377 |
// The static configuration provides the mapping of standard and JDK |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
378 |
// modules to the boot and platform loaders. All other modules (JDK |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
379 |
// tool modules, and both explicit and automatic modules on the |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
380 |
// application module path) are defined to the application class |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
381 |
// loader. |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
382 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
383 |
long t5 = System.nanoTime(); |
36511 | 384 |
|
385 |
// mapping of modules to class loaders |
|
386 |
Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf); |
|
387 |
||
388 |
// 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
|
389 |
// loaded from the runtime image |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
390 |
if (haveModulePath) { |
36511 | 391 |
for (ResolvedModule resolvedModule : cf.modules()) { |
392 |
ModuleReference mref = resolvedModule.reference(); |
|
393 |
String name = mref.descriptor().name(); |
|
394 |
ClassLoader cl = clf.apply(name); |
|
395 |
if (cl == null) { |
|
396 |
if (upgradeModulePath != null |
|
397 |
&& upgradeModulePath.find(name).isPresent()) |
|
398 |
fail(name + ": cannot be loaded from upgrade module path"); |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
399 |
if (!systemModuleFinder.find(name).isPresent()) |
36511 | 400 |
fail(name + ": cannot be loaded from application module path"); |
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
||
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
405 |
// check for split packages in the modules mapped to the built-in loaders |
52872 | 406 |
if (hasSplitPackages || isPatched || haveModulePath) { |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
407 |
checkSplitPackages(cf, clf); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
408 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
409 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
410 |
// load/register the modules with the built-in class loaders |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
411 |
loadModules(cf, clf); |
36511 | 412 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
413 |
Counters.add("jdk.module.boot.5.loadModulesTime", t5); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
414 |
|
36511 | 415 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
416 |
// Step 6: Define all modules to the VM |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
417 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
418 |
long t6 = System.nanoTime(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
419 |
ModuleLayer bootLayer = ModuleLayer.empty().defineModules(cf, clf); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
420 |
Counters.add("jdk.module.boot.6.layerCreateTime", t6); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
421 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
422 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
423 |
// Step 7: Miscellaneous |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
424 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
425 |
// check incubating status |
52872 | 426 |
if (hasIncubatorModules || haveModulePath) { |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
427 |
checkIncubatingStatus(cf); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
428 |
} |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
429 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
430 |
// --add-reads, --add-exports/--add-opens, and --illegal-access |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
431 |
long t7 = System.nanoTime(); |
36511 | 432 |
addExtraReads(bootLayer); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
433 |
boolean extraExportsOrOpens = addExtraExportsAndOpens(bootLayer); |
52872 | 434 |
|
435 |
Map<String, Set<String>> concealedPackagesToOpen; |
|
436 |
Map<String, Set<String>> exportedPackagesToOpen; |
|
437 |
if (archivedModuleGraph != null) { |
|
438 |
concealedPackagesToOpen = archivedModuleGraph.concealedPackagesToOpen(); |
|
439 |
exportedPackagesToOpen = archivedModuleGraph.exportedPackagesToOpen(); |
|
440 |
} else { |
|
441 |
concealedPackagesToOpen = systemModules.concealedPackagesToOpen(); |
|
442 |
exportedPackagesToOpen = systemModules.exportedPackagesToOpen(); |
|
443 |
} |
|
444 |
addIllegalAccess(upgradeModulePath, |
|
445 |
concealedPackagesToOpen, |
|
446 |
exportedPackagesToOpen, |
|
447 |
bootLayer, |
|
448 |
extraExportsOrOpens); |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
449 |
Counters.add("jdk.module.boot.7.adjustModulesTime", t7); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
450 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
451 |
// save module finders for later use |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
452 |
if (savedModuleFinder != null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
453 |
unlimitedFinder = new SafeModuleFinder(savedModuleFinder); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
454 |
if (savedModuleFinder != finder) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
455 |
limitedFinder = new SafeModuleFinder(finder); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
456 |
} |
36511 | 457 |
|
51371
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
458 |
// Module graph can be archived at CDS dump time. Only allow the |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
459 |
// unnamed module case for now. |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
460 |
if (canArchive && (mainModule == null)) { |
52872 | 461 |
ArchivedModuleGraph.archive(mainModule, |
462 |
hasSplitPackages, |
|
463 |
hasIncubatorModules, |
|
464 |
systemModuleFinder, |
|
465 |
cf, |
|
466 |
concealedPackagesToOpen, |
|
467 |
exportedPackagesToOpen); |
|
51371
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
468 |
} |
3ab8b84e93cd
8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents:
51327
diff
changeset
|
469 |
|
36511 | 470 |
// total time to initialize |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
471 |
Counters.add("jdk.module.boot.totalTime", t0); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
472 |
Counters.publish(); |
36511 | 473 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
474 |
return bootLayer; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
475 |
} |
36511 | 476 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
477 |
/** |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
478 |
* Load/register the modules to the built-in class loaders. |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
479 |
*/ |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
480 |
private static void loadModules(Configuration cf, |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
481 |
Function<String, ClassLoader> clf) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
482 |
for (ResolvedModule resolvedModule : cf.modules()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
483 |
ModuleReference mref = resolvedModule.reference(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
484 |
String name = resolvedModule.name(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
485 |
ClassLoader loader = clf.apply(name); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
486 |
if (loader == null) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
487 |
// skip java.base as it is already loaded |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
488 |
if (!name.equals(JAVA_BASE)) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
489 |
BootLoader.loadModule(mref); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
490 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
491 |
} else if (loader instanceof BuiltinClassLoader) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
492 |
((BuiltinClassLoader) loader).loadModule(mref); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
493 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
494 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
495 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
496 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
497 |
/** |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
498 |
* Checks for split packages between modules defined to the built-in class |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
499 |
* loaders. |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
500 |
*/ |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
501 |
private static void checkSplitPackages(Configuration cf, |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
502 |
Function<String, ClassLoader> clf) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
503 |
Map<String, String> packageToModule = new HashMap<>(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
504 |
for (ResolvedModule resolvedModule : cf.modules()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
505 |
ModuleDescriptor descriptor = resolvedModule.reference().descriptor(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
506 |
String name = descriptor.name(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
507 |
ClassLoader loader = clf.apply(name); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
508 |
if (loader == null || loader instanceof BuiltinClassLoader) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
509 |
for (String p : descriptor.packages()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
510 |
String other = packageToModule.putIfAbsent(p, name); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
511 |
if (other != null) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
512 |
String msg = "Package " + p + " in both module " |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
513 |
+ name + " and module " + other; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
514 |
throw new LayerInstantiationException(msg); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
515 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
516 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
517 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
518 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
519 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
520 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
521 |
/** |
36511 | 522 |
* Returns a ModuleFinder that limits observability to the given root |
523 |
* modules, their transitive dependences, plus a set of other modules. |
|
524 |
*/ |
|
525 |
private static ModuleFinder limitFinder(ModuleFinder finder, |
|
526 |
Set<String> roots, |
|
527 |
Set<String> otherMods) |
|
528 |
{ |
|
529 |
// resolve all root modules |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
530 |
Configuration cf = Configuration.empty().resolve(finder, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
531 |
ModuleFinder.of(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
532 |
roots); |
36511 | 533 |
|
534 |
// module name -> reference |
|
535 |
Map<String, ModuleReference> map = new HashMap<>(); |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
536 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
537 |
// root modules and their transitive dependences |
36511 | 538 |
cf.modules().stream() |
539 |
.map(ResolvedModule::reference) |
|
540 |
.forEach(mref -> map.put(mref.descriptor().name(), mref)); |
|
541 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
542 |
// additional modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
543 |
otherMods.stream() |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
544 |
.map(finder::find) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
545 |
.flatMap(Optional::stream) |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
546 |
.forEach(mref -> map.putIfAbsent(mref.descriptor().name(), mref)); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
547 |
|
36511 | 548 |
// set of modules that are observable |
549 |
Set<ModuleReference> mrefs = new HashSet<>(map.values()); |
|
550 |
||
551 |
return new ModuleFinder() { |
|
552 |
@Override |
|
553 |
public Optional<ModuleReference> find(String name) { |
|
554 |
return Optional.ofNullable(map.get(name)); |
|
555 |
} |
|
556 |
@Override |
|
557 |
public Set<ModuleReference> findAll() { |
|
558 |
return mrefs; |
|
559 |
} |
|
560 |
}; |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* 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
|
565 |
* system property and optionally patched by --patch-module |
36511 | 566 |
*/ |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
567 |
private static ModuleFinder finderFor(String prop) { |
36511 | 568 |
String s = System.getProperty(prop); |
569 |
if (s == null) { |
|
570 |
return null; |
|
571 |
} else { |
|
572 |
String[] dirs = s.split(File.pathSeparator); |
|
573 |
Path[] paths = new Path[dirs.length]; |
|
574 |
int i = 0; |
|
575 |
for (String dir: dirs) { |
|
49285
4d2e3f5abb48
8194746: (fs) Add equivalents of Paths.get to Path interface
bpb
parents:
47471
diff
changeset
|
576 |
paths[i++] = Path.of(dir); |
36511 | 577 |
} |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
578 |
return ModulePath.of(patcher, paths); |
36511 | 579 |
} |
580 |
} |
|
581 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
582 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
583 |
* Initialize the module patcher for the initial configuration passed on the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
584 |
* value of the --patch-module options. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
585 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
586 |
private static ModulePatcher initModulePatcher() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
587 |
Map<String, List<String>> map = decode("jdk.module.patch.", |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
588 |
File.pathSeparator, |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
589 |
false); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
590 |
return new ModulePatcher(map); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
591 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
592 |
|
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
593 |
/** |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
594 |
* Returns the set of module names specified by --add-module options. |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
595 |
*/ |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
596 |
private static Set<String> addModules() { |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
597 |
String prefix = "jdk.module.addmods."; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
598 |
int index = 0; |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
599 |
// the system property is removed after decoding |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
600 |
String value = getAndRemoveProperty(prefix + index); |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
601 |
if (value == null) { |
51327
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
50951
diff
changeset
|
602 |
return Set.of(); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
603 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
604 |
Set<String> modules = new HashSet<>(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
605 |
while (value != null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
606 |
for (String s : value.split(",")) { |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52872
diff
changeset
|
607 |
if (!s.isEmpty()) |
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52872
diff
changeset
|
608 |
modules.add(s); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
609 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
610 |
index++; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
611 |
value = getAndRemoveProperty(prefix + index); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
612 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
613 |
return modules; |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
614 |
} |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
615 |
} |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
616 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
617 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
618 |
* Returns the set of module names specified by --limit-modules. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
619 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
620 |
private static Set<String> limitModules() { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
621 |
String value = getAndRemoveProperty("jdk.module.limitmods"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
622 |
if (value == null) { |
51327
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
50951
diff
changeset
|
623 |
return Set.of(); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
624 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
625 |
Set<String> names = new HashSet<>(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
626 |
for (String name : value.split(",")) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
627 |
if (name.length() > 0) names.add(name); |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
628 |
} |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
629 |
return names; |
41114
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
630 |
} |
f83e9aebbab4
8165634: Support multiple --add-modules options on the command line
hseigel
parents:
40261
diff
changeset
|
631 |
} |
36511 | 632 |
|
633 |
/** |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
634 |
* Process the --add-reads options to add any additional read edges that |
36511 | 635 |
* are specified on the command-line. |
636 |
*/ |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
637 |
private static void addExtraReads(ModuleLayer bootLayer) { |
36511 | 638 |
|
639 |
// decode the command line options |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
640 |
Map<String, List<String>> map = decode("jdk.module.addreads."); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
641 |
if (map.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
642 |
return; |
36511 | 643 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
644 |
for (Map.Entry<String, List<String>> e : map.entrySet()) { |
36511 | 645 |
|
646 |
// the key is $MODULE |
|
647 |
String mn = e.getKey(); |
|
648 |
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
|
649 |
if (!om.isPresent()) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
650 |
warnUnknownModule(ADD_READS, mn); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
651 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
652 |
} |
36511 | 653 |
Module m = om.get(); |
654 |
||
655 |
// the value is the set of other modules (by name) |
|
656 |
for (String name : e.getValue()) { |
|
657 |
if (ALL_UNNAMED.equals(name)) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
658 |
Modules.addReadsAllUnnamed(m); |
36511 | 659 |
} else { |
660 |
om = bootLayer.findModule(name); |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
661 |
if (om.isPresent()) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
662 |
Modules.addReads(m, om.get()); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
663 |
} else { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
664 |
warnUnknownModule(ADD_READS, name); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
665 |
} |
36511 | 666 |
} |
667 |
} |
|
668 |
} |
|
669 |
} |
|
670 |
||
671 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
672 |
* Process the --add-exports and --add-opens options to export/open |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
673 |
* additional packages specified on the command-line. |
36511 | 674 |
*/ |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
675 |
private static boolean addExtraExportsAndOpens(ModuleLayer bootLayer) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
676 |
boolean extraExportsOrOpens = false; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
677 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
678 |
// --add-exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
679 |
String prefix = "jdk.module.addexports."; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
680 |
Map<String, List<String>> extraExports = decode(prefix); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
681 |
if (!extraExports.isEmpty()) { |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
682 |
addExtraExportsOrOpens(bootLayer, extraExports, false); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
683 |
extraExportsOrOpens = true; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
684 |
} |
36511 | 685 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
686 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
687 |
// --add-opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
688 |
prefix = "jdk.module.addopens."; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
689 |
Map<String, List<String>> extraOpens = decode(prefix); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
690 |
if (!extraOpens.isEmpty()) { |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
691 |
addExtraExportsOrOpens(bootLayer, extraOpens, true); |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
692 |
extraExportsOrOpens = true; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
693 |
} |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42774
diff
changeset
|
694 |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
695 |
return extraExportsOrOpens; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
696 |
} |
36511 | 697 |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44364
diff
changeset
|
698 |
private static void addExtraExportsOrOpens(ModuleLayer bootLayer, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
699 |
Map<String, List<String>> map, |
44364
9cc9dc782213
8177474: Do not emit warnings when illegal access is allowed by --add-exports/--add-opens
alanb
parents:
44359
diff
changeset
|
700 |
boolean opens) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
701 |
{ |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
702 |
String option = opens ? ADD_OPENS : ADD_EXPORTS; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
703 |
for (Map.Entry<String, List<String>> e : map.entrySet()) { |
36511 | 704 |
|
705 |
// the key is $MODULE/$PACKAGE |
|
706 |
String key = e.getKey(); |
|
707 |
String[] s = key.split("/"); |
|
708 |
if (s.length != 2) |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43813
diff
changeset
|
709 |
fail(unableToParse(option, "<module>/<package>", key)); |
36511 | 710 |
|
711 |
String mn = s[0]; |
|
712 |
String pn = s[1]; |
|
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
713 |
if (mn.isEmpty() || pn.isEmpty()) |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43813
diff
changeset
|
714 |
fail(unableToParse(option, "<module>/<package>", key)); |
36511 | 715 |
|
716 |
// The exporting module is in the boot layer |
|
717 |
Module m; |
|
718 |
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
|
719 |
if (!om.isPresent()) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
720 |
warnUnknownModule(option, mn); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
721 |
continue; |
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 |
|
36511 | 724 |
m = om.get(); |
725 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
726 |
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
|
727 |
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
|
728 |
continue; |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
729 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
730 |
|
36511 | 731 |
// the value is the set of modules to export to (by name) |
732 |
for (String name : e.getValue()) { |
|
733 |
boolean allUnnamed = false; |
|
734 |
Module other = null; |
|
735 |
if (ALL_UNNAMED.equals(name)) { |
|
736 |
allUnnamed = true; |
|
737 |
} else { |
|
738 |
om = bootLayer.findModule(name); |
|
739 |
if (om.isPresent()) { |
|
740 |
other = om.get(); |
|
741 |
} else { |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
742 |
warnUnknownModule(option, name); |
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
743 |
continue; |
36511 | 744 |
} |
745 |
} |
|
746 |
if (allUnnamed) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
747 |
if (opens) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
748 |
Modules.addOpensToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
749 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
750 |
Modules.addExportsToAllUnnamed(m, pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
751 |
} |
36511 | 752 |
} else { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
753 |
if (opens) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
754 |
Modules.addOpens(m, pn, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
755 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
756 |
Modules.addExports(m, pn, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
757 |
} |
36511 | 758 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
759 |
|
36511 | 760 |
} |
761 |
} |
|
762 |
} |
|
763 |
||
764 |
/** |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
765 |
* Process the --illegal-access option (and its default) to open packages |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
766 |
* of system modules in the boot layer to code in unnamed modules. |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
767 |
*/ |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
768 |
private static void addIllegalAccess(ModuleFinder upgradeModulePath, |
52872 | 769 |
Map<String, Set<String>> concealedPackagesToOpen, |
770 |
Map<String, Set<String>> exportedPackagesToOpen, |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
771 |
ModuleLayer bootLayer, |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
772 |
boolean extraExportsOrOpens) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
773 |
String value = getAndRemoveProperty("jdk.module.illegalAccess"); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
774 |
IllegalAccessLogger.Mode mode = IllegalAccessLogger.Mode.ONESHOT; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
775 |
if (value != null) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
776 |
switch (value) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
777 |
case "deny": |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
778 |
return; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
779 |
case "permit": |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
780 |
break; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
781 |
case "warn": |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
782 |
mode = IllegalAccessLogger.Mode.WARN; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
783 |
break; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
784 |
case "debug": |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
785 |
mode = IllegalAccessLogger.Mode.DEBUG; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
786 |
break; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
787 |
default: |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
788 |
fail("Value specified to --illegal-access not recognized:" |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
789 |
+ " '" + value + "'"); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
790 |
return; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
791 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
792 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
793 |
IllegalAccessLogger.Builder builder |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
794 |
= new IllegalAccessLogger.Builder(mode, System.err); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
795 |
|
52872 | 796 |
if (concealedPackagesToOpen.isEmpty() && exportedPackagesToOpen.isEmpty()) { |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
797 |
// need to generate (exploded build) |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
798 |
IllegalAccessMaps maps = IllegalAccessMaps.generate(limitedFinder()); |
52872 | 799 |
concealedPackagesToOpen = maps.concealedPackagesToOpen(); |
800 |
exportedPackagesToOpen = maps.exportedPackagesToOpen(); |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
801 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
802 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
803 |
// open specific packages in the system modules |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
804 |
for (Module m : bootLayer.modules()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
805 |
ModuleDescriptor descriptor = m.getDescriptor(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
806 |
String name = m.getName(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
807 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
808 |
// skip open modules |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
809 |
if (descriptor.isOpen()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
810 |
continue; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
811 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
812 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
813 |
// skip modules loaded from the upgrade module path |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
814 |
if (upgradeModulePath != null |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
815 |
&& upgradeModulePath.find(name).isPresent()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
816 |
continue; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
817 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
818 |
|
52872 | 819 |
Set<String> concealedPackages = concealedPackagesToOpen.getOrDefault(name, Set.of()); |
820 |
Set<String> exportedPackages = exportedPackagesToOpen.getOrDefault(name, Set.of()); |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
821 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
822 |
// refresh the set of concealed and exported packages if needed |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
823 |
if (extraExportsOrOpens) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
824 |
concealedPackages = new HashSet<>(concealedPackages); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
825 |
exportedPackages = new HashSet<>(exportedPackages); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
826 |
Iterator<String> iterator = concealedPackages.iterator(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
827 |
while (iterator.hasNext()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
828 |
String pn = iterator.next(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
829 |
if (m.isExported(pn, BootLoader.getUnnamedModule())) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
830 |
// concealed package is exported to ALL-UNNAMED |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
831 |
iterator.remove(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
832 |
exportedPackages.add(pn); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
833 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
834 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
835 |
iterator = exportedPackages.iterator(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
836 |
while (iterator.hasNext()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
837 |
String pn = iterator.next(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
838 |
if (m.isOpen(pn, BootLoader.getUnnamedModule())) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
839 |
// exported package is opened to ALL-UNNAMED |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
840 |
iterator.remove(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
841 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
842 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
843 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
844 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
845 |
// log reflective access to all types in concealed packages |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
846 |
builder.logAccessToConcealedPackages(m, concealedPackages); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
847 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
848 |
// log reflective access to non-public members/types in exported packages |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
849 |
builder.logAccessToExportedPackages(m, exportedPackages); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
850 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
851 |
// open the packages to unnamed modules |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
852 |
JavaLangAccess jla = SharedSecrets.getJavaLangAccess(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
853 |
jla.addOpensToAllUnnamed(m, concat(concealedPackages.iterator(), |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
854 |
exportedPackages.iterator())); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
855 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
856 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
857 |
builder.complete(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
858 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
859 |
|
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
860 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
861 |
* Decodes the values of --add-reads, -add-exports, --add-opens or |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
862 |
* --patch-modules options that are encoded in system properties. |
36511 | 863 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
864 |
* @param prefix the system property prefix |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
865 |
* @praam regex the regex for splitting the RHS of the option value |
36511 | 866 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
867 |
private static Map<String, List<String>> decode(String prefix, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
868 |
String regex, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
869 |
boolean allowDuplicates) { |
36511 | 870 |
int index = 0; |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
871 |
// the system property is removed after decoding |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
872 |
String value = getAndRemoveProperty(prefix + index); |
36511 | 873 |
if (value == null) |
51327
a19fda433921
8209003: Consolidate use of empty collections in java.lang.module
redestad
parents:
50951
diff
changeset
|
874 |
return Map.of(); |
36511 | 875 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
876 |
Map<String, List<String>> map = new HashMap<>(); |
36511 | 877 |
|
878 |
while (value != null) { |
|
879 |
||
880 |
int pos = value.indexOf('='); |
|
881 |
if (pos == -1) |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
882 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 883 |
if (pos == 0) |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
884 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 885 |
|
886 |
// key is <module> or <module>/<package> |
|
887 |
String key = value.substring(0, pos); |
|
888 |
||
889 |
String rhs = value.substring(pos+1); |
|
890 |
if (rhs.isEmpty()) |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
891 |
fail(unableToParse(option(prefix), "<module>=<value>", value)); |
36511 | 892 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
893 |
// value is <module>(,<module>)* or <file>(<pathsep><file>)* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
894 |
if (!allowDuplicates && map.containsKey(key)) |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43813
diff
changeset
|
895 |
fail(key + " specified more than once to " + option(prefix)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
896 |
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
|
897 |
int ntargets = 0; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
898 |
for (String s : rhs.split(regex)) { |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52872
diff
changeset
|
899 |
if (!s.isEmpty()) { |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
900 |
values.add(s); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
901 |
ntargets++; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
902 |
} |
36511 | 903 |
} |
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
904 |
if (ntargets == 0) |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
905 |
fail("Target must be specified: " + option(prefix) + " " + value); |
36511 | 906 |
|
907 |
index++; |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
908 |
value = getAndRemoveProperty(prefix + index); |
36511 | 909 |
} |
910 |
||
911 |
return map; |
|
912 |
} |
|
913 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
914 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
915 |
* Decodes the values of --add-reads, -add-exports or --add-opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
916 |
* which use the "," to separate the RHS of the option value. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
917 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
918 |
private static Map<String, List<String>> decode(String prefix) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
919 |
return decode(prefix, ",", true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
920 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
921 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41414
diff
changeset
|
922 |
/** |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
923 |
* Gets and remove the named system property |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
924 |
*/ |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
925 |
private static String getAndRemoveProperty(String key) { |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
926 |
return (String)System.getProperties().remove(key); |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38457
diff
changeset
|
927 |
} |
36511 | 928 |
|
929 |
/** |
|
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
930 |
* Checks incubating status of modules in the configuration |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
931 |
*/ |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
932 |
private static void checkIncubatingStatus(Configuration cf) { |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
933 |
String incubating = null; |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
934 |
for (ResolvedModule resolvedModule : cf.modules()) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
935 |
ModuleReference mref = resolvedModule.reference(); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
936 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
937 |
// emit warning if the WARN_INCUBATING module resolution bit set |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
938 |
if (ModuleResolution.hasIncubatingWarning(mref)) { |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
939 |
String mn = mref.descriptor().name(); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
940 |
if (incubating == null) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
941 |
incubating = mn; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
942 |
} else { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
943 |
incubating += ", " + mn; |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
944 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
945 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
946 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
947 |
if (incubating != null) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
948 |
warn("Using incubator modules: " + incubating); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
949 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
950 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
951 |
/** |
36511 | 952 |
* Throws a RuntimeException with the given message |
953 |
*/ |
|
954 |
static void fail(String m) { |
|
955 |
throw new RuntimeException(m); |
|
956 |
} |
|
957 |
||
41414
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
958 |
static void warn(String m) { |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
959 |
System.err.println("WARNING: " + m); |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
960 |
} |
7fd4548e9733
8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents:
41114
diff
changeset
|
961 |
|
42774
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
962 |
static void warnUnknownModule(String option, String mn) { |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43813
diff
changeset
|
963 |
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
|
964 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
965 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
966 |
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
|
967 |
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
|
968 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
969 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
970 |
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
|
971 |
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
|
972 |
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
|
973 |
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
|
974 |
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
|
975 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
976 |
|
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
977 |
/* |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
978 |
* 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
|
979 |
* system property prefix. |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
980 |
*/ |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
981 |
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
|
982 |
switch (prefix) { |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
983 |
case "jdk.module.addexports.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
984 |
return ADD_EXPORTS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
985 |
case "jdk.module.addopens.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
986 |
return ADD_OPENS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
987 |
case "jdk.module.addreads.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
988 |
return ADD_READS; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
989 |
case "jdk.module.patch.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
990 |
return PATCH_MODULE; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
991 |
case "jdk.module.addmods.": |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
992 |
return ADD_MODULES; |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
993 |
default: |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
994 |
throw new IllegalArgumentException(prefix); |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
995 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
996 |
} |
74bcf37d15d8
8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
42770
diff
changeset
|
997 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
998 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
999 |
* Returns an iterator that yields all elements of the first iterator |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1000 |
* followed by all the elements of the second iterator. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1001 |
*/ |
45652
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1002 |
static <T> Iterator<T> concat(Iterator<T> iterator1, Iterator<T> iterator2) { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1003 |
return new Iterator<T>() { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1004 |
@Override |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1005 |
public boolean hasNext() { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1006 |
return iterator1.hasNext() || iterator2.hasNext(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1007 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1008 |
@Override |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1009 |
public T next() { |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1010 |
if (iterator1.hasNext()) return iterator1.next(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1011 |
if (iterator2.hasNext()) return iterator2.next(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1012 |
throw new NoSuchElementException(); |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1013 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1014 |
}; |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1015 |
} |
33342314ce89
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45004
diff
changeset
|
1016 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1017 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1018 |
* Wraps a (potentially not thread safe) ModuleFinder created during startup |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1019 |
* for use after startup. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1020 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1021 |
static class SafeModuleFinder implements ModuleFinder { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1022 |
private final Set<ModuleReference> mrefs; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1023 |
private volatile Map<String, ModuleReference> nameToModule; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1024 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1025 |
SafeModuleFinder(ModuleFinder finder) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1026 |
this.mrefs = Collections.unmodifiableSet(finder.findAll()); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1027 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1028 |
@Override |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1029 |
public Optional<ModuleReference> find(String name) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1030 |
Objects.requireNonNull(name); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1031 |
Map<String, ModuleReference> nameToModule = this.nameToModule; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1032 |
if (nameToModule == null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1033 |
this.nameToModule = nameToModule = mrefs.stream() |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1034 |
.collect(Collectors.toMap(m -> m.descriptor().name(), |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1035 |
Function.identity())); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1036 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1037 |
return Optional.ofNullable(nameToModule.get(name)); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1038 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1039 |
@Override |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1040 |
public Set<ModuleReference> findAll() { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1041 |
return mrefs; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1042 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1043 |
} |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
1044 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1045 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1046 |
* Counters for startup performance analysis. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1047 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1048 |
static class Counters { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1049 |
private static final boolean PUBLISH_COUNTERS; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1050 |
private static final boolean PRINT_COUNTERS; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1051 |
private static Map<String, Long> counters; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1052 |
static { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1053 |
String s = System.getProperty("jdk.module.boot.usePerfData"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1054 |
if (s == null) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1055 |
PUBLISH_COUNTERS = false; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1056 |
PRINT_COUNTERS = false; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1057 |
} else { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1058 |
PUBLISH_COUNTERS = true; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1059 |
PRINT_COUNTERS = s.equals("debug"); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1060 |
counters = new LinkedHashMap<>(); // preserve insert order |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1061 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1062 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1063 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1064 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1065 |
* Add a counter |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1066 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1067 |
static void add(String name, long start) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1068 |
if (PUBLISH_COUNTERS || PRINT_COUNTERS) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1069 |
counters.put(name, (System.nanoTime() - start)); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1070 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1071 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1072 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1073 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1074 |
* Publish the counters to the instrumentation buffer or stdout. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1075 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1076 |
static void publish() { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1077 |
if (PUBLISH_COUNTERS || PRINT_COUNTERS) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1078 |
for (Map.Entry<String, Long> e : counters.entrySet()) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1079 |
String name = e.getKey(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1080 |
long value = e.getValue(); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1081 |
if (PUBLISH_COUNTERS) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1082 |
PerfCounter.newPerfCounter(name).set(value); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1083 |
if (PRINT_COUNTERS) |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1084 |
System.out.println(name + " = " + value); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1085 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1086 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
45652
diff
changeset
|
1087 |
} |
36511 | 1088 |
} |
1089 |
} |