Skip to content

Preliminary support for Java 9 #5385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2016
Merged

Preliminary support for Java 9 #5385

merged 3 commits into from
Dec 2, 2016

Conversation

retronym
Copy link
Member

@retronym retronym commented Sep 8, 2016

Includes a fix for SI-9833

@scala-jenkins scala-jenkins added this to the 2.12.1 milestone Sep 8, 2016
@retronym
Copy link
Member Author

retronym commented Sep 8, 2016

First parts of the big TODO list at scala/scala-dev#139

@retronym
Copy link
Member Author

/rebuild

@retronym retronym force-pushed the topic/JEP-220 branch 2 times, most recently from b718eab to 2db7e8d Compare October 16, 2016 08:23
@retronym
Copy link
Member Author

!! 1330 - run/t6439.scala                           [non-zero exit code]
##### Log file '/home/jenkins/workspace/scala-2.12.x-validate-test/test/files/run/t6439-run.log' from failed test #####

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0

!! 1331 - run/t6507.scala                           [non-zero exit code]
##### Log file '/home/jenkins/workspace/scala-2.12.x-validate-test/test/files/run/t6507-run.log' from failed test #####

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0

ok 1332 - run/t6559.scala                         
ok 1333 - run/t657.scala                          
!! 1334 - run/t6502.scala                           [non-zero exit code]
##### Log file '/home/jenkins/workspace/scala-2.12.x-validate-test/test/files/run/t6502-run.log' from failed test #####

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0

ok 1335 - run/t6574b.scala  

@retronym
Copy link
Member Author

/rebuild

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, not sure about the MiMa failure..

override def output = Files.newOutputStream(nioPath)
override def sizeOption = Some(Files.size(nioPath).toInt)

override def toString = path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean fpath?

/** Delete the underlying file or directory (recursively). */
def delete(): Unit =
if (Files.isRegularFile(nioPath)) Files.deleteIfExists(nioPath)
else if (Files.isDirectory(nioPath)) ??? // TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not relevant, but for now you could do new Directory(file).deleteRecursively()

protected def toAbstractFile(f: Path): AbstractFile = new scala.reflect.io.PlainNioFile(f)
protected def isPackage(f: Path): Boolean = Files.isDirectory(f) && mayBeValidPackage(f.getFileName.toString)

assert(dir != null, "Directory file in DirectoryFileLookup cannot be null")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this up to the field definition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it altogether, it can't trip in this class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's still there..

def name = nioPath.getFileName.toString

/** Returns the path of this abstract file. */
def path = nioPath.getParent.toString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getParent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Fixed that, and I've also stress tested this by using it by default for a commit (then chickening out and reverting it in the following commit)

@retronym retronym force-pushed the topic/JEP-220 branch 4 times, most recently from bc40deb to 7fb1e92 Compare December 1, 2016 02:14
@retronym
Copy link
Member Author

retronym commented Dec 1, 2016

Looks good, not sure about the MiMa failure..

I've marked NioFile as private[scala] and whitelisted. If we prefer, I could move it to reflect.internal.io.NioFile

@lrytz
Copy link
Member

lrytz commented Dec 1, 2016

LGTM, maybe squash the last 4

