Skip to content
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

Enable javac's FSInfo caching #58

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 24 additions & 0 deletions src/compiler/scala/tools/nsc/PipelineMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -308,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
}

Expand Down Expand Up @@ -568,8 +580,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 ")
Expand Down