diff options
author | Paul Phillips <paulp@improving.org> | 2011-07-06 17:28:04 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-07-06 17:28:04 +0000 |
commit | 262114974bfab763b282bf0aa2ec5b902fdd69f5 (patch) | |
tree | 02254d5a907ba32866384ef2fb214831dd2a8aaa /src/compiler/scala/reflect/internal/SymbolTable.scala | |
parent | a21cb1b3759fcb079c9bd21a598cc732d8481072 (diff) | |
download | scala-262114974bfab763b282bf0aa2ec5b902fdd69f5.tar.gz scala-262114974bfab763b282bf0aa2ec5b902fdd69f5.tar.bz2 scala-262114974bfab763b282bf0aa2ec5b902fdd69f5.zip |
Created simple infrastructure for creating muta...
Created simple infrastructure for creating mutable sets and maps which
are automatically cleared after each compilation run. Since I am not too
familiar with the mechanics of the presentation compiler I'm not sure
this addresses the problem, or that it doesn't clear something which
shouldn't be cleared. Also, this is only a sampling of possible mutable
sets and maps: let me know if it does the job and I can expand it.
Review by dragos.
Diffstat (limited to 'src/compiler/scala/reflect/internal/SymbolTable.scala')
-rw-r--r-- | src/compiler/scala/reflect/internal/SymbolTable.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/internal/SymbolTable.scala b/src/compiler/scala/reflect/internal/SymbolTable.scala index 5c4d44f735..df73feaccc 100644 --- a/src/compiler/scala/reflect/internal/SymbolTable.scala +++ b/src/compiler/scala/reflect/internal/SymbolTable.scala @@ -6,6 +6,7 @@ package scala.reflect package internal +import scala.collection.{ mutable, immutable } import util._ abstract class SymbolTable extends /*reflect.generic.Universe @@ -113,6 +114,38 @@ abstract class SymbolTable extends /*reflect.generic.Universe } } + object perRunCaches { + import java.lang.ref.WeakReference + + // We can allow ourselves a structural type, these methods + // amount to a few calls per run at most. This does suggest + // a "Clearable" trait may be useful. + private type Clearable = { + def size: Int + def clear(): Unit + } + // Weak references so the garbage collector will take care of + // letting us know when a cache is really out of commission. + private val caches = mutable.HashSet[WeakReference[Clearable]]() + + def clearAll() = { + if (settings.debug.value) { + val size = caches flatMap (ref => Option(ref.get)) map (_.size) sum; + log("Clearing " + caches.size + " caches totalling " + size + " entries.") + } + caches foreach { ref => + val cache = ref.get() + if (cache == null) + caches -= ref + else + cache.clear() + } + } + + def newMap[K, V]() = { val m = mutable.HashMap[K, V]() ; caches += new WeakReference(m) ; m } + def newSet[K]() = { val s = mutable.HashSet[K]() ; caches += new WeakReference(s) ; s } + } + /** Break into repl debugger if assertion is true. */ // def breakIf(assertion: => Boolean, args: Any*): Unit = // if (assertion) |