diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-10-01 23:36:18 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-10-01 23:37:06 +0200 |
commit | 2f9e766ec269e4e4dd8ddb0f92d915366110af6d (patch) | |
tree | b354ef76c241df2b19f6d126073121c7091d8e41 /src/reflect | |
parent | 1088af1236b64b89118e566ce3856b8101b391a9 (diff) | |
download | scala-2f9e766ec269e4e4dd8ddb0f92d915366110af6d.tar.gz scala-2f9e766ec269e4e4dd8ddb0f92d915366110af6d.tar.bz2 scala-2f9e766ec269e4e4dd8ddb0f92d915366110af6d.zip |
fixes a bug in a weak cache in runtime reflection
Entries in SynchronizedTypes.uniques could previously be garbage collected
in-between a successful call to contains and an actual cache lookup.
The patch could be a one-liner, but I don't want to use HOFs
in this function, whose prototype is a hotspot in the compiler.
Also the fix doesn't touch scalac in any way. It only applies to
reflective universes that provide runtime reflection functionality.
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/runtime/SynchronizedTypes.scala | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala index b9b140a2fd..9b4d8d1d48 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala @@ -24,7 +24,8 @@ trait SynchronizedTypes extends internal.Types { self: SymbolTable => // i.e. they have their caches cleaned up automatically on per-run basis, // therefore they should use vanilla uniques, which are faster if (!isCompilerUniverse) { - val result = if (uniques contains tp) uniques(tp).get else null + val inCache = uniques get tp + val result = if (inCache.isDefined) inCache.get.get else null if (result ne null) result.asInstanceOf[T] else { uniques(tp) = new WeakReference(tp) |