Skip to content

Fail jhm on error and fix benchmarks #5020

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 5 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions bench/src/main/scala/Benchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,10 +36,9 @@ object Bench {
}
storeCompileOptions(args2)

val libs = System.getProperty("BENCH_CLASS_PATH")

val opts = new OptionsBuilder()
.jvmArgsPrepend(s"-classpath $libs", "-Xms2G", "-Xmx2G")
.shouldFailOnError(true)
.jvmArgs("-Xms2G", "-Xmx2G")
.mode(Mode.AverageTime)
.timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(warmup)
Expand All @@ -54,9 +55,20 @@ object Bench {
def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete()

def storeCompileOptions(args: Array[String]): Unit = {
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is -with-compiler used anywhere? Where would it be used?
If this is used, we should test it in the project/scripts/cmdTests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, it'll used in the benchmarks to test "dotty". I'll add it to project/scripts/cmdTests.

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"))
bw.write(argsNorm.mkString("", "\n", "\n"))
bw.close()
}

Expand All @@ -75,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)
Expand Down
3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions project/scripts/cmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down