author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 44359 | c6761862ca0b |
child 45004 | ea3137042a61 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36511 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.internal.module; |
|
27 |
||
28 |
import java.lang.module.ModuleDescriptor; |
|
29 |
import java.net.URI; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
30 |
import java.security.AccessController; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
31 |
import java.security.PrivilegedAction; |
36511 | 32 |
|
33 |
import jdk.internal.loader.BootLoader; |
|
34 |
import jdk.internal.loader.ClassLoaders; |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
35 |
import jdk.internal.misc.JavaLangAccess; |
36511 | 36 |
import jdk.internal.misc.SharedSecrets; |
37 |
||
38 |
/** |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
39 |
* A helper class for creating and updating modules. This class is intended to |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
40 |
* support command-line options, tests, and the instrumentation API. It is also |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
41 |
* used by the VM to add read edges when agents are instrumenting code that |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
42 |
* need to link to supporting classes. |
36511 | 43 |
* |
44 |
* The parameters that are package names in this API are the fully-qualified |
|
45 |
* names of the packages as defined in section 6.5.3 of <cite>The Java™ |
|
46 |
* Language Specification </cite>, for example, {@code "java.lang"}. |
|
47 |
*/ |
|
48 |
||
49 |
public class Modules { |
|
50 |
private Modules() { } |
|
51 |
||
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
52 |
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); |
36511 | 53 |
|
54 |
/** |
|
55 |
* Creates a new Module. The module has the given ModuleDescriptor and |
|
56 |
* is defined to the given class loader. |
|
57 |
* |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
58 |
* The resulting Module is in a larval state in that it does not not read |
36511 | 59 |
* any other module and does not have any exports. |
60 |
* |
|
61 |
* The URI is for information purposes only. |
|
62 |
*/ |
|
63 |
public static Module defineModule(ClassLoader loader, |
|
64 |
ModuleDescriptor descriptor, |
|
65 |
URI uri) |
|
66 |
{ |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
67 |
return JLA.defineModule(loader, descriptor, uri); |
36511 | 68 |
} |
69 |
||
70 |
/** |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
71 |
* Updates m1 to read m2. |
36511 | 72 |
* Same as m1.addReads(m2) but without a caller check. |
73 |
*/ |
|
74 |
public static void addReads(Module m1, Module m2) { |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
75 |
JLA.addReads(m1, m2); |
36511 | 76 |
} |
77 |
||
78 |
/** |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
79 |
* Update module m to read all unnamed modules. |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
80 |
*/ |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
81 |
public static void addReadsAllUnnamed(Module m) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
82 |
JLA.addReadsAllUnnamed(m); |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
83 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
84 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
85 |
/** |
36511 | 86 |
* Updates module m1 to export a package to module m2. |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
87 |
* Same as m1.addExports(pn, m2) but without a caller check |
36511 | 88 |
*/ |
89 |
public static void addExports(Module m1, String pn, Module m2) { |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
90 |
JLA.addExports(m1, pn, m2); |
36511 | 91 |
} |
92 |
||
93 |
/** |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
94 |
* Updates module m to export a package to all unnamed modules. |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
95 |
*/ |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
96 |
public static void addExportsToAllUnnamed(Module m, String pn) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
97 |
JLA.addExportsToAllUnnamed(m, pn); |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
98 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
99 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
100 |
/** |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
101 |
* Updates module m1 to open a package to module m2. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
102 |
* Same as m1.addOpens(pn, m2) but without a caller check. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
103 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
104 |
public static void addOpens(Module m1, String pn, Module m2) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
105 |
JLA.addOpens(m1, pn, m2); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
106 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
107 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
108 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
109 |
* Updates module m to open a package to all unnamed modules. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
110 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
111 |
public static void addOpensToAllUnnamed(Module m, String pn) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
112 |
JLA.addOpensToAllUnnamed(m, pn); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
113 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
114 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
115 |
/** |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
116 |
* Updates module m to use a service. |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
117 |
* Same as m2.addUses(service) but without a caller check. |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
118 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
119 |
public static void addUses(Module m, Class<?> service) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
120 |
JLA.addUses(m, service); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
121 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
122 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
123 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
124 |
* Updates module m to provide a service |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
125 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
126 |
public static void addProvides(Module m, Class<?> service, Class<?> impl) { |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
127 |
ModuleLayer layer = m.getLayer(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
128 |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
129 |
if (layer == null || layer == ModuleLayer.boot()) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
130 |
// update ClassLoader catalog |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
131 |
PrivilegedAction<ClassLoader> pa = m::getClassLoader; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
132 |
ClassLoader loader = AccessController.doPrivileged(pa); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
133 |
ServicesCatalog catalog; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
134 |
if (loader == null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
135 |
catalog = BootLoader.getServicesCatalog(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
136 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
137 |
catalog = ServicesCatalog.getServicesCatalog(loader); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
138 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
139 |
catalog.addProvider(m, service, impl); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
140 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
141 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
142 |
if (layer != null) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
143 |
// update Layer catalog |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44359
diff
changeset
|
144 |
JLA.getServicesCatalog(layer).addProvider(m, service, impl); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
145 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
146 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
147 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37779
diff
changeset
|
148 |
/** |
36511 | 149 |
* Called by the VM when code in the given Module has been transformed by |
150 |
* an agent and so may have been instrumented to call into supporting |
|
151 |
* classes on the boot class path or application class path. |
|
152 |
*/ |
|
153 |
public static void transformedByAgent(Module m) { |
|
154 |
addReads(m, BootLoader.getUnnamedModule()); |
|
155 |
addReads(m, ClassLoaders.appClassLoader().getUnnamedModule()); |
|
156 |
} |
|
157 |
} |