author | alanb |
Fri, 16 Dec 2016 06:19:16 +0000 | |
changeset 42703 | 20c39ea4a507 |
parent 42338 | a60f280f803c |
child 43532 | 5028c6b02af5 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.lang.reflect; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
30 |
import java.lang.annotation.Annotation; |
36511 | 31 |
import java.lang.module.Configuration; |
32 |
import java.lang.module.ModuleReference; |
|
33 |
import java.lang.module.ModuleDescriptor; |
|
34 |
import java.lang.module.ModuleDescriptor.Exports; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
35 |
import java.lang.module.ModuleDescriptor.Opens; |
36511 | 36 |
import java.lang.module.ModuleDescriptor.Version; |
37 |
import java.lang.module.ResolvedModule; |
|
38 |
import java.net.URI; |
|
39 |
import java.net.URL; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
40 |
import java.security.AccessController; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
41 |
import java.security.PrivilegedAction; |
36511 | 42 |
import java.util.Collections; |
43 |
import java.util.HashMap; |
|
44 |
import java.util.HashSet; |
|
45 |
import java.util.Map; |
|
46 |
import java.util.Objects; |
|
47 |
import java.util.Optional; |
|
48 |
import java.util.Set; |
|
49 |
import java.util.concurrent.ConcurrentHashMap; |
|
50 |
import java.util.function.Function; |
|
51 |
import java.util.stream.Stream; |
|
52 |
||
53 |
import jdk.internal.loader.BuiltinClassLoader; |
|
54 |
import jdk.internal.loader.BootLoader; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
55 |
import jdk.internal.loader.ResourceHelper; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
56 |
import jdk.internal.misc.JavaLangAccess; |
36511 | 57 |
import jdk.internal.misc.JavaLangReflectModuleAccess; |
58 |
import jdk.internal.misc.SharedSecrets; |
|
59 |
import jdk.internal.module.ServicesCatalog; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
60 |
import jdk.internal.org.objectweb.asm.AnnotationVisitor; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
61 |
import jdk.internal.org.objectweb.asm.Attribute; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
62 |
import jdk.internal.org.objectweb.asm.ClassReader; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
63 |
import jdk.internal.org.objectweb.asm.ClassVisitor; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
64 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
65 |
import jdk.internal.org.objectweb.asm.Opcodes; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
66 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36511
diff
changeset
|
67 |
import jdk.internal.reflect.Reflection; |
36511 | 68 |
import sun.security.util.SecurityConstants; |
69 |
||
70 |
/** |
|
71 |
* Represents a run-time module, either {@link #isNamed() named} or unnamed. |
|
72 |
* |
|
73 |
* <p> Named modules have a {@link #getName() name} and are constructed by the |
|
74 |
* Java Virtual Machine when a graph of modules is defined to the Java virtual |
|
75 |
* machine to create a module {@link Layer Layer}. </p> |
|
76 |
* |
|
77 |
* <p> An unnamed module does not have a name. There is an unnamed module |
|
78 |
* per {@link ClassLoader ClassLoader} that is obtained by invoking the class |
|
79 |
* loader's {@link ClassLoader#getUnnamedModule() getUnnamedModule} method. The |
|
80 |
* {@link Class#getModule() getModule} method of all types defined by a class |
|
81 |
* loader that are not in a named module return the class loader's unnamed |
|
82 |
* module. </p> |
|
83 |
* |
|
84 |
* <p> The package names that are parameters or returned by methods defined in |
|
85 |
* this class are the fully-qualified names of the packages as defined in |
|
86 |
* section 6.5.3 of <cite>The Java™ Language Specification </cite>, for |
|
87 |
* example, {@code "java.lang"}. </p> |
|
88 |
* |
|
89 |
* <p> Unless otherwise specified, passing a {@code null} argument to a method |
|
90 |
* in this class causes a {@link NullPointerException NullPointerException} to |
|
91 |
* be thrown. </p> |
|
92 |
* |
|
93 |
* @since 9 |
|
94 |
* @see java.lang.Class#getModule |
|
95 |
*/ |
|
96 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
97 |
public final class Module implements AnnotatedElement { |
36511 | 98 |
|
99 |
// the layer that contains this module, can be null |
|
100 |
private final Layer layer; |
|
101 |
||
102 |
// module name and loader, these fields are read by VM |
|
103 |
private final String name; |
|
104 |
private final ClassLoader loader; |
|
105 |
||
106 |
// the module descriptor |
|
107 |
private final ModuleDescriptor descriptor; |
|
108 |
||
109 |
||
110 |
/** |
|
111 |
* Creates a new named Module. The resulting Module will be defined to the |
|
112 |
* VM but will not read any other modules, will not have any exports setup |
|
113 |
* and will not be registered in the service catalog. |
|
114 |
*/ |
|
115 |
private Module(Layer layer, |
|
116 |
ClassLoader loader, |
|
117 |
ModuleDescriptor descriptor, |
|
118 |
URI uri) |
|
119 |
{ |
|
120 |
this.layer = layer; |
|
121 |
this.name = descriptor.name(); |
|
122 |
this.loader = loader; |
|
123 |
this.descriptor = descriptor; |
|
124 |
||
125 |
// define module to VM |
|
126 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
127 |
boolean isOpen = descriptor.isOpen(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
128 |
Version version = descriptor.version().orElse(null); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
129 |
String vs = Objects.toString(version, null); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
130 |
String loc = Objects.toString(uri, null); |
36511 | 131 |
Set<String> packages = descriptor.packages(); |
132 |
int n = packages.size(); |
|
133 |
String[] array = new String[n]; |
|
134 |
int i = 0; |
|
135 |
for (String pn : packages) { |
|
136 |
array[i++] = pn.replace('.', '/'); |
|
137 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
138 |
defineModule0(this, isOpen, vs, loc, array); |
36511 | 139 |
} |
140 |
||
141 |
||
142 |
/** |
|
143 |
* Create the unnamed Module for the given ClassLoader. |
|
144 |
* |
|
145 |
* @see ClassLoader#getUnnamedModule |
|
146 |
*/ |
|
147 |
private Module(ClassLoader loader) { |
|
148 |
this.layer = null; |
|
149 |
this.name = null; |
|
150 |
this.loader = loader; |
|
151 |
this.descriptor = null; |
|
152 |
} |
|
153 |
||
154 |
||
155 |
/** |
|
156 |
* Creates a named module but without defining the module to the VM. |
|
157 |
* |
|
158 |
* @apiNote This constructor is for VM white-box testing. |
|
159 |
*/ |
|
160 |
Module(ClassLoader loader, ModuleDescriptor descriptor) { |
|
161 |
this.layer = null; |
|
162 |
this.name = descriptor.name(); |
|
163 |
this.loader = loader; |
|
164 |
this.descriptor = descriptor; |
|
165 |
} |
|
166 |
||
167 |
||
168 |
||
169 |
/** |
|
170 |
* Returns {@code true} if this module is a named module. |
|
171 |
* |
|
172 |
* @return {@code true} if this is a named module |
|
173 |
* |
|
174 |
* @see ClassLoader#getUnnamedModule() |
|
175 |
*/ |
|
176 |
public boolean isNamed() { |
|
177 |
return name != null; |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Returns the module name or {@code null} if this module is an unnamed |
|
182 |
* module. |
|
183 |
* |
|
184 |
* @return The module name |
|
185 |
*/ |
|
186 |
public String getName() { |
|
187 |
return name; |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* Returns the {@code ClassLoader} for this module. |
|
192 |
* |
|
193 |
* <p> If there is a security manager then its {@code checkPermission} |
|
194 |
* method if first called with a {@code RuntimePermission("getClassLoader")} |
|
195 |
* permission to check that the caller is allowed to get access to the |
|
196 |
* class loader. </p> |
|
197 |
* |
|
198 |
* @return The class loader for this module |
|
199 |
* |
|
200 |
* @throws SecurityException |
|
201 |
* If denied by the security manager |
|
202 |
*/ |
|
203 |
public ClassLoader getClassLoader() { |
|
204 |
SecurityManager sm = System.getSecurityManager(); |
|
205 |
if (sm != null) { |
|
206 |
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); |
|
207 |
} |
|
208 |
return loader; |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Returns the module descriptor for this module or {@code null} if this |
|
213 |
* module is an unnamed module. |
|
214 |
* |
|
215 |
* @return The module descriptor for this module |
|
216 |
*/ |
|
217 |
public ModuleDescriptor getDescriptor() { |
|
218 |
return descriptor; |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Returns the layer that contains this module or {@code null} if this |
|
223 |
* module is not in a layer. |
|
224 |
* |
|
225 |
* A module {@code Layer} contains named modules and therefore this |
|
226 |
* method always returns {@code null} when invoked on an unnamed module. |
|
227 |
* |
|
228 |
* <p> <a href="Proxy.html#dynamicmodule">Dynamic modules</a> are named |
|
229 |
* modules that are generated at runtime. A dynamic module may or may |
|
230 |
* not be in a module Layer. </p> |
|
231 |
* |
|
232 |
* @return The layer that contains this module |
|
233 |
* |
|
234 |
* @see Proxy |
|
235 |
*/ |
|
236 |
public Layer getLayer() { |
|
237 |
if (isNamed()) { |
|
238 |
Layer layer = this.layer; |
|
239 |
if (layer != null) |
|
240 |
return layer; |
|
241 |
||
242 |
// special-case java.base as it is created before the boot Layer |
|
243 |
if (loader == null && name.equals("java.base")) { |
|
244 |
return SharedSecrets.getJavaLangAccess().getBootLayer(); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
return null; |
|
249 |
} |
|
250 |
||
251 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
252 |
// -- |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
253 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
254 |
// special Module to mean "all unnamed modules" |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
255 |
private static final Module ALL_UNNAMED_MODULE = new Module(null); |
36511 | 256 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
257 |
// special Module to mean "everyone" |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
258 |
private static final Module EVERYONE_MODULE = new Module(null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
259 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
260 |
// set contains EVERYONE_MODULE, used when a package is opened or |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
261 |
// exported unconditionally |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
262 |
private static final Set<Module> EVERYONE_SET = Set.of(EVERYONE_MODULE); |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
263 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
264 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
265 |
// -- readability -- |
36511 | 266 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
267 |
// the modules that this module reads |
36511 | 268 |
private volatile Set<Module> reads; |
269 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
270 |
// additional module (2nd key) that some module (1st key) reflectively reads |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
271 |
private static final WeakPairMap<Module, Module, Boolean> reflectivelyReads |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
272 |
= new WeakPairMap<>(); |
36511 | 273 |
|
274 |
||
275 |
/** |
|
276 |
* Indicates if this module reads the given module. This method returns |
|
277 |
* {@code true} if invoked to test if this module reads itself. It also |
|
278 |
* returns {@code true} if invoked on an unnamed module (as unnamed |
|
279 |
* modules read all modules). |
|
280 |
* |
|
281 |
* @param other |
|
282 |
* The other module |
|
283 |
* |
|
284 |
* @return {@code true} if this module reads {@code other} |
|
285 |
* |
|
286 |
* @see #addReads(Module) |
|
287 |
*/ |
|
288 |
public boolean canRead(Module other) { |
|
289 |
Objects.requireNonNull(other); |
|
290 |
||
291 |
// an unnamed module reads all modules |
|
292 |
if (!this.isNamed()) |
|
293 |
return true; |
|
294 |
||
295 |
// all modules read themselves |
|
296 |
if (other == this) |
|
297 |
return true; |
|
298 |
||
299 |
// check if this module reads other |
|
300 |
if (other.isNamed()) { |
|
301 |
Set<Module> reads = this.reads; // volatile read |
|
302 |
if (reads != null && reads.contains(other)) |
|
303 |
return true; |
|
304 |
} |
|
305 |
||
306 |
// check if this module reads the other module reflectively |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
307 |
if (reflectivelyReads.containsKeyPair(this, other)) |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
308 |
return true; |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
309 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
310 |
// if other is an unnamed module then check if this module reads |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
311 |
// all unnamed modules |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
312 |
if (!other.isNamed() |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
313 |
&& reflectivelyReads.containsKeyPair(this, ALL_UNNAMED_MODULE)) |
36511 | 314 |
return true; |
315 |
||
316 |
return false; |
|
317 |
} |
|
318 |
||
319 |
/** |
|
320 |
* If the caller's module is this module then update this module to read |
|
321 |
* the given module. |
|
322 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
323 |
* This method is a no-op if {@code other} is this module (all modules read |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
324 |
* themselves), this module is an unnamed module (as unnamed modules read |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
325 |
* all modules), or this module already reads {@code other}. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
326 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
327 |
* @implNote <em>Read edges</em> added by this method are <em>weak</em> and |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
328 |
* do not prevent {@code other} from being GC'ed when this module is |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
329 |
* strongly reachable. |
36511 | 330 |
* |
331 |
* @param other |
|
332 |
* The other module |
|
333 |
* |
|
334 |
* @return this module |
|
335 |
* |
|
336 |
* @throws IllegalStateException |
|
337 |
* If this is a named module and the caller is not this module |
|
338 |
* |
|
339 |
* @see #canRead |
|
340 |
*/ |
|
341 |
@CallerSensitive |
|
342 |
public Module addReads(Module other) { |
|
343 |
Objects.requireNonNull(other); |
|
344 |
if (this.isNamed()) { |
|
345 |
Module caller = Reflection.getCallerClass().getModule(); |
|
346 |
if (caller != this) { |
|
347 |
throw new IllegalStateException(caller + " != " + this); |
|
348 |
} |
|
349 |
implAddReads(other, true); |
|
350 |
} |
|
351 |
return this; |
|
352 |
} |
|
353 |
||
354 |
/** |
|
355 |
* Updates this module to read another module. |
|
356 |
* |
|
357 |
* @apiNote This method is for Proxy use and white-box testing. |
|
358 |
*/ |
|
359 |
void implAddReads(Module other) { |
|
360 |
implAddReads(other, true); |
|
361 |
} |
|
362 |
||
363 |
/** |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
364 |
* Updates this module to read another module without notifying the VM. |
36511 | 365 |
* |
366 |
* @apiNote This method is for VM white-box testing. |
|
367 |
*/ |
|
368 |
void implAddReadsNoSync(Module other) { |
|
369 |
implAddReads(other, false); |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Makes the given {@code Module} readable to this module. |
|
374 |
* |
|
375 |
* If {@code syncVM} is {@code true} then the VM is notified. |
|
376 |
*/ |
|
377 |
private void implAddReads(Module other, boolean syncVM) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
378 |
Objects.requireNonNull(other); |
36511 | 379 |
|
380 |
// nothing to do |
|
381 |
if (other == this || !this.isNamed()) |
|
382 |
return; |
|
383 |
||
384 |
// check if we already read this module |
|
385 |
Set<Module> reads = this.reads; |
|
386 |
if (reads != null && reads.contains(other)) |
|
387 |
return; |
|
388 |
||
389 |
// update VM first, just in case it fails |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
390 |
if (syncVM) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
391 |
if (other == ALL_UNNAMED_MODULE) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
392 |
addReads0(this, null); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
393 |
} else { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
394 |
addReads0(this, other); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
395 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
396 |
} |
36511 | 397 |
|
398 |
// add reflective read |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
399 |
reflectivelyReads.putIfAbsent(this, other, Boolean.TRUE); |
36511 | 400 |
} |
401 |
||
402 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
403 |
// -- exported and open packages -- |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
404 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
405 |
// the packages are open to other modules, can be null |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
406 |
// if the value contains EVERYONE_MODULE then the package is open to all |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
407 |
private volatile Map<String, Set<Module>> openPackages; |
36511 | 408 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
409 |
// the packages that are exported, can be null |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
410 |
// if the value contains EVERYONE_MODULE then the package is exported to all |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
411 |
private volatile Map<String, Set<Module>> exportedPackages; |
36511 | 412 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
413 |
// additional exports or opens added at run-time |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
414 |
// this module (1st key), other module (2nd key) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
415 |
// (package name, open?) (value) |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
416 |
private static final WeakPairMap<Module, Module, Map<String, Boolean>> |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
417 |
reflectivelyExports = new WeakPairMap<>(); |
36511 | 418 |
|
419 |
||
420 |
/** |
|
421 |
* Returns {@code true} if this module exports the given package to at |
|
422 |
* least the given module. |
|
423 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
424 |
* <p> This method returns {@code true} if invoked to test if a package in |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
425 |
* this module is exported to itself. It always returns {@code true} when |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
426 |
* invoked on an unnamed module. A package that is {@link #isOpen open} to |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
427 |
* the given module is considered exported to that module at run-time and |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
428 |
* so this method returns {@code true} if the package is open to the given |
36511 | 429 |
* module. </p> |
430 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
431 |
* <p> This method does not check if the given module reads this module. </p> |
36511 | 432 |
* |
433 |
* @param pn |
|
434 |
* The package name |
|
435 |
* @param other |
|
436 |
* The other module |
|
437 |
* |
|
438 |
* @return {@code true} if this module exports the package to at least the |
|
439 |
* given module |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
440 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
441 |
* @see ModuleDescriptor#exports() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
442 |
* @see #addExports(String,Module) |
36511 | 443 |
*/ |
444 |
public boolean isExported(String pn, Module other) { |
|
445 |
Objects.requireNonNull(pn); |
|
446 |
Objects.requireNonNull(other); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
447 |
return implIsExportedOrOpen(pn, other, /*open*/false); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
448 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
449 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
450 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
451 |
* Returns {@code true} if this module has <em>opened</em> a package to at |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
452 |
* least the given module. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
453 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
454 |
* <p> This method returns {@code true} if invoked to test if a package in |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
455 |
* this module is open to itself. It returns {@code true} when invoked on an |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
456 |
* {@link ModuleDescriptor#isOpen open} module with a package in the module. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
457 |
* It always returns {@code true} when invoked on an unnamed module. </p> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
458 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
459 |
* <p> This method does not check if the given module reads this module. </p> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
460 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
461 |
* @param pn |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
462 |
* The package name |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
463 |
* @param other |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
464 |
* The other module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
465 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
466 |
* @return {@code true} if this module has <em>opened</em> the package |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
467 |
* to at least the given module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
468 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
469 |
* @see ModuleDescriptor#opens() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
470 |
* @see #addOpens(String,Module) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
471 |
* @see AccessibleObject#setAccessible(boolean) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
472 |
* @see java.lang.invoke.MethodHandles#privateLookupIn |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
473 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
474 |
public boolean isOpen(String pn, Module other) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
475 |
Objects.requireNonNull(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
476 |
Objects.requireNonNull(other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
477 |
return implIsExportedOrOpen(pn, other, /*open*/true); |
36511 | 478 |
} |
479 |
||
480 |
/** |
|
481 |
* Returns {@code true} if this module exports the given package |
|
482 |
* unconditionally. |
|
483 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
484 |
* <p> This method always returns {@code true} when invoked on an unnamed |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
485 |
* module. A package that is {@link #isOpen(String) opened} unconditionally |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
486 |
* is considered exported unconditionally at run-time and so this method |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
487 |
* returns {@code true} if the package is opened unconditionally. </p> |
36511 | 488 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
489 |
* <p> This method does not check if the given module reads this module. </p> |
36511 | 490 |
* |
491 |
* @param pn |
|
492 |
* The package name |
|
493 |
* |
|
494 |
* @return {@code true} if this module exports the package unconditionally |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
495 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
496 |
* @see ModuleDescriptor#exports() |
36511 | 497 |
*/ |
498 |
public boolean isExported(String pn) { |
|
499 |
Objects.requireNonNull(pn); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
500 |
return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/false); |
36511 | 501 |
} |
502 |
||
503 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
504 |
* Returns {@code true} if this module has <em>opened</em> a package |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
505 |
* unconditionally. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
506 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
507 |
* <p> This method always returns {@code true} when invoked on an unnamed |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
508 |
* module. Additionally, it always returns {@code true} when invoked on an |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
509 |
* {@link ModuleDescriptor#isOpen open} module with a package in the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
510 |
* module. </p> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
511 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
512 |
* <p> This method does not check if the given module reads this module. </p> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
513 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
514 |
* @param pn |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
515 |
* The package name |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
516 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
517 |
* @return {@code true} if this module has <em>opened</em> the package |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
518 |
* unconditionally |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
519 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
520 |
* @see ModuleDescriptor#opens() |
36511 | 521 |
*/ |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
522 |
public boolean isOpen(String pn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
523 |
Objects.requireNonNull(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
524 |
return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
525 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
526 |
|
36511 | 527 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
528 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
529 |
* Returns {@code true} if this module exports or opens the given package |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
530 |
* to the given module. If the other module is {@code EVERYONE_MODULE} then |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
531 |
* this method tests if the package is exported or opened unconditionally. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
532 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
533 |
private boolean implIsExportedOrOpen(String pn, Module other, boolean open) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
534 |
// all packages in unnamed modules are open |
36511 | 535 |
if (!isNamed()) |
536 |
return true; |
|
537 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
538 |
// all packages are exported/open to self |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
539 |
if (other == this && containsPackage(pn)) |
36511 | 540 |
return true; |
541 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
542 |
// all packages in open modules are open |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
543 |
if (descriptor.isOpen()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
544 |
return containsPackage(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
545 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
546 |
// exported/opened via module declaration/descriptor |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
547 |
if (isStaticallyExportedOrOpen(pn, other, open)) |
36511 | 548 |
return true; |
549 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
550 |
// exported via addExports/addOpens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
551 |
if (isReflectivelyExportedOrOpen(pn, other, open)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
552 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
553 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
554 |
// not exported or open to other |
36511 | 555 |
return false; |
556 |
} |
|
557 |
||
558 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
559 |
* Returns {@code true} if this module exports or opens a package to |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
560 |
* the given module via its module declaration. |
36511 | 561 |
*/ |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
562 |
boolean isStaticallyExportedOrOpen(String pn, Module other, boolean open) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
563 |
// package is open to everyone or <other> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
564 |
Map<String, Set<Module>> openPackages = this.openPackages; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
565 |
if (openPackages != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
566 |
Set<Module> targets = openPackages.get(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
567 |
if (targets != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
568 |
if (targets.contains(EVERYONE_MODULE)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
569 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
570 |
if (other != EVERYONE_MODULE && targets.contains(other)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
571 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
572 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
573 |
} |
36511 | 574 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
575 |
if (!open) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
576 |
// package is exported to everyone or <other> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
577 |
Map<String, Set<Module>> exportedPackages = this.exportedPackages; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
578 |
if (exportedPackages != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
579 |
Set<Module> targets = exportedPackages.get(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
580 |
if (targets != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
581 |
if (targets.contains(EVERYONE_MODULE)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
582 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
583 |
if (other != EVERYONE_MODULE && targets.contains(other)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
584 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
585 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
586 |
} |
36511 | 587 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
588 |
|
36511 | 589 |
return false; |
590 |
} |
|
591 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
592 |
|
36511 | 593 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
594 |
* Returns {@code true} if this module reflectively exports or opens given |
36511 | 595 |
* package package to the given module. |
596 |
*/ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
597 |
private boolean isReflectivelyExportedOrOpen(String pn, Module other, boolean open) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
598 |
// exported or open to all modules |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
599 |
Map<String, Boolean> exports = reflectivelyExports.get(this, EVERYONE_MODULE); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
600 |
if (exports != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
601 |
Boolean b = exports.get(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
602 |
if (b != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
603 |
boolean isOpen = b.booleanValue(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
604 |
if (!open || isOpen) return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
605 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
606 |
} |
36511 | 607 |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
608 |
if (other != EVERYONE_MODULE) { |
36511 | 609 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
610 |
// exported or open to other |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
611 |
exports = reflectivelyExports.get(this, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
612 |
if (exports != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
613 |
Boolean b = exports.get(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
614 |
if (b != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
615 |
boolean isOpen = b.booleanValue(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
616 |
if (!open || isOpen) return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
617 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
618 |
} |
36511 | 619 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
620 |
// other is an unnamed module && exported or open to all unnamed |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
621 |
if (!other.isNamed()) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
622 |
exports = reflectivelyExports.get(this, ALL_UNNAMED_MODULE); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
623 |
if (exports != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
624 |
Boolean b = exports.get(pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
625 |
if (b != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
626 |
boolean isOpen = b.booleanValue(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
627 |
if (!open || isOpen) return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
628 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
629 |
} |
36511 | 630 |
} |
631 |
||
632 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
633 |
|
36511 | 634 |
return false; |
635 |
} |
|
636 |
||
637 |
||
638 |
/** |
|
639 |
* If the caller's module is this module then update this module to export |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
640 |
* the given package to the given module. |
36511 | 641 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
642 |
* <p> This method has no effect if the package is already exported (or |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
643 |
* <em>open</em>) to the given module. It also has no effect if |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
644 |
* invoked on an {@link ModuleDescriptor#isOpen open} module. </p> |
36511 | 645 |
* |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
646 |
* @apiNote As specified in section 5.4.3 of the <cite>The Java™ |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
647 |
* Virtual Machine Specification </cite>, if an attempt to resolve a |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
648 |
* symbolic reference fails because of a linkage error, then subsequent |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
649 |
* attempts to resolve the reference always fail with the same error that |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
650 |
* was thrown as a result of the initial resolution attempt. |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
651 |
* |
36511 | 652 |
* @param pn |
653 |
* The package name |
|
654 |
* @param other |
|
655 |
* The module |
|
656 |
* |
|
657 |
* @return this module |
|
658 |
* |
|
659 |
* @throws IllegalArgumentException |
|
660 |
* If {@code pn} is {@code null}, or this is a named module and the |
|
661 |
* package {@code pn} is not a package in this module |
|
662 |
* @throws IllegalStateException |
|
663 |
* If this is a named module and the caller is not this module |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
664 |
* |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
665 |
* @jvms 5.4.3 Resolution |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
666 |
* @see #isExported(String,Module) |
36511 | 667 |
*/ |
668 |
@CallerSensitive |
|
669 |
public Module addExports(String pn, Module other) { |
|
670 |
if (pn == null) |
|
671 |
throw new IllegalArgumentException("package is null"); |
|
672 |
Objects.requireNonNull(other); |
|
673 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
674 |
if (isNamed() && !descriptor.isOpen()) { |
36511 | 675 |
Module caller = Reflection.getCallerClass().getModule(); |
676 |
if (caller != this) { |
|
677 |
throw new IllegalStateException(caller + " != " + this); |
|
678 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
679 |
implAddExportsOrOpens(pn, other, /*open*/false, /*syncVM*/true); |
36511 | 680 |
} |
681 |
||
682 |
return this; |
|
683 |
} |
|
684 |
||
685 |
/** |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
686 |
* If this module has <em>opened</em> a package to at least the caller |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
687 |
* module then update this module to open the package to the given module. |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
688 |
* Opening a package with this method allows all types in the package, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
689 |
* and all their members, not just public types and their public members, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
690 |
* to be reflected on by the given module when using APIs that support |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
691 |
* private access or a way to bypass or suppress default Java language |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
692 |
* access control checks. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
693 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
694 |
* <p> This method has no effect if the package is already <em>open</em> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
695 |
* to the given module. It also has no effect if invoked on an {@link |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
696 |
* ModuleDescriptor#isOpen open} module. </p> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
697 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
698 |
* @param pn |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
699 |
* The package name |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
700 |
* @param other |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
701 |
* The module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
702 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
703 |
* @return this module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
704 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
705 |
* @throws IllegalArgumentException |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
706 |
* If {@code pn} is {@code null}, or this is a named module and the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
707 |
* package {@code pn} is not a package in this module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
708 |
* @throws IllegalStateException |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
709 |
* If this is a named module and this module has not opened the |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
710 |
* package to at least the caller |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
711 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
712 |
* @see #isOpen(String,Module) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
713 |
* @see AccessibleObject#setAccessible(boolean) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
714 |
* @see java.lang.invoke.MethodHandles#privateLookupIn |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
715 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
716 |
@CallerSensitive |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
717 |
public Module addOpens(String pn, Module other) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
718 |
if (pn == null) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
719 |
throw new IllegalArgumentException("package is null"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
720 |
Objects.requireNonNull(other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
721 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
722 |
if (isNamed() && !descriptor.isOpen()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
723 |
Module caller = Reflection.getCallerClass().getModule(); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
724 |
if (caller != this && !isOpen(pn, caller)) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
725 |
throw new IllegalStateException(pn + " is not open to " + caller); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
726 |
implAddExportsOrOpens(pn, other, /*open*/true, /*syncVM*/true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
727 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
728 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
729 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
730 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
731 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
732 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
733 |
/** |
36511 | 734 |
* Updates the exports so that package {@code pn} is exported to module |
735 |
* {@code other} but without notifying the VM. |
|
736 |
* |
|
737 |
* @apiNote This method is for VM white-box testing. |
|
738 |
*/ |
|
739 |
void implAddExportsNoSync(String pn, Module other) { |
|
740 |
if (other == null) |
|
741 |
other = EVERYONE_MODULE; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
742 |
implAddExportsOrOpens(pn.replace('/', '.'), other, false, false); |
36511 | 743 |
} |
744 |
||
745 |
/** |
|
746 |
* Updates the exports so that package {@code pn} is exported to module |
|
747 |
* {@code other}. |
|
748 |
* |
|
749 |
* @apiNote This method is for white-box testing. |
|
750 |
*/ |
|
751 |
void implAddExports(String pn, Module other) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
752 |
implAddExportsOrOpens(pn, other, false, true); |
36511 | 753 |
} |
754 |
||
755 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
756 |
* Updates the module to open package {@code pn} to module {@code other}. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
757 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
758 |
* @apiNote This method is for white-box tests and jtreg |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
759 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
760 |
void implAddOpens(String pn, Module other) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
761 |
implAddExportsOrOpens(pn, other, true, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
762 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
763 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
764 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
765 |
* Updates a module to export or open a module to another module. |
36511 | 766 |
* |
767 |
* If {@code syncVM} is {@code true} then the VM is notified. |
|
768 |
*/ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
769 |
private void implAddExportsOrOpens(String pn, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
770 |
Module other, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
771 |
boolean open, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
772 |
boolean syncVM) { |
36511 | 773 |
Objects.requireNonNull(other); |
774 |
Objects.requireNonNull(pn); |
|
775 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
776 |
// all packages are open in unnamed and open modules |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
777 |
if (!isNamed() || descriptor.isOpen()) |
36511 | 778 |
return; |
779 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
780 |
// nothing to do if already exported/open to other |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
781 |
if (implIsExportedOrOpen(pn, other, open)) |
36511 | 782 |
return; |
783 |
||
784 |
// can only export a package in the module |
|
785 |
if (!containsPackage(pn)) { |
|
786 |
throw new IllegalArgumentException("package " + pn |
|
787 |
+ " not in contents"); |
|
788 |
} |
|
789 |
||
790 |
// update VM first, just in case it fails |
|
791 |
if (syncVM) { |
|
792 |
String pkgInternalForm = pn.replace('.', '/'); |
|
793 |
if (other == EVERYONE_MODULE) { |
|
794 |
addExportsToAll0(this, pkgInternalForm); |
|
795 |
} else if (other == ALL_UNNAMED_MODULE) { |
|
796 |
addExportsToAllUnnamed0(this, pkgInternalForm); |
|
797 |
} else { |
|
798 |
addExports0(this, pkgInternalForm, other); |
|
799 |
} |
|
800 |
} |
|
801 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
802 |
// add package name to reflectivelyExports if absent |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
803 |
Map<String, Boolean> map = reflectivelyExports |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
804 |
.computeIfAbsent(this, other, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
805 |
(m1, m2) -> new ConcurrentHashMap<>()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
806 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
807 |
if (open) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
808 |
map.put(pn, Boolean.TRUE); // may need to promote from FALSE to TRUE |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
809 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
810 |
map.putIfAbsent(pn, Boolean.FALSE); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
811 |
} |
36511 | 812 |
} |
813 |
||
814 |
||
815 |
// -- services -- |
|
816 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
817 |
// additional service type (2nd key) that some module (1st key) uses |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
818 |
private static final WeakPairMap<Module, Class<?>, Boolean> reflectivelyUses |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
819 |
= new WeakPairMap<>(); |
36511 | 820 |
|
821 |
/** |
|
822 |
* If the caller's module is this module then update this module to add a |
|
823 |
* service dependence on the given service type. This method is intended |
|
824 |
* for use by frameworks that invoke {@link java.util.ServiceLoader |
|
825 |
* ServiceLoader} on behalf of other modules or where the framework is |
|
826 |
* passed a reference to the service type by other code. This method is |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
827 |
* a no-op when invoked on an unnamed module or an automatic module. |
36511 | 828 |
* |
829 |
* <p> This method does not cause {@link |
|
830 |
* Configuration#resolveRequiresAndUses resolveRequiresAndUses} to be |
|
831 |
* re-run. </p> |
|
832 |
* |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
833 |
* @param service |
36511 | 834 |
* The service type |
835 |
* |
|
836 |
* @return this module |
|
837 |
* |
|
838 |
* @throws IllegalStateException |
|
839 |
* If this is a named module and the caller is not this module |
|
840 |
* |
|
841 |
* @see #canUse(Class) |
|
842 |
* @see ModuleDescriptor#uses() |
|
843 |
*/ |
|
844 |
@CallerSensitive |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
845 |
public Module addUses(Class<?> service) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
846 |
Objects.requireNonNull(service); |
36511 | 847 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
848 |
if (isNamed() && !descriptor.isAutomatic()) { |
36511 | 849 |
Module caller = Reflection.getCallerClass().getModule(); |
850 |
if (caller != this) { |
|
851 |
throw new IllegalStateException(caller + " != " + this); |
|
852 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
853 |
implAddUses(service); |
36511 | 854 |
} |
855 |
||
856 |
return this; |
|
857 |
} |
|
858 |
||
859 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
860 |
* Update this module to add a service dependence on the given service |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
861 |
* type. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
862 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
863 |
void implAddUses(Class<?> service) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
864 |
if (!canUse(service)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
865 |
reflectivelyUses.putIfAbsent(this, service, Boolean.TRUE); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
866 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
867 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
868 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
869 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
870 |
/** |
36511 | 871 |
* Indicates if this module has a service dependence on the given service |
872 |
* type. This method always returns {@code true} when invoked on an unnamed |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
873 |
* module or an automatic module. |
36511 | 874 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
875 |
* @param service |
36511 | 876 |
* The service type |
877 |
* |
|
878 |
* @return {@code true} if this module uses service type {@code st} |
|
879 |
* |
|
880 |
* @see #addUses(Class) |
|
881 |
*/ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
882 |
public boolean canUse(Class<?> service) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
883 |
Objects.requireNonNull(service); |
36511 | 884 |
|
885 |
if (!isNamed()) |
|
886 |
return true; |
|
887 |
||
888 |
if (descriptor.isAutomatic()) |
|
889 |
return true; |
|
890 |
||
891 |
// uses was declared |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
892 |
if (descriptor.uses().contains(service.getName())) |
36511 | 893 |
return true; |
894 |
||
895 |
// uses added via addUses |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
896 |
return reflectivelyUses.containsKeyPair(this, service); |
36511 | 897 |
} |
898 |
||
899 |
||
900 |
||
901 |
// -- packages -- |
|
902 |
||
903 |
// Additional packages that are added to the module at run-time. |
|
904 |
// The field is volatile as it may be replaced at run-time |
|
905 |
private volatile Set<String> extraPackages; |
|
906 |
||
907 |
private boolean containsPackage(String pn) { |
|
908 |
if (descriptor.packages().contains(pn)) |
|
909 |
return true; |
|
910 |
Set<String> extraPackages = this.extraPackages; |
|
911 |
if (extraPackages != null && extraPackages.contains(pn)) |
|
912 |
return true; |
|
913 |
return false; |
|
914 |
} |
|
915 |
||
916 |
||
917 |
/** |
|
918 |
* Returns an array of the package names of the packages in this module. |
|
919 |
* |
|
920 |
* <p> For named modules, the returned array contains an element for each |
|
921 |
* package in the module. It may contain elements corresponding to packages |
|
922 |
* added to the module, <a href="Proxy.html#dynamicmodule">dynamic modules</a> |
|
923 |
* for example, after it was loaded. |
|
924 |
* |
|
925 |
* <p> For unnamed modules, this method is the equivalent of invoking the |
|
926 |
* {@link ClassLoader#getDefinedPackages() getDefinedPackages} method of |
|
927 |
* this module's class loader and returning the array of package names. </p> |
|
928 |
* |
|
929 |
* <p> A package name appears at most once in the returned array. </p> |
|
930 |
* |
|
931 |
* @apiNote This method returns an array rather than a {@code Set} for |
|
932 |
* consistency with other {@code java.lang.reflect} types. |
|
933 |
* |
|
934 |
* @return an array of the package names of the packages in this module |
|
935 |
*/ |
|
936 |
public String[] getPackages() { |
|
937 |
if (isNamed()) { |
|
938 |
||
939 |
Set<String> packages = descriptor.packages(); |
|
940 |
Set<String> extraPackages = this.extraPackages; |
|
941 |
if (extraPackages == null) { |
|
942 |
return packages.toArray(new String[0]); |
|
943 |
} else { |
|
944 |
return Stream.concat(packages.stream(), |
|
945 |
extraPackages.stream()) |
|
946 |
.toArray(String[]::new); |
|
947 |
} |
|
948 |
||
949 |
} else { |
|
950 |
// unnamed module |
|
951 |
Stream<Package> packages; |
|
952 |
if (loader == null) { |
|
953 |
packages = BootLoader.packages(); |
|
954 |
} else { |
|
955 |
packages = SharedSecrets.getJavaLangAccess().packages(loader); |
|
956 |
} |
|
957 |
return packages.map(Package::getName).toArray(String[]::new); |
|
958 |
} |
|
959 |
} |
|
960 |
||
961 |
/** |
|
962 |
* Add a package to this module. |
|
963 |
* |
|
964 |
* @apiNote This method is for Proxy use. |
|
965 |
* |
|
966 |
* @apiNote This is an expensive operation, not expected to be used often. |
|
967 |
* At this time then it does not validate that the package name is a |
|
968 |
* valid java identifier. |
|
969 |
*/ |
|
970 |
void addPackage(String pn) { |
|
971 |
implAddPackage(pn, true); |
|
972 |
} |
|
973 |
||
974 |
/** |
|
975 |
* Add a package to this module without notifying the VM. |
|
976 |
* |
|
977 |
* @apiNote This method is VM white-box testing. |
|
978 |
*/ |
|
979 |
void implAddPackageNoSync(String pn) { |
|
980 |
implAddPackage(pn.replace('/', '.'), false); |
|
981 |
} |
|
982 |
||
983 |
/** |
|
984 |
* Add a package to this module. |
|
985 |
* |
|
986 |
* If {@code syncVM} is {@code true} then the VM is notified. |
|
987 |
*/ |
|
988 |
private void implAddPackage(String pn, boolean syncVM) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
989 |
if (!isNamed()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
990 |
throw new InternalError("adding package to unnamed module?"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
991 |
if (descriptor.isOpen()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
992 |
throw new InternalError("adding package to open module?"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
993 |
if (pn.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
994 |
throw new InternalError("adding <unnamed> package to module?"); |
36511 | 995 |
|
996 |
if (descriptor.packages().contains(pn)) { |
|
997 |
// already in module |
|
998 |
return; |
|
999 |
} |
|
1000 |
||
1001 |
Set<String> extraPackages = this.extraPackages; |
|
1002 |
if (extraPackages != null && extraPackages.contains(pn)) { |
|
1003 |
// already added |
|
1004 |
return; |
|
1005 |
} |
|
1006 |
synchronized (this) { |
|
1007 |
// recheck under lock |
|
1008 |
extraPackages = this.extraPackages; |
|
1009 |
if (extraPackages != null) { |
|
1010 |
if (extraPackages.contains(pn)) { |
|
1011 |
// already added |
|
1012 |
return; |
|
1013 |
} |
|
1014 |
||
1015 |
// copy the set |
|
1016 |
extraPackages = new HashSet<>(extraPackages); |
|
1017 |
extraPackages.add(pn); |
|
1018 |
} else { |
|
1019 |
extraPackages = Collections.singleton(pn); |
|
1020 |
} |
|
1021 |
||
1022 |
// update VM first, just in case it fails |
|
1023 |
if (syncVM) |
|
1024 |
addPackage0(this, pn.replace('.', '/')); |
|
1025 |
||
1026 |
// replace with new set |
|
1027 |
this.extraPackages = extraPackages; // volatile write |
|
1028 |
} |
|
1029 |
} |
|
1030 |
||
1031 |
||
1032 |
// -- creating Module objects -- |
|
1033 |
||
1034 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1035 |
* Defines all module in a configuration to the runtime. |
36511 | 1036 |
* |
1037 |
* @return a map of module name to runtime {@code Module} |
|
1038 |
* |
|
1039 |
* @throws IllegalArgumentException |
|
1040 |
* If defining any of the modules to the VM fails |
|
1041 |
*/ |
|
1042 |
static Map<String, Module> defineModules(Configuration cf, |
|
1043 |
Function<String, ClassLoader> clf, |
|
1044 |
Layer layer) |
|
1045 |
{ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1046 |
Map<String, Module> nameToModule = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1047 |
Map<String, ClassLoader> moduleToLoader = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1048 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1049 |
boolean isBootLayer = (Layer.boot() == null); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1050 |
Set<ClassLoader> loaders = new HashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1051 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1052 |
// map each module to a class loader |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1053 |
for (ResolvedModule resolvedModule : cf.modules()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1054 |
String name = resolvedModule.name(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1055 |
ClassLoader loader = clf.apply(name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1056 |
if (loader != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1057 |
moduleToLoader.put(name, loader); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1058 |
loaders.add(loader); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1059 |
} else if (!isBootLayer) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1060 |
throw new IllegalArgumentException("loader can't be 'null'"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1061 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1062 |
} |
36511 | 1063 |
|
1064 |
// define each module in the configuration to the VM |
|
1065 |
for (ResolvedModule resolvedModule : cf.modules()) { |
|
1066 |
ModuleReference mref = resolvedModule.reference(); |
|
1067 |
ModuleDescriptor descriptor = mref.descriptor(); |
|
1068 |
String name = descriptor.name(); |
|
1069 |
URI uri = mref.location().orElse(null); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1070 |
ClassLoader loader = moduleToLoader.get(resolvedModule.name()); |
36511 | 1071 |
Module m; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1072 |
if (loader == null && isBootLayer && name.equals("java.base")) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1073 |
// java.base is already defined to the VM |
36511 | 1074 |
m = Object.class.getModule(); |
1075 |
} else { |
|
1076 |
m = new Module(layer, loader, descriptor, uri); |
|
1077 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1078 |
nameToModule.put(name, m); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1079 |
moduleToLoader.put(name, loader); |
36511 | 1080 |
} |
1081 |
||
1082 |
// setup readability and exports |
|
1083 |
for (ResolvedModule resolvedModule : cf.modules()) { |
|
1084 |
ModuleReference mref = resolvedModule.reference(); |
|
1085 |
ModuleDescriptor descriptor = mref.descriptor(); |
|
1086 |
||
1087 |
String mn = descriptor.name(); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1088 |
Module m = nameToModule.get(mn); |
36511 | 1089 |
assert m != null; |
1090 |
||
1091 |
// reads |
|
1092 |
Set<Module> reads = new HashSet<>(); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1093 |
for (ResolvedModule other : resolvedModule.reads()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1094 |
Module m2 = null; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1095 |
if (other.configuration() == cf) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1096 |
String dn = other.reference().descriptor().name(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1097 |
m2 = nameToModule.get(dn); |
36511 | 1098 |
} else { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1099 |
for (Layer parent: layer.parents()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1100 |
m2 = findModule(parent, other); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1101 |
if (m2 != null) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1102 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1103 |
} |
36511 | 1104 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1105 |
assert m2 != null; |
36511 | 1106 |
|
1107 |
reads.add(m2); |
|
1108 |
||
1109 |
// update VM view |
|
1110 |
addReads0(m, m2); |
|
1111 |
} |
|
1112 |
m.reads = reads; |
|
1113 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1114 |
// automatic modules read all unnamed modules |
36511 | 1115 |
if (descriptor.isAutomatic()) { |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1116 |
m.implAddReads(ALL_UNNAMED_MODULE, true); |
36511 | 1117 |
} |
1118 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1119 |
// exports and opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1120 |
initExportsAndOpens(descriptor, nameToModule, m); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1121 |
} |
36511 | 1122 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1123 |
// register the modules in the boot layer |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1124 |
if (isBootLayer) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1125 |
for (ResolvedModule resolvedModule : cf.modules()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1126 |
ModuleReference mref = resolvedModule.reference(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1127 |
ModuleDescriptor descriptor = mref.descriptor(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1128 |
if (!descriptor.provides().isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1129 |
String name = descriptor.name(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1130 |
Module m = nameToModule.get(name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1131 |
ClassLoader loader = moduleToLoader.get(name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1132 |
ServicesCatalog catalog; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1133 |
if (loader == null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1134 |
catalog = BootLoader.getServicesCatalog(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1135 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1136 |
catalog = ServicesCatalog.getServicesCatalog(loader); |
36511 | 1137 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1138 |
catalog.register(m); |
36511 | 1139 |
} |
1140 |
} |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1141 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1142 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1143 |
// record that there is a layer with modules defined to the class loader |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1144 |
for (ClassLoader loader : loaders) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1145 |
layer.bindToLoader(loader); |
36511 | 1146 |
} |
1147 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1148 |
return nameToModule; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1149 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1150 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1151 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1152 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1153 |
* Find the runtime Module corresponding to the given ResolvedModule |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1154 |
* in the given parent layer (or its parents). |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1155 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1156 |
private static Module findModule(Layer parent, ResolvedModule resolvedModule) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1157 |
Configuration cf = resolvedModule.configuration(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1158 |
String dn = resolvedModule.name(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1159 |
return parent.layers() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1160 |
.filter(l -> l.configuration() == cf) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1161 |
.findAny() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1162 |
.map(layer -> { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1163 |
Optional<Module> om = layer.findModule(dn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1164 |
assert om.isPresent() : dn + " not found in layer"; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1165 |
Module m = om.get(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1166 |
assert m.getLayer() == layer : m + " not in expected layer"; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1167 |
return m; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1168 |
}) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1169 |
.orElse(null); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1170 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1171 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1172 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1173 |
* Initialize the maps of exported and open packages for module m. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1174 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1175 |
private static void initExportsAndOpens(ModuleDescriptor descriptor, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1176 |
Map<String, Module> nameToModule, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1177 |
Module m) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1178 |
{ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1179 |
// The VM doesn't know about open modules so need to export all packages |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1180 |
if (descriptor.isOpen()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1181 |
assert descriptor.opens().isEmpty(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1182 |
for (String source : descriptor.packages()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1183 |
String sourceInternalForm = source.replace('.', '/'); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1184 |
addExportsToAll0(m, sourceInternalForm); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1185 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1186 |
return; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1187 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1188 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1189 |
Map<String, Set<Module>> openPackages = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1190 |
Map<String, Set<Module>> exportedPackages = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1191 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1192 |
// process the open packages first |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1193 |
for (Opens opens : descriptor.opens()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1194 |
String source = opens.source(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1195 |
String sourceInternalForm = source.replace('.', '/'); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1196 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1197 |
if (opens.isQualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1198 |
// qualified opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1199 |
Set<Module> targets = new HashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1200 |
for (String target : opens.targets()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1201 |
// only open to modules that are in this configuration |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1202 |
Module m2 = nameToModule.get(target); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1203 |
if (m2 != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1204 |
addExports0(m, sourceInternalForm, m2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1205 |
targets.add(m2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1206 |
} |
36511 | 1207 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1208 |
if (!targets.isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1209 |
openPackages.put(source, targets); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1210 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1211 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1212 |
// unqualified opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1213 |
addExportsToAll0(m, sourceInternalForm); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1214 |
openPackages.put(source, EVERYONE_SET); |
36511 | 1215 |
} |
1216 |
} |
|
1217 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1218 |
// next the exports, skipping exports when the package is open |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1219 |
for (Exports exports : descriptor.exports()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1220 |
String source = exports.source(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1221 |
String sourceInternalForm = source.replace('.', '/'); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1222 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1223 |
// skip export if package is already open to everyone |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1224 |
Set<Module> openToTargets = openPackages.get(source); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1225 |
if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1226 |
continue; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1227 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1228 |
if (exports.isQualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1229 |
// qualified exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1230 |
Set<Module> targets = new HashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1231 |
for (String target : exports.targets()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1232 |
// only export to modules that are in this configuration |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1233 |
Module m2 = nameToModule.get(target); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1234 |
if (m2 != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1235 |
// skip qualified export if already open to m2 |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1236 |
if (openToTargets == null || !openToTargets.contains(m2)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1237 |
addExports0(m, sourceInternalForm, m2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1238 |
targets.add(m2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1239 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1240 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1241 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1242 |
if (!targets.isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1243 |
exportedPackages.put(source, targets); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1244 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1245 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1246 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1247 |
// unqualified exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1248 |
addExportsToAll0(m, sourceInternalForm); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1249 |
exportedPackages.put(source, EVERYONE_SET); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1250 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1251 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1252 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1253 |
if (!openPackages.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1254 |
m.openPackages = openPackages; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1255 |
if (!exportedPackages.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1256 |
m.exportedPackages = exportedPackages; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1257 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1258 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1259 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1260 |
// -- annotations -- |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1261 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1262 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1263 |
* {@inheritDoc} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1264 |
* This method returns {@code null} when invoked on an unnamed module. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1265 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1266 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1267 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1268 |
return moduleInfoClass().getDeclaredAnnotation(annotationClass); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1269 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1270 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1271 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1272 |
* {@inheritDoc} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1273 |
* This method returns an empty array when invoked on an unnamed module. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1274 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1275 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1276 |
public Annotation[] getAnnotations() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1277 |
return moduleInfoClass().getAnnotations(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1278 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1279 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1280 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1281 |
* {@inheritDoc} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1282 |
* This method returns an empty array when invoked on an unnamed module. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1283 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1284 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1285 |
public Annotation[] getDeclaredAnnotations() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1286 |
return moduleInfoClass().getDeclaredAnnotations(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1287 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1288 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1289 |
// cached class file with annotations |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1290 |
private volatile Class<?> moduleInfoClass; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1291 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1292 |
private Class<?> moduleInfoClass() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1293 |
Class<?> clazz = this.moduleInfoClass; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1294 |
if (clazz != null) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1295 |
return clazz; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1296 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1297 |
synchronized (this) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1298 |
clazz = this.moduleInfoClass; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1299 |
if (clazz == null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1300 |
if (isNamed()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1301 |
PrivilegedAction<Class<?>> pa = this::loadModuleInfoClass; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1302 |
clazz = AccessController.doPrivileged(pa); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1303 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1304 |
if (clazz == null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1305 |
class DummyModuleInfo { } |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1306 |
clazz = DummyModuleInfo.class; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1307 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1308 |
this.moduleInfoClass = clazz; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1309 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1310 |
return clazz; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1311 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1312 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1313 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1314 |
private Class<?> loadModuleInfoClass() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1315 |
Class<?> clazz = null; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1316 |
try (InputStream in = getResourceAsStream("module-info.class")) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1317 |
if (in != null) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1318 |
clazz = loadModuleInfoClass(in); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1319 |
} catch (Exception ignore) { } |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1320 |
return clazz; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1321 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1322 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1323 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1324 |
* Loads module-info.class as a package-private interface in a class loader |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1325 |
* that is a child of this module's class loader. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1326 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1327 |
private Class<?> loadModuleInfoClass(InputStream in) throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1328 |
final String MODULE_INFO = "module-info"; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1329 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1330 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1331 |
+ ClassWriter.COMPUTE_FRAMES); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1332 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1333 |
ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, cw) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1334 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1335 |
public void visit(int version, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1336 |
int access, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1337 |
String name, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1338 |
String signature, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1339 |
String superName, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1340 |
String[] interfaces) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1341 |
cw.visit(version, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1342 |
Opcodes.ACC_INTERFACE |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1343 |
+ Opcodes.ACC_ABSTRACT |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1344 |
+ Opcodes.ACC_SYNTHETIC, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1345 |
MODULE_INFO, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1346 |
null, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1347 |
"java/lang/Object", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1348 |
null); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1349 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1350 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1351 |
public AnnotationVisitor visitAnnotation(String desc, boolean visible) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1352 |
// keep annotations |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1353 |
return super.visitAnnotation(desc, visible); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1354 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1355 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1356 |
public void visitAttribute(Attribute attr) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1357 |
// drop non-annotation attributes |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1358 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1359 |
}; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1360 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1361 |
ClassReader cr = new ClassReader(in); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1362 |
cr.accept(cv, 0); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1363 |
byte[] bytes = cw.toByteArray(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1364 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1365 |
ClassLoader cl = new ClassLoader(loader) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1366 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1367 |
protected Class<?> findClass(String cn)throws ClassNotFoundException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1368 |
if (cn.equals(MODULE_INFO)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1369 |
return super.defineClass(cn, bytes, 0, bytes.length); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1370 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1371 |
throw new ClassNotFoundException(cn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1372 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1373 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1374 |
}; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1375 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1376 |
try { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1377 |
return cl.loadClass(MODULE_INFO); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1378 |
} catch (ClassNotFoundException e) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1379 |
throw new InternalError(e); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1380 |
} |
36511 | 1381 |
} |
1382 |
||
1383 |
||
1384 |
// -- misc -- |
|
1385 |
||
1386 |
||
1387 |
/** |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1388 |
* Returns an input stream for reading a resource in this module. The |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1389 |
* {@code name} parameter is a {@code '/'}-separated path name that |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1390 |
* identifies the resource. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1391 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1392 |
* <p> A resource in a named modules may be <em>encapsulated</em> so that |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1393 |
* it cannot be located by code in other modules. Whether a resource can be |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1394 |
* located or not is determined as follows: |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1395 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1396 |
* <ul> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1397 |
* <li> The <em>package name</em> of the resource is derived from the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1398 |
* subsequence of characters that precedes the last {@code '/'} and then |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1399 |
* replacing each {@code '/'} character in the subsequence with |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1400 |
* {@code '.'}. For example, the package name derived for a resource |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1401 |
* named "{@code a/b/c/foo.properties}" is "{@code a.b.c}". </li> |
36511 | 1402 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1403 |
* <li> If the package name is a package in the module then the package |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1404 |
* must be {@link #isOpen open} the module of the caller of this method. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1405 |
* If the package is not in the module then the resource is not |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1406 |
* encapsulated. Resources in the unnamed package or "{@code META-INF}", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1407 |
* for example, are never encapsulated because they can never be |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1408 |
* packages in a named module. </li> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1409 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1410 |
* <li> As a special case, resources ending with "{@code .class}" are |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1411 |
* never encapsulated. </li> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1412 |
* </ul> |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1413 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1414 |
* <p> This method returns {@code null} if the resource is not in this |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1415 |
* module, the resource is encapsulated and cannot be located by the caller, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1416 |
* or access to the resource is denied by the security manager. |
36511 | 1417 |
* |
1418 |
* @param name |
|
1419 |
* The resource name |
|
1420 |
* |
|
1421 |
* @return An input stream for reading the resource or {@code null} |
|
1422 |
* |
|
1423 |
* @throws IOException |
|
1424 |
* If an I/O error occurs |
|
1425 |
* |
|
1426 |
* @see java.lang.module.ModuleReader#open(String) |
|
1427 |
*/ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1428 |
@CallerSensitive |
36511 | 1429 |
public InputStream getResourceAsStream(String name) throws IOException { |
1430 |
Objects.requireNonNull(name); |
|
1431 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1432 |
if (isNamed() && !ResourceHelper.isSimpleResource(name)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1433 |
Module caller = Reflection.getCallerClass().getModule(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1434 |
if (caller != this && caller != Object.class.getModule()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1435 |
// ignore packages added for proxies via addPackage |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1436 |
Set<String> packages = getDescriptor().packages(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1437 |
String pn = ResourceHelper.getPackageName(name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1438 |
if (packages.contains(pn) && !isOpen(pn, caller)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1439 |
// resource is in package not open to caller |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1440 |
return null; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1441 |
} |
36511 | 1442 |
} |
1443 |
} |
|
1444 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1445 |
String mn = this.name; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1446 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1447 |
// special-case built-in class loaders to avoid URL connection |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1448 |
if (loader == null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1449 |
return BootLoader.findResourceAsStream(mn, name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1450 |
} else if (loader instanceof BuiltinClassLoader) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1451 |
return ((BuiltinClassLoader) loader).findResourceAsStream(mn, name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1452 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1453 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1454 |
// locate resource in module |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1455 |
JavaLangAccess jla = SharedSecrets.getJavaLangAccess(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1456 |
URL url = jla.findResource(loader, mn, name); |
36511 | 1457 |
if (url != null) { |
1458 |
try { |
|
1459 |
return url.openStream(); |
|
1460 |
} catch (SecurityException e) { } |
|
1461 |
} |
|
1462 |
||
1463 |
return null; |
|
1464 |
} |
|
1465 |
||
1466 |
/** |
|
1467 |
* Returns the string representation of this module. For a named module, |
|
1468 |
* the representation is the string {@code "module"}, followed by a space, |
|
1469 |
* and then the module name. For an unnamed module, the representation is |
|
1470 |
* the string {@code "unnamed module"}, followed by a space, and then an |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1471 |
* implementation specific string that identifies the unnamed module. |
36511 | 1472 |
* |
1473 |
* @return The string representation of this module |
|
1474 |
*/ |
|
1475 |
@Override |
|
1476 |
public String toString() { |
|
1477 |
if (isNamed()) { |
|
1478 |
return "module " + name; |
|
1479 |
} else { |
|
1480 |
String id = Integer.toHexString(System.identityHashCode(this)); |
|
1481 |
return "unnamed module @" + id; |
|
1482 |
} |
|
1483 |
} |
|
1484 |
||
1485 |
||
1486 |
// -- native methods -- |
|
1487 |
||
1488 |
// JVM_DefineModule |
|
1489 |
private static native void defineModule0(Module module, |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1490 |
boolean isOpen, |
36511 | 1491 |
String version, |
1492 |
String location, |
|
1493 |
String[] pns); |
|
1494 |
||
1495 |
// JVM_AddReadsModule |
|
1496 |
private static native void addReads0(Module from, Module to); |
|
1497 |
||
1498 |
// JVM_AddModuleExports |
|
1499 |
private static native void addExports0(Module from, String pn, Module to); |
|
1500 |
||
1501 |
// JVM_AddModuleExportsToAll |
|
1502 |
private static native void addExportsToAll0(Module from, String pn); |
|
1503 |
||
1504 |
// JVM_AddModuleExportsToAllUnnamed |
|
1505 |
private static native void addExportsToAllUnnamed0(Module from, String pn); |
|
1506 |
||
1507 |
// JVM_AddModulePackage |
|
1508 |
private static native void addPackage0(Module m, String pn); |
|
1509 |
||
1510 |
/** |
|
1511 |
* Register shared secret to provide access to package-private methods |
|
1512 |
*/ |
|
1513 |
static { |
|
1514 |
SharedSecrets.setJavaLangReflectModuleAccess( |
|
1515 |
new JavaLangReflectModuleAccess() { |
|
1516 |
@Override |
|
1517 |
public Module defineUnnamedModule(ClassLoader loader) { |
|
1518 |
return new Module(loader); |
|
1519 |
} |
|
1520 |
@Override |
|
1521 |
public Module defineModule(ClassLoader loader, |
|
1522 |
ModuleDescriptor descriptor, |
|
1523 |
URI uri) { |
|
1524 |
return new Module(null, loader, descriptor, uri); |
|
1525 |
} |
|
1526 |
@Override |
|
1527 |
public void addReads(Module m1, Module m2) { |
|
1528 |
m1.implAddReads(m2, true); |
|
1529 |
} |
|
1530 |
@Override |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1531 |
public void addReadsAllUnnamed(Module m) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1532 |
m.implAddReads(Module.ALL_UNNAMED_MODULE); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1533 |
} |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1534 |
@Override |
36511 | 1535 |
public void addExports(Module m, String pn, Module other) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1536 |
m.implAddExportsOrOpens(pn, other, false, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1537 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1538 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1539 |
public void addOpens(Module m, String pn, Module other) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1540 |
m.implAddExportsOrOpens(pn, other, true, true); |
36511 | 1541 |
} |
1542 |
@Override |
|
1543 |
public void addExportsToAll(Module m, String pn) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1544 |
m.implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, false, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1545 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1546 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1547 |
public void addOpensToAll(Module m, String pn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1548 |
m.implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, true, true); |
36511 | 1549 |
} |
1550 |
@Override |
|
1551 |
public void addExportsToAllUnnamed(Module m, String pn) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1552 |
m.implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, false, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1553 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1554 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1555 |
public void addOpensToAllUnnamed(Module m, String pn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1556 |
m.implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, true, true); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1557 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1558 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1559 |
public void addUses(Module m, Class<?> service) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1560 |
m.implAddUses(service); |
36511 | 1561 |
} |
1562 |
@Override |
|
1563 |
public void addPackage(Module m, String pn) { |
|
1564 |
m.implAddPackage(pn, true); |
|
1565 |
} |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1566 |
@Override |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1567 |
public ServicesCatalog getServicesCatalog(Layer layer) { |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1568 |
return layer.getServicesCatalog(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37363
diff
changeset
|
1569 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1570 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1571 |
public Stream<Layer> layers(Layer layer) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1572 |
return layer.layers(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1573 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1574 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1575 |
public Stream<Layer> layers(ClassLoader loader) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1576 |
return Layer.layers(loader); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
38564
diff
changeset
|
1577 |
} |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
1578 |
@Override |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
1579 |
public boolean isStaticallyExported(Module module, String pn, Module other) { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
1580 |
return module.isStaticallyExportedOrOpen(pn, other, false); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
1581 |
} |
36511 | 1582 |
}); |
1583 |
} |
|
1584 |
} |