summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala
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 /test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala
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 'test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala')
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala
index 5430e33d6c..2c71e9d533 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOpts.scala
@@ -13,10 +13,18 @@ import scala.tools.testing.AssertUtil._
import CodeGenTools._
import scala.tools.partest.ASMConverters
import ASMConverters._
+import scala.tools.testing.ClearAfterClass
+
+object MethodLevelOpts extends ClearAfterClass.Clearable {
+ var methodOptCompiler = newCompiler(extraArgs = "-target:jvm-1.6 -Ybackend:GenBCode -Yopt:l:method")
+ def clear(): Unit = { methodOptCompiler = null }
+}
@RunWith(classOf[JUnit4])
-class MethodLevelOpts {
- val methodOptCompiler = newCompiler(extraArgs = "-target:jvm-1.6 -Ybackend:GenBCode -Yopt:l:method")
+class MethodLevelOpts extends ClearAfterClass {
+ ClearAfterClass.stateToClear = MethodLevelOpts
+
+ val methodOptCompiler = MethodLevelOpts.methodOptCompiler
def wrapInDefault(code: Instruction*) = List(Label(0), LineNumber(1, Label(0))) ::: code.toList ::: List(Label(1))