diff options
author | Martin Odersky <odersky@gmail.com> | 2014-02-24 15:37:14 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-02-24 18:56:48 +0100 |
commit | ed7755b781bd1b444d38329cb22eacaa3fc1c005 (patch) | |
tree | 2eb43f71741310e77248111f5fa5c39203e33c8d /src/dotty/tools/dotc/core/pickling | |
parent | cdeafeafd252b20a0df5440e0420211af95e0cdc (diff) | |
download | dotty-ed7755b781bd1b444d38329cb22eacaa3fc1c005.tar.gz dotty-ed7755b781bd1b444d38329cb22eacaa3fc1c005.tar.bz2 dotty-ed7755b781bd1b444d38329cb22eacaa3fc1c005.zip |
Avoid memory leaks on repeated compilation.
Several measures:
1. Invalidate classOfId and superIdOfClass in ContextBase after each run. These contain local classes
that should become inaccessible.
2. Also clear implicitScope cache that maps types to their implicit scopes after each run. (not sure whether
this is needed; it did show up in paths from root, but on second thought this might have been a gc-able
cycle.
3. Avoid capturing contexts in lazy annotations.
4. Avoid capturing contexts in functions that compute souceModule and moduleClass
5. Avoid capturing contexts in Unpickler's postReadOp hook.
Diffstat (limited to 'src/dotty/tools/dotc/core/pickling')
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 1395b4f43..012fc7af3 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -32,7 +32,7 @@ class ClassfileParser( protected var classTParams = Map[Name,Symbol]() classRoot.info = (new NoCompleter).withDecls(instanceScope) - moduleRoot.info = (new NoCompleter).withDecls(staticScope).withSourceModule(staticModule) + moduleRoot.info = (new NoCompleter).withDecls(staticScope).withSourceModule(_ => staticModule) private def currentIsTopLevel(implicit ctx: Context) = classRoot.owner is Flags.PackageClass diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 78a91b2ef..544a2ebdb 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -171,7 +171,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: case _ => errorBadSignature(s"a runtime exception occured: $ex", Some(ex)) } - private var postReadOp: () => Unit = null + private var postReadOp: Context => Unit = null def run()(implicit ctx: Context) = try { @@ -182,7 +182,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: readIndex = index(i) entries(i) = readSymbol() if (postReadOp != null) { - postReadOp() + postReadOp(ctx) postReadOp = null } readIndex = savedIndex @@ -457,7 +457,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: ctx.newSymbol(owner, name1, flags1, localMemberUnpickler, coord = start) case CLASSsym => val infoRef = readNat() - postReadOp = () => atReadPos(index(infoRef), readTypeParams) // force reading type params early, so they get entered in the right order. + postReadOp = implicit ctx => atReadPos(index(infoRef), readTypeParams) // force reading type params early, so they get entered in the right order. if (isClassRoot) completeRoot( classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol)) @@ -471,7 +471,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: def completer(cls: Symbol) = { val unpickler = new LocalUnpickler() withDecls symScope(cls) if (flags is ModuleClass) - unpickler withSourceModule ( + unpickler withSourceModule (implicit ctx => cls.owner.decls.lookup(cls.name.sourceModuleName) .suchThat(_ is Module).symbol) else unpickler @@ -543,7 +543,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: def rootClassUnpickler(start: Coord, cls: Symbol, module: Symbol) = (new LocalUnpickler with SymbolLoaders.SecondCompleter { override def startCoord(denot: SymDenotation): Coord = start - }) withDecls symScope(cls) withSourceModule module + }) withDecls symScope(cls) withSourceModule (_ => module) /** Convert * tp { type name = sym } forSome { sym >: L <: H } @@ -852,7 +852,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: val start = readIndex val atp = readTypeRef() Annotation.deferred( - atp.typeSymbol, atReadPos(start, () => readAnnotationContents(end))) + atp.typeSymbol, implicit ctx => atReadPos(start, () => readAnnotationContents(end))) } /* Read an abstract syntax tree */ |