summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/CompileServer.scala
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2008-10-22 09:46:19 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2008-10-22 09:46:19 +0000
commitc06b1d3f61f8d1bdf4d8ad58c97fec2c51e1e9f2 (patch)
treeab95adaea8cb03ee33b0e9a97a5a37cb186ca31d /src/compiler/scala/tools/nsc/CompileServer.scala
parentf9924c9efdeb247b0ed330e70391aec0966555e9 (diff)
downloadscala-c06b1d3f61f8d1bdf4d8ad58c97fec2c51e1e9f2.tar.gz
scala-c06b1d3f61f8d1bdf4d8ad58c97fec2c51e1e9f2.tar.bz2
scala-c06b1d3f61f8d1bdf4d8ad58c97fec2c51e1e9f2.zip
fsc watchdog removal.
In addition, fixed a potential initialization problem in the fsc server, which would open a socket, get a port number, and close the socket, only to try to reallocate the same port number a bit later, even though the port might have become unavailable in the meantime. Now the socket is initialized only once, and the port is not released.
Diffstat (limited to 'src/compiler/scala/tools/nsc/CompileServer.scala')
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala127
1 files changed, 54 insertions, 73 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala
index 541aadaffa..e652f8d6ec 100644
--- a/src/compiler/scala/tools/nsc/CompileServer.scala
+++ b/src/compiler/scala/tools/nsc/CompileServer.scala
@@ -35,8 +35,6 @@ class StandardCompileServer extends SocketServer {
var shutDown: Boolean = false
private var compiler: Global = null
- private var inSession: Boolean = false
- private var progress: Boolean = false
private def settingsAreCompatible(s1: Settings, s2: Settings) = s1 == s2
@@ -46,20 +44,6 @@ class StandardCompileServer extends SocketServer {
Predef.exit(code)
}
- private def spawnWatchDog(): Unit = spawn {
- while (true) {
- Thread.sleep(10000)
- if (!compileSocket.portFile(port).exists() && !inSession) {
- progress = false
- spawn {
- Thread.sleep(10000)
- if (!progress)
- fatal("port file no longer exists; exiting")
- }
- }
- }
- }
-
private val runtime = Runtime.getRuntime()
var reporter: ConsoleReporter = _
@@ -71,6 +55,10 @@ class StandardCompileServer extends SocketServer {
override def inform(msg: String) = out.println(msg)
}
+ override def timeout() {
+ if (!compileSocket.portFile(port).exists())
+ fatal("port file no longer exists; skipping cleanup")
+ }
protected def newOfflineCompilerCommand(
arguments: List[String],
@@ -89,68 +77,62 @@ class StandardCompileServer extends SocketServer {
val guessedPassword = in.readLine()
val input = in.readLine()
if ((input ne null) && password == guessedPassword) {
- try {
- inSession = true
- progress = true
- val args = input.split("\0",-1).toList
- if (args contains "-shutdown") {
- out.println("[Compile server exited]")
- shutDown = true
- return
- }
- if (args contains "-reset") {
- out.println("[Compile server was reset]")
- compiler = null
- return
- }
- def error(msg: String) {
- out.println(/*new Position*/ FakePos("fsc"),
- msg + "\n fsc -help gives more information")
- }
- val command = newOfflineCompilerCommand(args, new Settings(error), error, false)
-
- reporter = new ConsoleReporter(command.settings, in, out) {
- // disable prompts, so that compile server cannot block
- override def displayPrompt = ()
- }
-
- if (command.shouldStopWithInfo) {
- reporter.info(null,
- command.getInfoMessage(newGlobal(command.settings, reporter)), true)
+ val args = input.split("\0",-1).toList
+ if (args contains "-shutdown") {
+ out.println("[Compile server exited]")
+ shutDown = true
+ return
+ }
+ if (args contains "-reset") {
+ out.println("[Compile server was reset]")
+ compiler = null
+ return
+ }
+ def error(msg: String) {
+ out.println(/*new Position*/ FakePos("fsc"),
+ msg + "\n fsc -help gives more information")
+ }
+ val command = newOfflineCompilerCommand(args, new Settings(error), error, false)
+
+ reporter = new ConsoleReporter(command.settings, in, out) {
+ // disable prompts, so that compile server cannot block
+ override def displayPrompt = ()
+ }
+
+ if (command.shouldStopWithInfo) {
+ reporter.info(null,
+ command.getInfoMessage(newGlobal(command.settings, reporter)), true)
} else if (command.files.isEmpty)
- reporter.info(null, command.usageMsg, true)
- else {
- try {
- if ((compiler ne null) && settingsAreCompatible(command.settings, compiler.settings)) {
- compiler.settings = command.settings
- compiler.reporter = reporter
- } else {
- if (args contains "-verbose")
- out.println("[Starting new compile server instance]")
- compiler = newGlobal(command.settings, reporter)
- }
- val c = compiler
- val run = new c.Run
- run compile command.files
- } catch {
- case ex @ FatalError(msg) =>
- if (command.settings.debug.value)
- ex.printStackTrace(out);
+ reporter.info(null, command.usageMsg, true)
+ else {
+ try {
+ if ((compiler ne null) && settingsAreCompatible(command.settings, compiler.settings)) {
+ compiler.settings = command.settings
+ compiler.reporter = reporter
+ } else {
+ if (args contains "-verbose")
+ out.println("[Starting new compile server instance]")
+ compiler = newGlobal(command.settings, reporter)
+ }
+ val c = compiler
+ val run = new c.Run
+ run compile command.files
+ } catch {
+ case ex @ FatalError(msg) =>
+ if (command.settings.debug.value)
+ ex.printStackTrace(out);
reporter.error(null, "fatal error: " + msg)
compiler = null
- case ex: Throwable =>
- ex.printStackTrace(out);
+ case ex: Throwable =>
+ ex.printStackTrace(out);
reporter.error(null, "fatal error (server aborted): " + ex.getMessage())
shutDown = true
+ }
+ reporter.printSummary()
+ runtime.gc()
+ if ((runtime.totalMemory() - runtime.freeMemory()).toDouble /
+ runtime.maxMemory().toDouble > MaxCharge) compiler = null
}
- reporter.printSummary()
- runtime.gc()
- if ((runtime.totalMemory() - runtime.freeMemory()).toDouble /
- runtime.maxMemory().toDouble > MaxCharge) compiler = null
- }
- } finally {
- inSession = false
- }
}
}
@@ -171,7 +153,6 @@ class StandardCompileServer extends SocketServer {
redirect(System.setErr, "scala-compile-server-err.log")
System.err.println("...starting server on socket "+port+"...")
System.err.flush()
- spawnWatchDog()
compileSocket.setPort(port)
run()
compileSocket.deletePort(port)