def apply(): List[ClassPath] = {
try {
val fs = FileSystems.getFileSystem(URI.create("jrt:/"))
val dir: Path = fs.getPath("/modules")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, where's the spec for jrt:/modules/...? in http://openjdk.java.net/jeps/220 i could only find

A jrt URL is a hierarchical URI, per RFC 3986, with the syntax jrt:/[$MODULE[/$PATH]]

and

jrt:/ refers to the entire collection of class and resource files stored in the current run-time image.

example: jrt:/java.base/java/lang/Class.class


OK, Google. https://bugs.openjdk.java.net/browse/JDK-8066492

protected def toAbstractFile(f: Path): AbstractFile = new scala.reflect.io.PlainNioFile(f)
protected def isPackage(f: Path): Boolean = Files.isDirectory(f) && mayBeValidPackage(f.getFileName.toString)

assert(dir != null, "Directory file in DirectoryFileLookup cannot be null")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's still there..

@adriaanm
Copy link
Contributor

adriaanm commented Dec 2, 2016

Needs a rebase (and some squashing?)

This was not having the desired effect of placing the
Scala library on the JVM's regular classpath.

This commit honours this setting.

Note that the Windows scripts have never supported
the use of bootclasspath, so no changes are required.

The existing bug:

```
(java_use 1.8; ~/scala/2.11.8/bin/scala -nobootcp -debug -e 'print("")')

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java
-Xmx256M
-Xms32M
-Xbootclasspath/a:/Users/jason/scala/2.11.8/lib/akka-actor_2.11-2.3.10.jar:/Users/jason/scala/2.11.8/lib/config-1.2.1.jar:/Users/jason/scala/2.11.8/lib/jline-2.12.1.jar:/Users/jason/scala/2.11.8/lib/scala-actors-2.11.0.jar:/Users/jason/scala/2.11.8/lib/scala-actors-migration_2.11-1.1.0.jar:/Users/jason/scala/2.11.8/lib/scala-compiler.jar:/Users/jason/scala/2.11.8/lib/scala-continuations-library_2.11-1.0.2.jar:/Users/jason/scala/2.11.8/lib/scala-continuations-plugin_2.11.8-1.0.2.jar:/Users/jason/scala/2.11.8/lib/scala-library.jar:/Users/jason/scala/2.11.8/lib/scala-parser-combinators_2.11-1.0.4.jar:/Users/jason/scala/2.11.8/lib/scala-reflect.jar:/Users/jason/scala/2.11.8/lib/scala-swing_2.11-1.0.2.jar:/Users/jason/scala/2.11.8/lib/scala-xml_2.11-1.0.4.jar:/Users/jason/scala/2.11.8/lib/scalap-2.11.8.jar
-classpath
""
-Dscala.home=/Users/jason/scala/2.11.8
-Dscala.usejavacp=true
-Denv.emacs=
scala.tools.nsc.MainGenericRunner

print("")
```

Fixed by this patch:

```
⚡ (java_use 1.8; qscala -nobootcp -debug -e 'print("")')

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java
-Xmx256M
-Xms32M
-classpath
/Users/jason/code/scala/build/quick/classes/repl-jline-embedded:/Users/jason/code/scala/build/quick/classes/repl-jline:/Users/jason/code/scala/build/quick/classes/repl:/Users/jason/code/scala/build/quick/classes/compiler:/Users/jason/code/scala/build/quick/classes/library:/Users/jason/code/scala/build/quick/classes/reflect:/Users/jason/code/scala/build/quick/classes/interactive:/Users/jason/.ivy2/cache/org.apache.ant/ant/jars/ant-1.9.4.jar:/Users/jason/.ivy2/cache/org.apache.ant/ant-launcher/jars/ant-launcher-1.9.4.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles/scala-asm-5.1.0-scala-1.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12.0-RC1/bundles/scala-xml_2.12.0-RC1-1.0.5.jar:/Users/jason/.ivy2/cache/jline/jline/jars/jline-2.14.1.jar
-Dscala.home=/Users/jason/code/scala/build/quick
-Dscala.usejavacp=true
-Denv.emacs=
scala.tools.nsc.MainGenericRunner
-nc

print("")
```
In Java 9. we can no longer introspect the boot classpath with
a JVM provided system property. Instead, this commit passes
a custom property which will be found by PathResolver when it
constructs the compiler classpath.
http://openjdk.java.net/jeps/220 changes the layout of the
JDK to encapsulate the provided libraries with the new module
system.

This commit modifies the compiler's classpath implementation
to scan the new location of these, the `jrt://` virtual filesystem.

This might need to be adjusted once we provide a means for
users to specify the subset of modules that they want to
depend on, but for now reclaims the ground we lost.

```
⚡ (java_use 9-ea; qscala)
Welcome to Scala 2.12.0-20160908-223617-7e4ebda (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea).
Type in expressions for evaluation. Or try :help.

scala> import StackWalker._, java.util.stream._, scala.collection.JavaConverters._
import StackWalker._
import java.util.stream._
import scala.collection.JavaConverters._

scala> (() => StackWalker.getInstance(java.util.EnumSet.of(Option.RETAIN_CLASS_REFERENCE)).walk[Seq[String]]((s: java.util.stream.Stream[StackFrame]) => s.iterator.asScala.take(3).map(_.toString).toList)).apply().mkString("\n")
res0: String =
.$anonfun$res0$1(<console>:21)
.<init>(<console>:21)
.<clinit>(<console>)

scala>
```

I've marked the new class, `NioFile` as `private[scala]` to justify
the forward compatibility whitelist entry.

In principle we could use NioFile more widely rather than `PlainFile`
I tried this out in b2d0a17a
which passed CI. But to be conservative, I'm not submitting that change
at this point.
@retronym
Copy link
Member Author

retronym commented Dec 2, 2016

All done.

@lrytz lrytz merged commit ccfa360 into scala:2.12.x Dec 2, 2016
@SethTisue
Copy link
Member

Should we release-note this? Or is it not enough Java 9 support to yet be worth highlighting?

@lrytz
Copy link
Member

lrytz commented Dec 2, 2016

I'm fine either way. Not sure how much testing Jason did on JDK 9, the only thing I did was 1+1 in the REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants