Skip to content

jmh rules uses jmh hook that doesn't support Java 8 bytecode #295

@gkossakowski

Description

@gkossakowski

While upgrading the rules to Scala 2.12, we've run into mysterious:

ERROR: /Users/gkk/stripe/rules_scala/test/jmh/BUILD:23:1: Couldn't build file test/jmh/test_benchmark_codegen.srcjar: Generating benchmark code for //test/jmh:test_benchmark_codegen failed (Exit 1).
Exception in thread "main" java.lang.RuntimeException
	at org.objectweb.asm.MethodVisitor.visitParameter(Unknown Source)
	at org.objectweb.asm.ClassReader.b(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.openjdk.jmh.generators.asm.ASMGeneratorSource.processClass(ASMGeneratorSource.java:60)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.$anonfun$generateJmhBenchmark$3(BenchmarkGenerator.scala:140)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.$anonfun$generateJmhBenchmark$3$adapted(BenchmarkGenerator.scala:139)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.$anonfun$generateJmhBenchmark$2(BenchmarkGenerator.scala:139)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.withClassLoader(BenchmarkGenerator.scala:97)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.$anonfun$generateJmhBenchmark$1(BenchmarkGenerator.scala:134)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.$anonfun$generateJmhBenchmark$1$adapted(BenchmarkGenerator.scala:127)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.withTempDirectory(BenchmarkGenerator.scala:107)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.generateJmhBenchmark(BenchmarkGenerator.scala:127)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator$.main(BenchmarkGenerator.scala:43)
	at io.bazel.rules_scala.jmh_support.BenchmarkGenerator.main(BenchmarkGenerator.scala)

I traced this problem and it's unrelated to Scala 2.12 but related to Java 8 bytecode support. The culpirt is this place: http://hg.openjdk.java.net/code-tools/jmh/file/1ddf31f810a3/jmh-generator-asm/src/main/java/org/openjdk/jmh/generators/asm/ASMClassInfo.java#l65
(called indirectly from BenchmarkGenerator)

asm-based generator in jmh has ASM4 level of bytecode support hardcoded in it which means it supports bytecode up to Java 7. It doesn't look like there's a way to pass a newer version as a parameter so I suspect this code is not widely used.

For comparison, sbt-jmh is calling a different generator in asm: https://github.com/ktoso/sbt-jmh/blob/master/plugin/src/main/scala/pl/project13/scala/sbt/JmhPlugin.scala#L125

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions