Higher optimization levels (O1+) produce NPE-throwing code

Description

The optimizing compiler (at levels O1 or higher) seems to produce incorrect code for a method from the scalap benchmarks of the Scala benchmark suite found at http://repo.scalabench.org/snapshots/org/scalabench/benchmarks/scala-benchmark-suite/0.1.0-SNAPSHOT/scala-benchmark-suite-0.1.0-20120216.103539-3.jar.
When run with ./dist/production_ia32-linux/rvm -X:aos:enable_recompilation=false -X:aos:initial_compiler=opt -X:irc:O1 -jar scala-benchmark-suite-0.1.0-20120216.103539-3.jar scalap --preserve the following exception ensues:

Caused by: java.lang.NullPointerException
at scala.tools.scalap.scalax.rules.StateRules$class.apply(Rules.scala:88)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$.apply(ScalaSig.scala:56)
at scala.tools.scalap.scalax.rules.scalasig.ByteCodeReader$class.bytes(ClassFileParser.scala:92)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$$anonfun$3.apply(ScalaSig.scala:70)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$$anonfun$3.apply(ScalaSig.scala:70)
at scala.tools.scalap.scalax.rules.Rule$$anonfun$flatMap$1.apply(Rule.scala:35)
at scala.tools.scalap.scalax.rules.Rule$$anonfun$flatMap$1.apply(Rule.scala:34)
at scala.tools.scalap.scalax.rules.Rule$$anonfun$mapResult$1.apply(Rule.scala:45)
at scala.tools.scalap.scalax.rules.Rule$$anonfun$mapResult$1.apply(Rule.scala:45)
at scala.tools.scalap.scalax.rules.Rules$DefaultRule.apply(Rules.scala:62)
at scala.tools.scalap.scalax.rules.Rules$DefaultRule.apply(Rules.scala:60)
...

When limiting oneself to -X:aos:initial_compiler=opt -X:irc:O0 or -X:aos:initial_compiler=base, this exception does not show up.

Unfortunately, this NPE is harder to pinpoint to a specific cause the the ClassCastException of RVM-957; I was unable to find minimal compiler advice that triggers this exact exception. However, the attached compiler advice file does trigger a (hopefully related) NPE occuring at the same bytecode index (7) in scala.tools.scalap.scalax.rules.StateRules$class.apply(scala.tools.scalap.scalax.rules.StateRules, scala.Function1).

Caused by: java.lang.NullPointerException
at scala.tools.scalap.scalax.rules.StateRules$class.apply(Rules.scala:88)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$.apply(ScalaSig.scala:56)
at scala.tools.scalap.scalax.rules.scalasig.ByteCodeReader$class.$init$(ClassFileParser.scala:86)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$.<init>(ScalaSig.scala:56)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigAttributeParsers$.<clinit>(ScalaSig.scala:0)
at org.jikesrvm.classloader.RVMClass.initialize(RVMClass.java:1541)
at org.jikesrvm.runtime.RuntimeEntrypoints.initializeClassForDynamicLink(RuntimeEntrypoints.java:616)
at org.jikesrvm.classloader.TableBasedDynamicLinker.resolveMember(TableBasedDynamicLinker.java:76)
at org.jikesrvm.classloader.TableBasedDynamicLinker.resolveMember(TableBasedDynamicLinker.java:65)
at scala.tools.scalap.scalax.rules.scalasig.ScalaSigParser$$anonfun$scalaSigFromAttribute$2.apply(ScalaSig.scala:35)
...

To preproduce the latter exception, which shouldn't be caused by a mere optimization either, simply run the following: ./dist/production_ia32-linux/rvm -X:aos:initial_compiler=base -X:aos:enable_precompile=true -X:aos:enable_recompilation=false -X:aos:cafi=scalap.ca -jar scala-benchmark-suite-0.1.0-20120216.103539-3.jar scalap --preserve

Again, I have tested this on OpenJDK (build 19.0-b09) using both the Client and Server compiler with forced compilation (-Xcomp): in neither case the scalap benchmark fails with a NPE.

Environment

host.name=ia32-linux
config.name=production

Status

Assignee

Unassigned

Reporter

Andreas Sewe

Labels

None

Components

Fix versions

Affects versions

Priority

Medium
Configure