You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A versioned Java source has a base copy and one or more versioned copies. The signature of each
119
+
Mx includes support for multiple versions of a Java class. The mechanism is inspired by and
120
+
similar to[multi-release jars](https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files).
121
+
A versioned Java class has a base version and one or more versioned copies. The public signature of each
122
122
copy (i.e., methods and fields accessed from outside the source file) must be identical.
123
-
A versioned copy must be in a project whose Java compliance is greater than the project
124
-
containing the base copy. For example, the base copy of [GraalServices.java](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/src/org.graalvm.compiler.serviceprovider/src/org/graalvm/compiler/serviceprovider/GraalServices.java)
125
-
is in a [project with Java compliance of 8](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L134).
126
-
There is a [GraalServices.java](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/src/org.graalvm.compiler.serviceprovider.jdk9/src/org/graalvm/compiler/serviceprovider/GraalServices.java)
127
-
source file that _presides over_ the base copy when running on JDK 9 or later.
128
-
The project containing the latter [uses](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L144-L145)
129
-
the `multiReleaseJarVersion` attribute to denote that it contains classes to be packaged in
130
-
a versioned jar directory. It also specifies the earliest Java version for which it is valid.
131
-
132
-
When these projects are combined into the same mx distribution, mx will put these class files into the distribution
133
-
jar according to the multi-release jar format:
134
-
```
135
-
> jar tvf mxbuild/dists/graal.jar | grep GraalServices
136
-
1562 Tue May 22 22:19:02 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
137
-
6546 Tue May 22 22:19:02 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices.class
138
-
1146 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$1.class
139
-
1435 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$1$1.class
140
-
932 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
141
-
6933 Tue May 22 22:19:02 CEST 2018 META-INF/versions/9/org/graalvm/compiler/serviceprovider/GraalServices.class
142
-
```
143
-
Resolving classes to the right version is done by the VM at runtime as explained in the JAR specification.
144
123
145
-
When a distribution also defines a module (e.g., [GRAAL](https://github.com/oracle/graal/blob/1bc9e1c762c85303d1388f98149bb9bb402f0cff/compiler/mx.compiler/suite.py#L1662)),
146
-
the versions are _flattened_ when creating the modular jar. That is, the modular jar contains only the class
147
-
files that would be resolved at runtime:
148
-
```
149
-
> jar tvf mxbuild/modules/jdk.internal.vm.compiler.jar | grep GraalServices
150
-
1146 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$1.class
151
-
1435 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$1$1.class
152
-
932 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices$JMXService.class
153
-
6933 Tue May 22 22:19:12 CEST 2018 org/graalvm/compiler/serviceprovider/GraalServices.class
154
-
```
124
+
Versioned classes for JDK 9 or later need to be in a project with a `javaCompliance` greater than
125
+
or equal to 9 and a `multiReleaseJarVersion` attribute whose value is also greater or equal to 9.
126
+
The versioned project must have the base project as a dependency.
127
+
128
+
Versioned classes for JDK 8 or earlier need to be in a project with a `javaCompliance` less than or
129
+
equal to 8 and an `overlayTarget` attribute denoting the base project.
0 commit comments