scala/bug

compiler does not work with "-opt:l:method" on JDK10

xuwei-k opened this issue ยท 20 comments

package example

class Foo
$ scala -version
Scala code runner version 2.13.0-M3 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
$ java -version
java version "10-ea" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10-ea+42)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10-ea+42, mixed mode)
$ scalac -opt:l:method Foo.scala
error: java.lang.IllegalArgumentException
	at scala.tools.asm.ClassReader.<init>(ClassReader.java:160)
	at scala.tools.asm.ClassReader.<init>(ClassReader.java:143)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.$anonfun$parseClass$1(ByteCodeRepository.scala:257)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.parseClass(ByteCodeRepository.scala:255)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.$anonfun$parsedClassNode$1(ByteCodeRepository.scala:70)
	at scala.collection.mutable.MapLike.getOrElseUpdate(MapLike.scala:202)
	at scala.collection.mutable.MapLike.getOrElseUpdate$(MapLike.scala:199)
	at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:80)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.parsedClassNode(ByteCodeRepository.scala:70)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.classNode(ByteCodeRepository.scala:91)
	at scala.tools.nsc.backend.jvm.opt.ByteCodeRepository.methodNode(ByteCodeRepository.scala:239)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.$anonfun$addMethod$2(CallGraph.scala:151)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.$anonfun$addMethod$2$adapted(CallGraph.scala:148)
	at scala.collection.Iterator.foreach(Iterator.scala:938)
	at scala.collection.Iterator.foreach$(Iterator.scala:938)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1426)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.addMethod(CallGraph.scala:148)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.$anonfun$addClass$1(CallGraph.scala:107)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.$anonfun$addClass$1$adapted(CallGraph.scala:107)
	at scala.collection.Iterator.foreach(Iterator.scala:938)
	at scala.collection.Iterator.foreach$(Iterator.scala:938)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1426)
	at scala.collection.IterableLike.foreach(IterableLike.scala:71)
	at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
	at scala.tools.nsc.backend.jvm.opt.CallGraph.addClass(CallGraph.scala:107)
	at scala.tools.nsc.backend.jvm.PostProcessor.$anonfun$runGlobalOptimizations$3(PostProcessor.scala:86)
	at scala.tools.nsc.backend.jvm.PostProcessor.$anonfun$runGlobalOptimizations$3$adapted(PostProcessor.scala:84)
	at scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:785)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.collection.generic.TraversableForwarder.foreach(TraversableForwarder.scala:35)
	at scala.collection.generic.TraversableForwarder.foreach$(TraversableForwarder.scala:35)
	at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:44)
	at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:784)
	at scala.tools.nsc.backend.jvm.PostProcessor.runGlobalOptimizations(PostProcessor.scala:84)
	at scala.tools.nsc.backend.jvm.PostProcessor.postProcessAndSendToDisk(PostProcessor.scala:46)
	at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.$anonfun$run$1(GenBCode.scala:54)
	at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.run(GenBCode.scala:51)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1453)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1437)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1429)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1546)
	at scala.tools.nsc.Driver.doCompile(Driver.scala:35)
	at scala.tools.nsc.MainClass.doCompile(Main.scala:24)
	at scala.tools.nsc.Driver.process(Driver.scala:55)
	at scala.tools.nsc.Driver.main(Driver.scala:68)
	at scala.tools.nsc.Main.main(Main.scala)
lrytz commented

So this issue should fix itself when we upgrade to asm 6.1 (not yet released), which will include the two commits listed above.

ijuma commented

Is there a plan to upgrade to ASM 6.1 in the Scala 2.12 series?

lrytz commented

In general we keep ASM up to date, so I'll probably do it for 2.12. Watching the asm issue tracker, I saw one regression in 6.1 that might be relevant to us: https://gitlab.ow2.org/asm/asm/issues/317815. If we do the update we need to look at this in more detail to see if it affects us. In any case, I'm busy right now with other stuff :)

ijuma commented

Thanks for the information.

mkurz commented

ASM 6.1.1 has been tagged and also availabe via the maven repos already.
https://gitlab.ow2.org/asm/asm/tags

@lrytz Feasible in 2.12.6?

version "10-ea" 2018-03-20 and 18.3 ? :-)

We will (carefully) consider an ASM upgrade for 2.12.7, but not 2.12.6.

It would be a big help if someone could submit our patches in scala/scala-asm upstream to https://gitlab.ow2.org/asm/asm, so that we could switch to using an official asm release. That would simplify upgrading to the latest ASM a lot! (EDIT: the differences are small, but essential for us -- we think they could all go upstream, but just haven't found the time to do so...)

I got the same compiler crash on JDK 10 with Scala 2.12.x.

/usr/lib/jvm/jdk-10/bin/java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

Sources: https://github.com/plokhotnyuk/jsoniter-scala
Command to reproduce:
sbt -java-home /usr/lib/jvm/jdk-10 -no-colors clean test

It fails with 2.12.4 too, but works fine for 2.11.12:
sbt -java-home /usr/lib/jvm/jdk-10 -no-colors ++2.11.12 clean test

lrytz commented

Just for reference; ASM 6.1.x has an issue that might affect us (https://gitlab.ow2.org/asm/asm/merge_requests/160), which will be fixed only in 6.2

On JDK 10 I am getting the same while compiling Zinc, which recently added List("-opt-inline-from:<sources>", "-opt:l:inline", "-Yopt-inline-heuristics:at-inline-annotated") sbt/zinc#492

mkurz commented

ASM 6.2 released with better JDK 10 support and even with JDK 11 support already!
http://asm.ow2.io/versions.html
https://gitlab.ow2.org/asm/asm/tags
https://gitlab.ow2.org/asm/asm/issues/317830

@lrytz referenced pr merged to 2.13.x branch only... will it be backported to 2.12.x?

lrytz commented

it should be, let's keep this open.

FYI, similar issue with JDK12+ #11372