From a950cbfd9b503146f2737f6a8946ad9c1fdb2033 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 8 Aug 2019 13:58:19 +1000 Subject: [PATCH 1/2] Install caching FSInfo in javac to avoid repeated JAR manifest lookups --- src/compiler/scala/tools/nsc/PipelineMain.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/compiler/scala/tools/nsc/PipelineMain.scala b/src/compiler/scala/tools/nsc/PipelineMain.scala index ee977974470a..fe6302b635d4 100644 --- a/src/compiler/scala/tools/nsc/PipelineMain.scala +++ b/src/compiler/scala/tools/nsc/PipelineMain.scala @@ -57,6 +57,10 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe private var reporter: Reporter = _ + private lazy val fsInfo: Option[Any] = { + Try(Class.forName("com.sun.tools.javac.file.CacheFSInfo").newInstance()).toOption + } + private object handler extends UncaughtExceptionHandler { override def uncaughtException(t: Thread, e: Throwable): Unit = { e.printStackTrace() @@ -568,8 +572,20 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe } } val fileManager = ToolProvider.getSystemJavaCompiler.getStandardFileManager(null, null, null) + fsInfo.foreach { fsInfo => + try { + val fsInfoField = fileManager.getClass.getDeclaredField("fsInfo") + fsInfoField.setAccessible(true) + fsInfoField.set(fileManager, fsInfo) + } catch { + case t: Throwable => + t.printStackTrace() + } + } val compileTask = compiler.getTask(null, fileManager, listener, opts, null, fileManager.getJavaFileObjects(javaSources.toArray: _*)) compileTask.setProcessors(Collections.emptyList()) + try + if (compileTask.call()) { javaTimer.stop() log(f"javac: done ${javaTimer.durationMs}%.0f ms ") From b71ddd0a36b466f47fe360c3c50e243ae4482e25 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 8 Aug 2019 14:00:20 +1000 Subject: [PATCH 2/2] Clear javac's FSInfo cache after pipeline build --- src/compiler/scala/tools/nsc/PipelineMain.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compiler/scala/tools/nsc/PipelineMain.scala b/src/compiler/scala/tools/nsc/PipelineMain.scala index fe6302b635d4..3563513e6ac1 100644 --- a/src/compiler/scala/tools/nsc/PipelineMain.scala +++ b/src/compiler/scala/tools/nsc/PipelineMain.scala @@ -312,6 +312,14 @@ class PipelineMainClass(argFiles: Seq[Path], pipelineSettings: PipelineMain.Pipe writeChromeTrace(dir, projects) } deleteTempPickleCache() + fsInfo.foreach { fsInfo => + try { + fsInfo.getClass.getDeclaredMethod("clearCache").invoke(fsInfo) + } catch { + case _: Throwable => + // ignore + } + } !reporter.hasErrors }