src/hotspot/share/gc/z/zStat.hpp
changeset 54331 f0fec71d2fff
parent 50875 2217b2fc29ea
child 55285 9a120214e732
child 58678 9cf78a70fa4f
--- a/src/hotspot/share/gc/z/zStat.hpp	Thu Mar 28 19:43:59 2019 +0100
+++ b/src/hotspot/share/gc/z/zStat.hpp	Thu Mar 28 19:43:59 2019 +0100
@@ -269,21 +269,45 @@
 //
 // Stat timer
 //
+class ZStatTimerDisable : public StackObj {
+private:
+  static __thread uint32_t _active;
+
+public:
+  ZStatTimerDisable() {
+    _active++;
+  }
+
+  ~ZStatTimerDisable() {
+    _active--;
+  }
+
+  static bool is_active() {
+    return _active > 0;
+  }
+};
+
 class ZStatTimer : public StackObj {
 private:
+  const bool        _enabled;
   const ZStatPhase& _phase;
   const Ticks       _start;
 
 public:
   ZStatTimer(const ZStatPhase& phase) :
+      _enabled(!ZStatTimerDisable::is_active()),
       _phase(phase),
       _start(Ticks::now()) {
-    _phase.register_start(_start);
+    if (_enabled) {
+      _phase.register_start(_start);
+    }
   }
 
   ~ZStatTimer() {
-    const Ticks end = Ticks::now();
-    _phase.register_end(_start, end);
+    if (_enabled) {
+      const Ticks end = Ticks::now();
+      _phase.register_end(_start, end);
+    }
   }
 };