summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-01-18 23:22:25 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2015-03-11 12:53:34 -0700
commit4ffe9345ca6e611ff5a83a3fdabeb7658a2fce50 (patch)
tree324b0ec35f2adc76e97548f90a1ba9e3351271f6 /src/reflect
parentb34a452c0683d260ffb1644575a0e970559cae87 (diff)
downloadscala-4ffe9345ca6e611ff5a83a3fdabeb7658a2fce50.tar.gz
scala-4ffe9345ca6e611ff5a83a3fdabeb7658a2fce50.tar.bz2
scala-4ffe9345ca6e611ff5a83a3fdabeb7658a2fce50.zip
Reuse the same compiler instance for all tests in a JUnit class
Note that JUnit creates a new instance of the test class for running each test method. So the compiler instance is added to the companion. However, the JVM would quickly run out of memory when running multiple tests, as the compilers cannot be GCd. So we make it a `var`, and set it to null when a class is done. For that we use JUnit's `@AfterClass` which is required to be on a static method. Therefore we add a Java class with such a static method that we can extend from Scala.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index 01e4cdf367..ef63078f90 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -355,6 +355,14 @@ abstract class SymbolTable extends macros.Universe
cache
}
+ /**
+ * Removes a cache from the per-run caches. This is useful for testing: it allows running the
+ * compiler and then inspect the state of a cache.
+ */
+ def unrecordCache[T <: Clearable](cache: T): Unit = {
+ caches = caches.filterNot(_.get eq cache)
+ }
+
def clearAll() = {
debuglog("Clearing " + caches.size + " caches.")
caches foreach (ref => Option(ref.get).foreach(_.clear))