diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-01-26 21:39:53 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-10-18 17:48:52 +0200 |
commit | 174f1465335bead724da6bf2ae823830422dd51c (patch) | |
tree | 13bf8706d9a9acdd31904e2a20a7f8b84f379e6b /test/files/run/reflection-sync-potpourri.scala | |
parent | 61cfb8c2080c8b1aba70647e9f7a837ef37e8c0d (diff) | |
download | scala-174f1465335bead724da6bf2ae823830422dd51c.tar.gz scala-174f1465335bead724da6bf2ae823830422dd51c.tar.bz2 scala-174f1465335bead724da6bf2ae823830422dd51c.zip |
runtime reflection: death from thousand threads
not anymore
Diffstat (limited to 'test/files/run/reflection-sync-potpourri.scala')
-rw-r--r-- | test/files/run/reflection-sync-potpourri.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/reflection-sync-potpourri.scala b/test/files/run/reflection-sync-potpourri.scala new file mode 100644 index 0000000000..06dcea9209 --- /dev/null +++ b/test/files/run/reflection-sync-potpourri.scala @@ -0,0 +1,31 @@ +import scala.reflect.runtime.universe._ + +// this test checks that under heavily multithreaded conditions: +// 1) scala.reflect.runtime.universe, its rootMirror and definitions are initialized correctly +// 2) symbols are correctly materialized into PackageScopes (no dupes) +// 3) unpickling works okay even we unpickle the same symbol a lot of times + +object Test extends App { + def foo[T: TypeTag](x: T) = typeOf[T].toString + val n = 1000 + val rng = new scala.util.Random() + val types = List( + () => typeOf[java.lang.reflect.Method], + () => typeOf[java.lang.annotation.Annotation], + () => typeOf[scala.io.BufferedSource], + () => typeOf[scala.io.Codec]) + val perms = types.permutations.toList + def force(lazytpe: () => Type): String = { + lazytpe().typeSymbol.typeSignature + lazytpe().toString + } + 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 s1 = foo("42") + val s2 = perms(diceRolls(i - 1)).map(x => force(x)).sorted.mkString(", ") + println(s"s1 = $s1, s2 = $s2") + } + }) + threads foreach (_.start) +}
\ No newline at end of file |