mx: --strict-compliance is now the only supported mode
Doug Simon
doug.simon at oracle.com
Fri Jun 1 14:54:36 UTC 2018
Historically, mx has used a non-strict algorithm when deciding which JDK to use for compiling a project with Java compliance N. The motivation was to support using a single JDK for all compilation. For Java code that only uses public JDK API, this was not a problem. However, both Graal and SVM use non-public JDK API which complicates things. To make it possible to use javac from JDK 9 with a `--release 8` option to compile a project that uses JDK 8 internal API (e.g. sun.misc.Unsafe), mx provided skeletons for the API in question (e.g., Unsafe.java <https://github.com/graalvm/mx/blob/72d6eea5d1ede2bc1ddb42c9cc61c44b93e0a371/java/Unsafe.java>) since the `--release` mechanism only provides symbol for public JDK API. However, this approach did not scale as it meant skeletons need to be provided for every internal API used by any mx project. A better approach is to simply enforce a strict JDK matching algorithm. That is, if a project has a Java compliance of 8, then a JDK 8 must be made available (via JAVA_HOME/EXTRA_JAVA_HOMES or --java-home/--extra-java-homes).
Mx has now been changed <https://github.com/graalvm/mx/commit/1c4adb1e3a6ca813ff4a693c7fcc7b48bb1b3085> to enforce this.
Prior to this change, a Java compliance could be either exact or open ended:
Compliance Value Compatible JDKs for compilation
8 JDK8
9+ JDK9, JDK10, JDK11, ...
Since a project may use internal API that spans only a fixed set of JDKs, Java compliance now also supports a fixed range:
Compliance Value Compatible JDKs for compilation
8 JDK8
9+ JDK9, JDK10, JDK11, ...
9..10 JDK9, JDK10
The lower bound in a fixed range specifies the language level. That is, it will be used as the value for the -source and -target javac options.
One noticeable impact is that the auto-JDK-selection in mx has been moved to a separate utility: select_jdk.py. When mx cannot find a JDK it needs, you will now get an error message such as:
--------------------------------------------------
Could not find a JDK
The following JDKs are available:
/Library/Java/JavaVirtualMachines/graalvm-1.0.0-rc1/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk8u172-b11
/Library/Java/JavaVirtualMachines/labsjdk-20180522-073957
/Library/Java/JavaVirtualMachines/labsjdk1.8.0_161-jvmci-0.42/Contents/Home
/Library/Java/JavaVirtualMachines/labsjdk1.8.0_171-jvmci-0.43/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-10.jdk/Contents/Home
Specify one with the --java-home or --extra-java-homes option or with the JAVA_HOME or EXTRA_JAVA_HOMES environment variable.
Or run `/Users/dsimon/mx/select_jdk.py -p /Users/dsimon/graal/graal/compiler` to set and persist these variables in /Users/dsimon/graal/graal/compiler/mx.compiler/env.
--------------------------------------------------
The last line shows you how to run the select_jdk.py utility to configure your env file.
This utility can also be used to define a `select_jdk` shell function as described here:
https://github.com/graalvm/mx/blob/master/select_jdk.py#L118-L129
Please feel free to reply or open mx issues on GitHub if you run into any problems as a result of this change.
-Doug
More information about the graal-dev
mailing list