add JDK 9 support #143

Merged
merged 6 commits into from Mar 10, 2017

Conversation

Projects
None yet
3 participants
@eed3si9n
Member

eed3si9n commented Feb 15, 2017

This copies https://github.com/retronym/java9-rt-export into this repository.

Next it improves the version detection script using sed.
When Java 9 is detected it uses java9-rt-export to evaluate the sbt's global base directory, and it copies the rt.jar off to the side, and starts sbt with -Dscala.ext.dirs flag as described in sbt/sbt#2951.

For Windows, it uses a bit more primitive method of detecting the Java version since sed is not available by default.

@eed3si9n eed3si9n requested a review from cunei Feb 15, 2017

@retronym retronym referenced this pull request in scala/scala Feb 16, 2017

Merged

More groundwork for JDK 9 support #5707

src/universal/bin/sbt-launch-lib.bash
+ ${java_args[@]} \
+ -jar "$rtexport" \
+ "${java9_rt}"
+ fi

This comment has been minimized.

@cunei

cunei Feb 16, 2017

Contributor

This will copy rt.jar only once. However, jdk 9 might be updated over time. People may select different versions for debugging reasons, or may flip from OpenJDK to Oracle's JDK, to IBM's JVM. That may cause unexpected behavior or crashes. Probably rt.jar should be copied on each startup; alternatively, the full version string could be dumped to a text file and matched upon startup, so that if it differs the rt.jar file is extracted again.

@cunei

cunei Feb 16, 2017

Contributor

This will copy rt.jar only once. However, jdk 9 might be updated over time. People may select different versions for debugging reasons, or may flip from OpenJDK to Oracle's JDK, to IBM's JVM. That may cause unexpected behavior or crashes. Probably rt.jar should be copied on each startup; alternatively, the full version string could be dumped to a text file and matched upon startup, so that if it differs the rt.jar file is extracted again.

src/universal/bin/sbt-launch-lib.bash
vlog "[process_args] java_version = '$java_version'"
+ rtexport=$(rt_export_file)
+ sbt_global_dir=$("$java_cmd" ${JAVA_OPTS} ${SBT_OPTS:-$default_sbt_opts} ${java_args[@]} \

This comment has been minimized.

@eed3si9n

eed3si9n Feb 16, 2017

Member

I need to move this out to copyRt so I can use this script from Java 1.6 and 1.7.

@eed3si9n

eed3si9n Feb 16, 2017

Member

I need to move this out to copyRt so I can use this script from Java 1.6 and 1.7.

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Mar 6, 2017

Member

@eed3si9n you mentioned you were seeing a 1.8 java.version in the system property. Could you show what you did? I'm not seeing it:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+158)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+158, mixed mode)

$ echo 'public class T { public static void main(String... args) { System.out.println(System.getProperty("java.version")); } }' > T.java

$ javac T.java

$ java T
9-ea
Member

dwijnand commented Mar 6, 2017

@eed3si9n you mentioned you were seeing a 1.8 java.version in the system property. Could you show what you did? I'm not seeing it:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+158)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+158, mixed mode)

$ echo 'public class T { public static void main(String... args) { System.out.println(System.getProperty("java.version")); } }' > T.java

$ javac T.java

$ java T
9-ea
@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Mar 6, 2017

Member

Using the Scala 2.12.1 REPL:

scala> sys.props.toSeq filter (_._1 matches "java.*version") foreach println
(java.specification.version,9)
(java.vm.specification.version,9)
(java.runtime.version,9-ea+158)
(java.version,9-ea)
(java.vm.version,9-ea+158)
(java.class.version,53.0)
Member

dwijnand commented Mar 6, 2017

Using the Scala 2.12.1 REPL:

scala> sys.props.toSeq filter (_._1 matches "java.*version") foreach println
(java.specification.version,9)
(java.vm.specification.version,9)
(java.runtime.version,9-ea+158)
(java.version,9-ea)
(java.vm.version,9-ea+158)
(java.class.version,53.0)
@cunei

This comment has been minimized.

Show comment
Hide comment
@cunei

cunei Mar 6, 2017

Contributor

The string used for versioning should include vendor, patch level, and all the details that may uniquely identify a given JVM release. Here are a few suggestions: http://stackoverflow.com/a/5103166
Also:

java -XshowSettings:properties -version
Contributor

cunei commented Mar 6, 2017

The string used for versioning should include vendor, patch level, and all the details that may uniquely identify a given JVM release. Here are a few suggestions: http://stackoverflow.com/a/5103166
Also:

java -XshowSettings:properties -version
@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Mar 7, 2017

Member

I did something along the lines of

            if (destination.equals("--rt-ext-dir")) {
                System.out.println(System.getProperty("java.version"));

                String v = System.getProperty("java.version");
                Path rtExtDir = Paths.get(globalBase, "java9-rt-ext-" + v);
                System.out.println(rtExtDir.toString());
                System.exit(0);
            }

compiled it using Java 8, and ran it on JDK 9, and I get this:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+156)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+156, mixed mode)
$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir
1.8.0_91
/Users/xxx/.sbt/0.13/java9-rt-ext-1.8.0_91
Member

