From 6f55382870cb26c908ae04ef4c73507a854abda5 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sun, 26 Aug 2018 12:45:03 +0200 Subject: [PATCH 1/5] fail jhm on error --- bench/src/main/scala/Benchmarks.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index b3224e6ee97b..411ff7593a5f 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -37,6 +37,7 @@ object Bench { val libs = System.getProperty("BENCH_CLASS_PATH") val opts = new OptionsBuilder() + .shouldFailOnError(true) .jvmArgsPrepend(s"-classpath $libs", "-Xms2G", "-Xmx2G") .mode(Mode.AverageTime) .timeUnit(TimeUnit.MILLISECONDS) From 8ea863b479eb0ffe9a8d32dc27abf36cec5d4ad2 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sun, 26 Aug 2018 13:07:43 +0200 Subject: [PATCH 2/5] fix benchmarks The classpath is intended for type checking, not for compiler run-time. Thus, they should be passed as compiler options, not JVM options. It works before because the compiler makes bootstrap classpath available for type checking. However, we can no longer use bootstrap classpath after Java 9 support (#3138). --- bench/src/main/scala/Benchmarks.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index 411ff7593a5f..f3c7567c3d0d 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -34,11 +34,9 @@ object Bench { } storeCompileOptions(args2) - val libs = System.getProperty("BENCH_CLASS_PATH") - val opts = new OptionsBuilder() .shouldFailOnError(true) - .jvmArgsPrepend(s"-classpath $libs", "-Xms2G", "-Xmx2G") + .jvmArgs("-Xms2G", "-Xmx2G") .mode(Mode.AverageTime) .timeUnit(TimeUnit.MILLISECONDS) .warmupIterations(warmup) @@ -55,9 +53,13 @@ object Bench { def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete() def storeCompileOptions(args: Array[String]): Unit = { + val libs = System.getProperty("BENCH_CLASS_PATH") + val file = new File(COMPILE_OPTS_FILE) val bw = new BufferedWriter(new FileWriter(file)) - bw.write(args.mkString("\n")) + bw.write(args.mkString("", "\n", "\n")) + bw.write("-classpath\n") + bw.write(libs) bw.close() } From 92f3cd515d7edccd599ce2c1397a8ff52b4e956d Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 27 Aug 2018 11:11:01 +0200 Subject: [PATCH 3/5] introduce -with-compiler and merge with user -classpath --- bench/src/main/scala/Benchmarks.scala | 15 +++++++++++---- project/Build.scala | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index f3c7567c3d0d..3a86daefc442 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -53,13 +53,20 @@ object Bench { def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete() def storeCompileOptions(args: Array[String]): Unit = { - val libs = System.getProperty("BENCH_CLASS_PATH") + val standard_libs = System.getProperty("BENCH_CLASS_PATH") + val compiler_libs = System.getProperty("BENCH_COMPILER_CLASS_PATH") + + val libs = if (args.contains("-with-compiler")) compiler_libs else standard_libs + var argsNorm = args.filter(_ != "-with-compiler") + + var cpIndex = argsNorm.indexOf("-classpath") + if (cpIndex == -1) cpIndex = argsNorm.indexOf("-cp") + if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + ":" + libs + else argsNorm = argsNorm :+ "-classpath" :+ libs val file = new File(COMPILE_OPTS_FILE) val bw = new BufferedWriter(new FileWriter(file)) - bw.write(args.mkString("", "\n", "\n")) - bw.write("-classpath\n") - bw.write(libs) + bw.write(argsNorm.mkString("", "\n", "\n")) bw.close() } diff --git a/project/Build.scala b/project/Build.scala index e50bfa73362a..00f5fe84cc1a 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -302,7 +302,8 @@ object Build { lazy val commonBenchmarkSettings = Seq( outputStrategy := Some(StdoutOutput), mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run - javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in Compile).value).mkString("", ":", "") + javaOptions += "-DBENCH_COMPILER_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-bootstrapped`, Compile)).value).mkString("", ":", ""), + javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-library-bootstrapped`, Compile)).value).mkString("", ":", "") ) // sbt >= 0.13.12 will automatically rewrite transitive dependencies on From 614cf22d6bf4676a03a7eeccc426d1e614d5a3f6 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 27 Aug 2018 11:31:27 +0200 Subject: [PATCH 4/5] suppress summary information to ease parsing of test data --- bench/src/main/scala/Benchmarks.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index 3a86daefc442..b4c1a369aa33 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -2,6 +2,8 @@ package dotty.tools.benchmarks import dotty.tools.dotc._ import core.Contexts.Context +import dotty.tools.FatalError +import reporting._ import org.openjdk.jmh.results.RunResult import org.openjdk.jmh.runner.Runner @@ -85,6 +87,21 @@ class CompilerOptions { } class Worker extends Driver { + // override to avoid printing summary information + override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = + if (fileNames.nonEmpty) + try { + val run = compiler.newRun + run.compile(fileNames) + ctx.reporter + } + catch { + case ex: FatalError => + ctx.error(ex.getMessage) // signals that we should fail compilation. + ctx.reporter + } + else ctx.reporter + @Benchmark def compile(state: CompilerOptions): Unit = { val res = process(state.opts) From f247238657b502e732f0983e7270d22b7177a559 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 27 Aug 2018 14:57:31 +0200 Subject: [PATCH 5/5] test -with-compiler --- project/scripts/cmdTests | 1 + 1 file changed, 1 insertion(+) diff --git a/project/scripts/cmdTests b/project/scripts/cmdTests index 21473b2c3c7b..27d57480f6e2 100755 --- a/project/scripts/cmdTests +++ b/project/scripts/cmdTests @@ -12,6 +12,7 @@ EXPECTED_OUTPUT="hello world" # check that benchmarks can run "$SBT" "dotty-bench/jmh:run 1 1 tests/pos/alias.scala" "$SBT" "dotty-bench-bootstrapped/jmh:run 1 1 tests/pos/alias.scala" +"$SBT" "dotty-bench-bootstrapped/jmh:run 1 1 -with-compiler compiler/src/dotty/tools/dotc/core/Types.scala" OUT=$(mktemp -d) OUT1=$(mktemp -d)