From 894aee1347600201dd2decbd07bcf7820cbbee3d Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Fri, 7 Feb 2014 16:40:44 +0100 Subject: Start the PC thread only after initialization of required symbols. If the class path is incomplete, the presentation compiler might crash during construction. If the PC thread was already started, it will never get the chance to shutdown, and the thread leaks. In the IDE, where the PC is started when needed, this can lead to a very quick depletion of JVM threads. See Scala IDE #1002016. --- src/interactive/scala/tools/nsc/interactive/Global.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala index 0e897d6492..e5eeb25ddf 100644 --- a/src/interactive/scala/tools/nsc/interactive/Global.scala +++ b/src/interactive/scala/tools/nsc/interactive/Global.scala @@ -534,7 +534,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") threadId += 1 compileRunner = new PresentationCompilerThread(this, projectName) compileRunner.setDaemon(true) - compileRunner.start() compileRunner } @@ -1252,11 +1251,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") forceSymbolsUsedByParser() + /** Start the compiler background thread and turn on thread confinement checks */ + private def finishInitialization(): Unit = { + // this flag turns on `assertCorrectThread checks` + initializing = false + + // Only start the thread if initialization was successful. A crash while forcing symbols (for example + // if the Scala library is not on the classpath) can leave running threads behind. See Scala IDE #1002016 + compileRunner.start() + } + /** The compiler has been initialized. Constructors are evaluated in textual order, - * so this is set to true only after all super constructors and the primary constructor + * if we reached here, all super constructors and the primary constructor * have been executed. */ - initializing = false + finishInitialization() } object CancelException extends Exception -- cgit v1.2.3