Skip to content

-Ystatistics implementation is not threadsafe #10460

@jvican

Description

@jvican

Turning _enabled into a compile-time constant with:

diff --git a/src/reflect/scala/reflect/internal/util/Statistics.scala b/src/reflect/scala/reflect/internal/util/Statistics.scala
index 81500e0792..9f96135fc5 100644
--- a/src/reflect/scala/reflect/internal/util/Statistics.scala
+++ b/src/reflect/scala/reflect/internal/util/Statistics.scala
@@ -254,7 +254,7 @@ quant)
     }
   }
 
-  private final val _enabled = false
+  private final val _enabled = true
   private val qs = new mutable.HashMap[String, Quantity]

creates the following error: https://scala-ci.typesafe.com/view/scala-bench/job/bootstrap-benchmark/258/console.

From looking at the code, it looks like this line is the responsible:

      val startByType = if (Statistics.canEnable) Statistics.pushTimer(byTypeStack, byTypeNanos(tree.getClass)) else null

where byTypeNanos at some point returns null for tree.getClass, causing pushTimer not to push the timer and popTimer in finally if (Statistics.canEnable) Statistics.popTimer(byTypeStack, startByType) to fail because the invariant that a timer must be pushed before we pop it is violated.

This is as far as I have got since I cannot investigate deeper.

This happened when playing around with the statistics.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions