author | alanb |
Fri, 10 Feb 2017 09:04:39 +0000 | |
changeset 43712 | 5dfd0950317c |
parent 39655 | 909e84883de9 |
child 44545 | 83b611b88ac8 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
/** |
|
27 |
* Classes to support module descriptors and creating configurations of modules |
|
28 |
* by means of resolution and service binding. |
|
29 |
* |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
30 |
* <h2><a name="resolution">Resolution</a></h2> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
31 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
32 |
* <p> Resolution is the process of computing the transitive closure of a set |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
33 |
* of root modules over a set of observable modules by resolving the |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
34 |
* dependences expressed by {@link |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
35 |
* java.lang.module.ModuleDescriptor.Requires requires} clauses. |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
36 |
* The <em>dependence graph</em> is augmented with edges that take account of |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
37 |
* implicitly declared dependences ({@code requires transitive}) to create a |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
38 |
* <em>readability graph</em>. The result of resolution is a {@link |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
39 |
* java.lang.module.Configuration Configuration} that encapsulates the |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
40 |
* readability graph. </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
41 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
42 |
* <p> As an example, suppose we have the following observable modules: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
43 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
44 |
* module m1 { requires m2; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
45 |
* module m2 { requires transitive m3; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
46 |
* module m3 { } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
47 |
* module m4 { } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
48 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
49 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
50 |
* <p> If the module {@code m1} is resolved then the resulting configuration |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
51 |
* contains three modules ({@code m1}, {@code m2}, {@code m3}). The edges in |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
52 |
* its readability graph are: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
53 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
54 |
* m1 --> m2 (meaning m1 reads m2) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
55 |
* m1 --> m3 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
56 |
* m2 --> m3 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
57 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
58 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
59 |
* <p> Resolution is an additive process. When computing the transitive closure |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
60 |
* then the dependence relation may include dependences on modules in {@link |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
61 |
* java.lang.module.Configuration#parents() parent} configurations. The result |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
62 |
* is a <em>relative configuration</em> that is relative to one or more parent |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
63 |
* configurations and where the readability graph may have edges from modules |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
64 |
* in the configuration to modules in parent configurations. </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
65 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
66 |
* <p> As an example, suppose we have the following observable modules: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
67 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
68 |
* module m1 { requires m2; requires java.xml; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
69 |
* module m2 { } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
70 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
71 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
72 |
* <p> If module {@code m1} is resolved with the configuration for the {@link |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
73 |
* java.lang.reflect.Layer#boot() boot} layer as the parent then the resulting |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
74 |
* configuration contains two modules ({@code m1}, {@code m2}). The edges in |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
75 |
* its readability graph are: |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
76 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
77 |
* m1 --> m2 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
78 |
* m1 --> java.xml |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
79 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
80 |
* where module {@code java.xml} is in the parent configuration. For |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
81 |
* simplicity, this example omits the implicitly declared dependence on the |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
82 |
* {@code java.base} module. |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
83 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
84 |
* <p> Requires clauses that are "{@code requires static}" express an optional |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
85 |
* dependence (except at compile-time). If a module declares that it |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
86 |
* "{@code requires static M}" then resolution does not search the observable |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
87 |
* modules for "{@code M}". However, if "{@code M}" is resolved (because resolution |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
88 |
* resolves a module that requires "{@code M}" without the {@link |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
89 |
* java.lang.module.ModuleDescriptor.Requires.Modifier#STATIC static} modifier) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
90 |
* then the readability graph will contain read edges for each module that |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
91 |
* "{@code requires static M}". </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
92 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
93 |
* <p> {@link java.lang.module.ModuleDescriptor#isAutomatic() Automatic} modules |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
94 |
* receive special treatment during resolution. Each automatic module is resolved |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
95 |
* so that it reads all other modules in the configuration and all parent |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
96 |
* configurations. Each automatic module is also resolved as if it |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
97 |
* "{@code requires transitive}" all other automatic modules in the configuration |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
98 |
* (and all automatic modules in parent configurations). </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
99 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
100 |
* <h2><a name="servicebinding">Service binding</a></h2> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
101 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
102 |
* <p> Service binding is the process of augmenting a graph of resolved modules |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
103 |
* from the set of observable modules induced by the service-use dependence |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
104 |
* ({@code uses} and {@code provides} clauses). Any module that was not |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
105 |
* previously in the graph requires resolution to compute its transitive |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
106 |
* closure. Service binding is an iterative process in that adding a module |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
107 |
* that satisfies some service-use dependence may introduce new service-use |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
108 |
* dependences. </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
109 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
110 |
* <p> Suppose we have the following observable modules: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
111 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
112 |
* module m1 { exports p; uses p.S; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
113 |
* module m2 { requires m1; provides p.S with p2.S2; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
114 |
* module m3 { requires m1; requires m4; provides p.S with p3.S3; } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
115 |
* module m4 { } |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
116 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
117 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
118 |
* <p> If the module {@code m1} is resolved then the resulting graph of modules |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
119 |
* has one module ({@code m1}). If the graph is augmented with modules induced |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
120 |
* by the service-use dependence relation then the configuration will contain |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
121 |
* four modules ({@code m1}, {@code m2}, {@code m3}, {@code m4}). The edges in |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
122 |
* its readability graph are: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
123 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
124 |
* m2 --> m1 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
125 |
* m3 --> m1 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
126 |
* m3 --> m4 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
127 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
128 |
* <p> The edges in the conceptual service-use graph are: </p> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
129 |
* <pre> {@code |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
130 |
* m1 --> m2 (meaning m1 uses a service that is provided by m2) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
131 |
* m1 --> m3 |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
132 |
* } </pre> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
133 |
* |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
134 |
* <h2>General Exceptions</h2> |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
135 |
* |
36511 | 136 |
* <p> Unless otherwise noted, passing a {@code null} argument to a constructor |
137 |
* or method of any class or interface in this package will cause a {@link |
|
138 |
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally, |
|
139 |
* invoking a method with an array or collection containing a {@code null} element |
|
140 |
* will cause a {@code NullPointerException}, unless otherwise specified. </p> |
|
141 |
* |
|
142 |
* @since 9 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
39655
diff
changeset
|
143 |
* @spec JPMS |
36511 | 144 |
*/ |
145 |
||
146 |
package java.lang.module; |