diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-02-07 17:30:15 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-10-18 17:52:16 +0200 |
commit | e19bfeebd6ce965aac4545b3ede3c12e99f7d358 (patch) | |
tree | 9f709cdbdbe941ee0d0069f10c090ff9f6675e6e /src/reflect | |
parent | 37f4e9ce3a05a5821d2a5e20af28f34355d12dfb (diff) | |
download | scala-e19bfeebd6ce965aac4545b3ede3c12e99f7d358.tar.gz scala-e19bfeebd6ce965aac4545b3ede3c12e99f7d358.tar.bz2 scala-e19bfeebd6ce965aac4545b3ede3c12e99f7d358.zip |
replaces locks over numbers with AtomicIntegers
This is another optimization we discussed with Roland.
Diffstat (limited to 'src/reflect')
3 files changed, 10 insertions, 15 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 9b44c815d2..77f966b3af 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -32,11 +32,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Used to keep track of the recursion depth on locked symbols */ private var recursionTable = immutable.Map.empty[Symbol, Int] - private var nextexid = 0 - protected def freshExistentialName(suffix: String) = { - nextexid += 1 - newTypeName("_" + nextexid + suffix) - } + private var existentialIds = 0 + protected def nextExistentialId() = { existentialIds += 1; existentialIds } + protected def freshExistentialName(suffix: String) = newTypeName("_" + nextExistentialId() + suffix) // Set the fields which point companions at one another. Returns the module. def connectModuleToClass(m: ModuleSymbol, moduleClass: ClassSymbol): ModuleSymbol = { diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala index 5f004330c3..f9c8b09f91 100644 --- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala +++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala @@ -42,8 +42,8 @@ trait JavaUniverseForce { self: runtime.JavaUniverse => // inaccessible: this._glbResults // inaccessible: this._indent // inaccessible: this._tostringRecursions - // inaccessible: this.nextIdLock - // inaccessible: this.freshExistentialNameLock + // inaccessible: this.atomicIds + // inaccessible: this.atomicExistentialIds // inaccessible: this.mirrors this.rootMirror this.treeBuild diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 5e1bfef234..4a0f6ffaea 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -6,14 +6,11 @@ import scala.reflect.io.AbstractFile private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => - // we can keep this lock fine-grained, because nextId is just a simple increment, which makes deadlocks impossible - private lazy val nextIdLock = new Object - override protected def nextId() = nextIdLock.synchronized { super.nextId() } - - // we can keep this lock fine-grained, because freshExistentialName is just a simple increment, which makes deadlocks impossible - private lazy val freshExistentialNameLock = new Object - override protected def freshExistentialName(suffix: String) = - freshExistentialNameLock.synchronized { super.freshExistentialName(suffix) } + private lazy val atomicIds = new java.util.concurrent.atomic.AtomicInteger(0) + override protected def nextId() = atomicIds.incrementAndGet() + + private lazy val atomicExistentialIds = new java.util.concurrent.atomic.AtomicInteger(0) + override protected def nextExistentialId() = atomicExistentialIds.incrementAndGet() // Set the fields which point companions at one another. Returns the module. override def connectModuleToClass(m: ModuleSymbol, moduleClass: ClassSymbol): ModuleSymbol = |