diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-09-03 18:12:31 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-09-03 18:12:31 -0700 |
commit | 989c3f85d95a22c95bc7ce936c4bd57ff0608bcd (patch) | |
tree | 29056a44bc8b637f31cb5e3f4617e86c57138850 | |
parent | 3ada7038877928711176da6ebde68528ab5fc39c (diff) | |
download | scala-989c3f85d95a22c95bc7ce936c4bd57ff0608bcd.tar.gz scala-989c3f85d95a22c95bc7ce936c4bd57ff0608bcd.tar.bz2 scala-989c3f85d95a22c95bc7ce936c4bd57ff0608bcd.zip |
SI-7149 Use a WeakHashSet for type uniqueness
Currently type uniqueness is done via a HashSet[Type], but
that means the Types live through an entire compile session, even
ones that are used once. The result is a huge amount of unnecessarily
retained memory. This commit uses a WeakHashSet instead so that Types
and their WeakReferences are cleaned up when no longer in use.
-rw-r--r-- | bincompat-backward.whitelist.conf | 24 | ||||
-rw-r--r-- | bincompat-forward.whitelist.conf | 24 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 4 |
3 files changed, 50 insertions, 2 deletions
diff --git a/bincompat-backward.whitelist.conf b/bincompat-backward.whitelist.conf index c016b52241..38d26c7fb7 100644 --- a/bincompat-backward.whitelist.conf +++ b/bincompat-backward.whitelist.conf @@ -279,6 +279,30 @@ filter { { matchName="scala.reflect.internal.util.WeakReferenceWithEquals" problemName=MissingClassProblem + }, + { + matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques" + problemName=IncompatibleResultTypeProblem + }, + { + matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques_=" + problemName=IncompatibleMethTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques" + problemName=IncompatibleResultTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_=" + problemName=IncompatibleMethTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques" + problemName=MissingMethodProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_=" + problemName=MissingMethodProblem } ] } diff --git a/bincompat-forward.whitelist.conf b/bincompat-forward.whitelist.conf index d1a19534db..a64eb0ba5d 100644 --- a/bincompat-forward.whitelist.conf +++ b/bincompat-forward.whitelist.conf @@ -1383,6 +1383,30 @@ filter { { matchName="scala.reflect.internal.util.WeakHashSet.reduceOption" problemName=MissingMethodProblem + }, + { + matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques" + problemName=IncompatibleResultTypeProblem + }, + { + matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques_=" + problemName=IncompatibleMethTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques" + problemName=IncompatibleResultTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_=" + problemName=IncompatibleMethTypeProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques" + problemName=MissingMethodProblem + }, + { + matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_=" + problemName=MissingMethodProblem } ] } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index cd9f3d23c9..cfa6f927b5 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -3935,13 +3935,13 @@ trait Types extends api.Types { self: SymbolTable => // Hash consing -------------------------------------------------------------- private val initialUniquesCapacity = 4096 - private var uniques: util.HashSet[Type] = _ + private var uniques: util.WeakHashSet[Type] = _ private var uniqueRunId = NoRunId protected def unique[T <: Type](tp: T): T = { if (Statistics.canEnable) Statistics.incCounter(rawTypeCount) if (uniqueRunId != currentRunId) { - uniques = util.HashSet[Type]("uniques", initialUniquesCapacity) + uniques = util.WeakHashSet[Type](initialUniquesCapacity) perRunCaches.recordCache(uniques) uniqueRunId = currentRunId } |