eed3si9n commented Mar 7, 2017

I did something along the lines of

            if (destination.equals("--rt-ext-dir")) {
                System.out.println(System.getProperty("java.version"));

                String v = System.getProperty("java.version");
                Path rtExtDir = Paths.get(globalBase, "java9-rt-ext-" + v);
                System.out.println(rtExtDir.toString());
                System.exit(0);
            }

compiled it using Java 8, and ran it on JDK 9, and I get this:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+156)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+156, mixed mode)
$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir
1.8.0_91
/Users/xxx/.sbt/0.13/java9-rt-ext-1.8.0_91
@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Mar 7, 2017

Member

Here's a WIP commit - a2ee22e
What am I doing wrong here?

Member

eed3si9n commented Mar 7, 2017

Here's a WIP commit - a2ee22e
What am I doing wrong here?

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Mar 7, 2017

Member

FWIW, rebasing that change on @retronym's original doesn't show what you're seeing:

diff --git a/src/main/java/io/github/retronym/java9rtexport/Export.java b/src/main/java/io/github/retronym/java9rtexport/Export.java
index 5591dde..e5c2b41 100644
--- a/src/main/java/io/github/retronym/java9rtexport/Export.java
+++ b/src/main/java/io/github/retronym/java9rtexport/Export.java
@@ -10,6 +10,8 @@ import java.util.Map;
 public class Export {
     public static void main(String[] args) {
         try {
+            final String v = System.getProperty("java.version");
+            System.out.println("java.version = " + v);
             FileSystem fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
             Path path = fileSystem.getPath("/modules");
             String destination = args[0];
10:58:32 $ jenv local 1.8

10:58:37 $ sbt clean package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/java9-rt-export/project
[info] Set current project to java9-rt-export (in build file:/d/java9-rt-export/)
[success] Total time: 0 s, completed 07-Mar-2017 10:58:50
[info] Updating {file:/d/java9-rt-export/}java9-rt-export...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/java9-rt-export/target/classes...
[info] Packaging /d/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 10:58:51

10:58:51 $ jenv local 9-ea

10:58:55 $ java -jar target/java9-rt-export-0.1-SNAPSHOT.jar rt.jar
java.version = 9-ea
Member

dwijnand commented Mar 7, 2017

FWIW, rebasing that change on @retronym's original doesn't show what you're seeing:

diff --git a/src/main/java/io/github/retronym/java9rtexport/Export.java b/src/main/java/io/github/retronym/java9rtexport/Export.java
index 5591dde..e5c2b41 100644
--- a/src/main/java/io/github/retronym/java9rtexport/Export.java
+++ b/src/main/java/io/github/retronym/java9rtexport/Export.java
@@ -10,6 +10,8 @@ import java.util.Map;
 public class Export {
     public static void main(String[] args) {
         try {
+            final String v = System.getProperty("java.version");
+            System.out.println("java.version = " + v);
             FileSystem fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
             Path path = fileSystem.getPath("/modules");
             String destination = args[0];
10:58:32 $ jenv local 1.8

10:58:37 $ sbt clean package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/java9-rt-export/project
[info] Set current project to java9-rt-export (in build file:/d/java9-rt-export/)
[success] Total time: 0 s, completed 07-Mar-2017 10:58:50
[info] Updating {file:/d/java9-rt-export/}java9-rt-export...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/java9-rt-export/target/classes...
[info] Packaging /d/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 10:58:51

10:58:51 $ jenv local 9-ea

10:58:55 $ java -jar target/java9-rt-export-0.1-SNAPSHOT.jar rt.jar
java.version = 9-ea
@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Mar 7, 2017

Member

I can't reproduce what you're seeing. Using a2ee22e on your wip/jdk9_branch:

11:20:22 $ jenv local 1.8

11:20:26 $ sbt -Dsbt.build.version=1.0.0 java9rtexport/clean java9rtexport/package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/sbt-launcher-package/project/project
[info] Loading project definition from /d/sbt-launcher-package/project
[info] Set current project to sbt-launcher-packaging (in build file:/d/sbt-launcher-package/)
[success] Total time: 0 s, completed 07-Mar-2017 11:20:40
[info] Updating {file:/d/sbt-launcher-package/}java9rtexport...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/sbt-launcher-package/java9-rt-export/target/classes...
[info] Packaging /d/sbt-launcher-package/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 11:20:41

11:20:42 $ jenv local 9-ea

11:20:48 $ java -jar java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar --rt-ext-dir
/Users/dnw/.sbt/0.13/java9-rt-ext-9-ea

Something's up with your setup maybe.

Member

dwijnand commented Mar 7, 2017

I can't reproduce what you're seeing. Using a2ee22e on your wip/jdk9_branch:

11:20:22 $ jenv local 1.8

11:20:26 $ sbt -Dsbt.build.version=1.0.0 java9rtexport/clean java9rtexport/package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/sbt-launcher-package/project/project
[info] Loading project definition from /d/sbt-launcher-package/project
[info] Set current project to sbt-launcher-packaging (in build file:/d/sbt-launcher-package/)
[success] Total time: 0 s, completed 07-Mar-2017 11:20:40
[info] Updating {file:/d/sbt-launcher-package/}java9rtexport...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/sbt-launcher-package/java9-rt-export/target/classes...
[info] Packaging /d/sbt-launcher-package/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 11:20:41

11:20:42 $ jenv local 9-ea

11:20:48 $ java -jar java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar --rt-ext-dir
/Users/dnw/.sbt/0.13/java9-rt-ext-9-ea

Something's up with your setup maybe.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Mar 7, 2017

Member

I finally figured out the mystery. When I was running the following:

$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir

jenv was picking up .java-version file located in ~/work/sbt-modules/sbt-launcher-package, even though my current directory was somewhere completely different. This is why my java -version and java -jar ... behaved differently.

Member

eed3si9n commented Mar 7, 2017

I finally figured out the mystery. When I was running the following:

$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir

jenv was picking up .java-version file located in ~/work/sbt-modules/sbt-launcher-package, even though my current directory was somewhere completely different. This is why my java -version and java -jar ... behaved differently.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Mar 8, 2017

Member

So now that --rt-ext-dir problem is solved, this PR is ready for another round of review?

Member

eed3si9n commented Mar 8, 2017

So now that --rt-ext-dir problem is solved, this PR is ready for another round of review?

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Mar 9, 2017

Member

Vendor properties and values on my 9-ea installation (using jshell):

15:14:41 $ JENV_VERSION=9-ea jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro

jshell> System.getProperties().entrySet().stream().collect(Collectors.toList()).stream().sorted((x, y) -> x.getKey().toString().compareTo(y.getKey().toString())).filter(kv -> kv.getKey().toString().contains("vendor")).map(kv -> String.format("%-45s %s", kv.getKey(), kv.getValue())).forEach(System.out::println)
java.specification.vendor                     Oracle Corporation
java.vendor                                   Oracle Corporation
java.vendor.url                               http://java.oracle.com/
java.vendor.url.bug                           http://bugreport.java.com/bugreport/
java.vm.specification.vendor                  Oracle Corporation
java.vm.vendor                                Oracle Corporation
Member

dwijnand commented Mar 9, 2017

Vendor properties and values on my 9-ea installation (using jshell):

15:14:41 $ JENV_VERSION=9-ea jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro

jshell> System.getProperties().entrySet().stream().collect(Collectors.toList()).stream().sorted((x, y) -> x.getKey().toString().compareTo(y.getKey().toString())).filter(kv -> kv.getKey().toString().contains("vendor")).map(kv -> String.format("%-45s %s", kv.getKey(), kv.getValue())).forEach(System.out::println)
java.specification.vendor                     Oracle Corporation
java.vendor                                   Oracle Corporation
java.vendor.url                               http://java.oracle.com/
java.vendor.url.bug                           http://bugreport.java.com/bugreport/
java.vm.specification.vendor                  Oracle Corporation
java.vm.vendor                                Oracle Corporation
@cunei

This comment has been minimized.

Show comment
Hide comment
@cunei

cunei Mar 9, 2017

Contributor

I would say a concatenation (with spaces/special characters remapped/removed) of these three, for the directory name:

    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.vendor = Oracle Corporation
    java.version = 1.8.0_121
Contributor

cunei commented Mar 9, 2017

I would say a concatenation (with spaces/special characters remapped/removed) of these three, for the directory name:

    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.vendor = Oracle Corporation
    java.version = 1.8.0_121
@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Mar 9, 2017

Member

For compiler bridge sbt currently just uses java.version as postfix. Maybe we can add java.vendor but I don't think we need to worry about java.vm.name.

Member

eed3si9n commented Mar 9, 2017

For compiler bridge sbt currently just uses java.version as postfix. Maybe we can add java.vendor but I don't think we need to worry about java.vm.name.

@cunei

cunei approved these changes Mar 10, 2017

@cunei

This comment has been minimized.

Show comment
Hide comment
@cunei

cunei Mar 10, 2017

Contributor

@eed3si9n All right, LGTM.

Contributor

cunei commented Mar 10, 2017

@eed3si9n All right, LGTM.

@eed3si9n eed3si9n merged commit 37e970c into master Mar 10, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@eed3si9n eed3si9n deleted the wip/jdk9 branch Mar 10, 2017

@eed3si9n eed3si9n referenced this pull request Mar 11, 2017

Closed

JDK 9 (Java 9) support #142

@xuwei-k xuwei-k referenced this pull request in xerial/sbt-jcheckstyle Mar 21, 2017

Closed

support Java 9 #3

@ktoso ktoso referenced this pull request in akka/akka Jul 24, 2017

Closed

JDK9: Failed TcpTest, touches "sun.nio.ch" #23400

@jackkoenig jackkoenig referenced this pull request in freechipsproject/firrtl Nov 30, 2017

Closed

"sbt assembly" fails: Java version check failure? #691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment