From 3b3bcd7b684fc432e48c20aa5317b56e87521c3b Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 14 Nov 2013 20:03:20 +0100 Subject: Revert "temporarily disables run/reflection-sync-subtypes" This reverts commit 04e2dbb29830d0e511cdfa8c132a9fad91d657ed, by avoiding the ill-fated attempt to short-circuit the global reflection lock. I think we can do better performance wise, but lets at least get something correct to start with. --- .../scala/reflect/runtime/SynchronizedSymbols.scala | 11 +++++++++-- test/disabled/run/reflection-sync-subtypes.scala | 20 -------------------- test/files/run/reflection-sync-subtypes.check | 0 test/files/run/reflection-sync-subtypes.scala | 20 ++++++++++++++++++++ 4 files changed, 29 insertions(+), 22 deletions(-) delete mode 100644 test/disabled/run/reflection-sync-subtypes.scala create mode 100644 test/files/run/reflection-sync-subtypes.check create mode 100644 test/files/run/reflection-sync-subtypes.scala diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 298d0ffebd..1a232c8de1 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -32,8 +32,15 @@ private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: Symb trait SynchronizedSymbol extends Symbol { def gilSynchronizedIfNotInited[T](body: => T): T = { - if (isFullyInitialized) body - else gilSynchronized { body } + // TODO JZ desired, but prone to race conditions. We need the runtime reflection based + // type completers to establish a memory barrier upon initialization. Maybe a volatile + // write? We need to consult with the experts here. Until them, lock pessimistically. + // + // `run/reflection-sync-subtypes.scala` fails about 1/50 times otherwise. + // + // if (isFullyInitialized) body + // else gilSynchronized { body } + gilSynchronized { body } } override def validTo = gilSynchronizedIfNotInited { super.validTo } diff --git a/test/disabled/run/reflection-sync-subtypes.scala b/test/disabled/run/reflection-sync-subtypes.scala deleted file mode 100644 index 7f75a464ac..0000000000 --- a/test/disabled/run/reflection-sync-subtypes.scala +++ /dev/null @@ -1,20 +0,0 @@ -import scala.reflect.runtime.universe._ - -object Test extends App { - val n = 1000 - val rng = new scala.util.Random() - val tasks = List( - () => typeOf[List[Int]] <:< typeOf[List[T] forSome { type T }], - () => typeOf[List[T] forSome { type T }] <:< typeOf[List[Any]], - () => typeOf[Map[Int, Object]] <:< typeOf[Iterable[(Int, String)]], - () => typeOf[Expr[Any] { val mirror: rootMirror.type }] <:< typeOf[Expr[List[List[List[Int]]]]{ val mirror: rootMirror.type }]) - val perms = tasks.permutations.toList - val diceRolls = List.fill(n)(rng.nextInt(perms.length)) - val threads = (1 to n) map (i => new Thread(s"Reflector-$i") { - override def run(): Unit = { - val result = perms(diceRolls(i - 1)).map(_()) - assert(result.sorted == List(false, false, true, true)) - } - }) - threads foreach (_.start) -} \ No newline at end of file diff --git a/test/files/run/reflection-sync-subtypes.check b/test/files/run/reflection-sync-subtypes.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/run/reflection-sync-subtypes.scala b/test/files/run/reflection-sync-subtypes.scala new file mode 100644 index 0000000000..7f75a464ac --- /dev/null +++ b/test/files/run/reflection-sync-subtypes.scala @@ -0,0 +1,20 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + val n = 1000 + val rng = new scala.util.Random() + val tasks = List( + () => typeOf[List[Int]] <:< typeOf[List[T] forSome { type T }], + () => typeOf[List[T] forSome { type T }] <:< typeOf[List[Any]], + () => typeOf[Map[Int, Object]] <:< typeOf[Iterable[(Int, String)]], + () => typeOf[Expr[Any] { val mirror: rootMirror.type }] <:< typeOf[Expr[List[List[List[Int]]]]{ val mirror: rootMirror.type }]) + val perms = tasks.permutations.toList + val diceRolls = List.fill(n)(rng.nextInt(perms.length)) + val threads = (1 to n) map (i => new Thread(s"Reflector-$i") { + override def run(): Unit = { + val result = perms(diceRolls(i - 1)).map(_()) + assert(result.sorted == List(false, false, true, true)) + } + }) + threads foreach (_.start) +} \ No newline at end of file -- cgit v1.2.3