summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2011-03-31 13:51:21 +0000
committerIulian Dragos <jaguarul@gmail.com>2011-03-31 13:51:21 +0000
commit74a967da857ead23ec5d976c6616ac98fb7c33ef (patch)
treeb5a41651af980c8572b42244a66140af0fab3110
parent2a76132a56c7c426d55f563792b95ba073f83c5c (diff)
downloadscala-74a967da857ead23ec5d976c6616ac98fb7c33ef.tar.gz
scala-74a967da857ead23ec5d976c6616ac98fb7c33ef.tar.bz2
scala-74a967da857ead23ec5d976c6616ac98fb7c33ef.zip
Merged revisions 24647,24649 via svnmerge from
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk ........ r24647 | dragos | 2011-03-31 10:12:40 +0200 (Thu, 31 Mar 2011) | 1 line Don't create a new thread on each presentation compiler crash. Solves race conditions in outstanding maps (should fix deadlocks in the IDE). Added project name to the thread name and log messages. no review. ........ r24649 | dragos | 2011-03-31 15:42:23 +0200 (Thu, 31 Mar 2011) | 1 line Allow the presentation thread to terminate when the compiler is shut down. no review. ........
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala36
2 files changed, 19 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index a2426d2212..ddc870a045 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -24,7 +24,7 @@ import scala.reflect.generic.Flags.{ACCESSOR, PARAMACCESSOR}
/** The main class of the presentation compiler in an interactive environment such as an IDE
*/
-class Global(settings: Settings, reporter: Reporter)
+class Global(settings: Settings, reporter: Reporter, projectName: String = "")
extends scala.tools.nsc.Global(settings, reporter)
with CompilerControl
with RangePositions
@@ -61,11 +61,11 @@ class Global(settings: Settings, reporter: Reporter)
/** Print msg only when debugIDE is true. */
@inline final def debugLog(msg: => String) =
- if (debugIDE) println(msg)
+ if (debugIDE) println("[%s] %s".format(projectName, msg))
/** Inform with msg only when verboseIDE is true. */
@inline final def informIDE(msg: => String) =
- if (verboseIDE) println("["+msg+"]")
+ if (verboseIDE) println("[%s][%s]".format(projectName, msg))
override def forInteractive = true
@@ -390,9 +390,9 @@ class Global(settings: Settings, reporter: Reporter)
/** Create a new presentation compiler runner.
*/
- private[interactive] def newRunnerThread(): Thread = {
+ private def newRunnerThread(): Thread = {
threadId += 1
- compileRunner = new PresentationCompilerThread(this, threadId)
+ compileRunner = new PresentationCompilerThread(this, projectName)
compileRunner.start()
compileRunner
}
diff --git a/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala b/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
index b61d7f6638..4ba0208c39 100644
--- a/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
+++ b/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
@@ -8,30 +8,26 @@ package scala.tools.nsc.interactive
/** A presentation compiler thread. This is a lightweight class, delegating most
* of its functionality to the compiler instance.
*
- * @note This thread class may not be GCd, so it's important not to keep around
- * large objects. For instance, the JDT weaving framework keeps threads around
- * in a map, preventing them from being GCd. This prompted the separation between
- * interactive.Global and this class.
*/
-class PresentationCompilerThread(var compiler: Global, threadId: Int) extends Thread("Scala Presentation Compiler V"+threadId) {
+final class PresentationCompilerThread(var compiler: Global, name: String = "")
+ extends Thread("Scala Presentation Compiler [" + name + "]") {
+
/** The presentation compiler loop.
*/
override def run() {
compiler.debugLog("starting new runner thread")
- try {
- while (true) {
- compiler.checkNoResponsesOutstanding()
- compiler.log.logreplay("wait for more work", { compiler.scheduler.waitForMoreWork(); true })
- compiler.pollForWork(compiler.NoPosition)
- while (compiler.isOutOfDate) {
- try {
- compiler.backgroundCompile()
- } catch {
- case FreshRunReq =>
- compiler.debugLog("fresh run req caught, starting new pass")
- }
- compiler.log.flush()
+ while (compiler ne null) try {
+ compiler.checkNoResponsesOutstanding()
+ compiler.log.logreplay("wait for more work", { compiler.scheduler.waitForMoreWork(); true })
+ compiler.pollForWork(compiler.NoPosition)
+ while (compiler.isOutOfDate) {
+ try {
+ compiler.backgroundCompile()
+ } catch {
+ case FreshRunReq =>
+ compiler.debugLog("fresh run req caught, starting new pass")
}
+ compiler.log.flush()
}
} catch {
case ex @ ShutdownReq =>
@@ -42,7 +38,6 @@ class PresentationCompilerThread(var compiler: Global, threadId: Int) extends Th
compiler = null
case ex =>
compiler.log.flush()
- compiler.newRunnerThread()
ex match {
case FreshRunReq =>
@@ -51,9 +46,6 @@ class PresentationCompilerThread(var compiler: Global, threadId: Int) extends Th
compiler.debugLog("validate exception caught outside presentation compiler loop; ignored")
case _ => ex.printStackTrace(); compiler.informIDE("Fatal Error: "+ex)
}
-
- // make sure we don't keep around stale instances
- compiler = null
}
}
}