Skip to content

Commit 4007910

Browse files
committed
Fix deadlock in t5375 and similar tests.
See t5375.scala for details.
1 parent f85663a commit 4007910

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
369369
// though the second condition seems weird, it's not true for symbols which are defined in some
370370
// weird combinations of super calls.
371371
(encClass, EmptyFlags)
372-
} else
373-
(topClass, JavaStatic)
372+
} else if (encClass.is(ModuleClass, butNot = Package) && encClass.isStatic) // needed to not cause deadlocks in classloader. see t5375.scala
373+
(encClass, EmptyFlags)
374+
else (topClass, JavaStatic)
374375
}
375376
else (lOwner, EmptyFlags)
376377
local.copySymDenotation(

tests/run/t5375.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/** Hello fellow compiler developer.
2+
if you are wondering why does test suite hang on this test
3+
then it's likely that the lambda inside map has been compiled into static method
4+
unfotrunatelly, as it is executed inside static object initializer,
5+
it is executed inside class-loader, in a synchronized block that is not source defined.
6+
7+
If the lambda will be static Test$#foo, calling it through a different thread would require grabbing the
8+
lock inside classloader. Unlike if it not static and is called through This(Test).foo, no lock is grabbed.
9+
10+
@DarkDimius
11+
*/
112
object Test extends dotty.runtime.LegacyApp {
213
val foos = (1 to 1000).toSeq
314
try

0 commit comments

Comments
 (0)