8231996: ZGC: Replace ZStatisticsForceTrace with check if JFR event is enabled
authorpliden
Mon, 21 Oct 2019 09:55:58 +0200
changeset 58704 8b16701b4636
parent 58703 c203d10291e1
child 58705 f5662bdbee4a
8231996: ZGC: Replace ZStatisticsForceTrace with check if JFR event is enabled Reviewed-by: eosterlund
src/hotspot/share/gc/z/zStat.cpp
src/hotspot/share/gc/z/zStat.hpp
src/hotspot/share/gc/z/zTracer.cpp
src/hotspot/share/gc/z/zTracer.hpp
src/hotspot/share/gc/z/zTracer.inline.hpp
src/hotspot/share/gc/z/z_globals.hpp
src/jdk.jfr/share/conf/jfr/default.jfc
src/jdk.jfr/share/conf/jfr/profile.jfc
--- a/src/hotspot/share/gc/z/zStat.cpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/zStat.cpp	Mon Oct 21 09:55:58 2019 +0200
@@ -716,7 +716,7 @@
 }
 
 void ZStatSubPhase::register_end(const Ticks& start, const Ticks& end) const {
-  ZTracer::tracer()->report_thread_phase(*this, start, end);
+  ZTracer::tracer()->report_thread_phase(name(), start, end);
 
   const Tickspan duration = end - start;
   ZStatSample(_sampler, duration.value());
@@ -736,7 +736,7 @@
 }
 
 void ZStatCriticalPhase::register_end(const Ticks& start, const Ticks& end) const {
-  ZTracer::tracer()->report_thread_phase(*this, start, end);
+  ZTracer::tracer()->report_thread_phase(name(), start, end);
 
   const Tickspan duration = end - start;
   ZStatSample(_sampler, duration.value());
@@ -759,7 +759,7 @@
 //
 // Stat sample/inc
 //
-void ZStatSample(const ZStatSampler& sampler, uint64_t value, bool trace) {
+void ZStatSample(const ZStatSampler& sampler, uint64_t value) {
   ZStatSamplerData* const cpu_data = sampler.get();
   Atomic::add(1u, &cpu_data->_nsamples);
   Atomic::add(value, &cpu_data->_sum);
@@ -782,18 +782,14 @@
     max = prev_max;
   }
 
-  if (trace) {
-    ZTracer::tracer()->report_stat_sampler(sampler, value);
-  }
+  ZTracer::tracer()->report_stat_sampler(sampler, value);
 }
 
-void ZStatInc(const ZStatCounter& counter, uint64_t increment, bool trace) {
+void ZStatInc(const ZStatCounter& counter, uint64_t increment) {
   ZStatCounterData* const cpu_data = counter.get();
   const uint64_t value = Atomic::add(increment, &cpu_data->_counter);
 
-  if (trace) {
-    ZTracer::tracer()->report_stat_counter(counter, increment, value);
-  }
+  ZTracer::tracer()->report_stat_counter(counter, increment, value);
 }
 
 void ZStatInc(const ZStatUnsampledCounter& counter, uint64_t increment) {
--- a/src/hotspot/share/gc/z/zStat.hpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/zStat.hpp	Mon Oct 21 09:55:58 2019 +0200
@@ -315,8 +315,8 @@
 //
 // Stat sample/increment
 //
-void ZStatSample(const ZStatSampler& sampler, uint64_t value, bool trace = ZStatisticsForceTrace);
-void ZStatInc(const ZStatCounter& counter, uint64_t increment = 1, bool trace = ZStatisticsForceTrace);
+void ZStatSample(const ZStatSampler& sampler, uint64_t value);
+void ZStatInc(const ZStatCounter& counter, uint64_t increment = 1);
 void ZStatInc(const ZStatUnsampledCounter& counter, uint64_t increment = 1);
 
 //
--- a/src/hotspot/share/gc/z/zTracer.cpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/zTracer.cpp	Mon Oct 21 09:55:58 2019 +0200
@@ -22,18 +22,19 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/shared/gcId.hpp"
 #include "gc/z/zStat.hpp"
 #include "gc/z/zTracer.hpp"
-#include "gc/shared/gcId.hpp"
-#include "gc/shared/gcLocker.hpp"
 #include "jfr/jfrEvents.hpp"
-#include "runtime/safepoint.hpp"
 #include "runtime/safepointVerifiers.hpp"
+#include "utilities/debug.hpp"
+#include "utilities/macros.hpp"
 #if INCLUDE_JFR
 #include "jfr/metadata/jfrSerializer.hpp"
 #endif
 
 #if INCLUDE_JFR
+
 class ZStatisticsCounterTypeConstant : public JfrSerializer {
 public:
   virtual void serialize(JfrCheckpointWriter& writer) {
@@ -66,7 +67,8 @@
                                      true /* permit_cache */,
                                      new ZStatisticsSamplerTypeConstant());
 }
-#endif
+
+#endif // INCLUDE_JFR
 
 ZTracer* ZTracer::_tracer = NULL;
 
@@ -79,24 +81,24 @@
   JFR_ONLY(register_jfr_type_serializers());
 }
 
-void ZTracer::send_stat_counter(uint32_t counter_id, uint64_t increment, uint64_t value) {
+void ZTracer::send_stat_counter(const ZStatCounter& counter, uint64_t increment, uint64_t value) {
   NoSafepointVerifier nsv;
 
   EventZStatisticsCounter e;
   if (e.should_commit()) {
-    e.set_id(counter_id);
+    e.set_id(counter.id());
     e.set_increment(increment);
     e.set_value(value);
     e.commit();
   }
 }
 
-void ZTracer::send_stat_sampler(uint32_t sampler_id, uint64_t value) {
+void ZTracer::send_stat_sampler(const ZStatSampler& sampler, uint64_t value) {
   NoSafepointVerifier nsv;
 
   EventZStatisticsSampler e;
   if (e.should_commit()) {
-    e.set_id(sampler_id);
+    e.set_id(sampler.id());
     e.set_value(value);
     e.commit();
   }
@@ -115,7 +117,7 @@
   }
 }
 
-void ZTracer::send_page_alloc(size_t size, size_t used, size_t free, size_t cache, bool nonblocking, bool noreserve) {
+void ZTracer::send_page_alloc(size_t size, size_t used, size_t free, size_t cache, ZAllocationFlags flags) {
   NoSafepointVerifier nsv;
 
   EventZPageAllocation e;
@@ -124,28 +126,8 @@
     e.set_usedAfter(used);
     e.set_freeAfter(free);
     e.set_inCacheAfter(cache);
-    e.set_nonBlocking(nonblocking);
-    e.set_noReserve(noreserve);
+    e.set_nonBlocking(flags.non_blocking());
+    e.set_noReserve(flags.no_reserve());
     e.commit();
   }
 }
-
-void ZTracer::report_stat_counter(const ZStatCounter& counter, uint64_t increment, uint64_t value) {
-  send_stat_counter(counter.id(), increment, value);
-}
-
-void ZTracer::report_stat_sampler(const ZStatSampler& sampler, uint64_t value) {
-  send_stat_sampler(sampler.id(), value);
-}
-
-void ZTracer::report_thread_phase(const ZStatPhase& phase, const Ticks& start, const Ticks& end) {
-  send_thread_phase(phase.name(), start, end);
-}
-
-void ZTracer::report_thread_phase(const char* name, const Ticks& start, const Ticks& end) {
-  send_thread_phase(name, start, end);
-}
-
-void ZTracer::report_page_alloc(size_t size, size_t used, size_t free, size_t cache, ZAllocationFlags flags) {
-  send_page_alloc(size, used, free, cache, flags.non_blocking(), flags.no_reserve());
-}
--- a/src/hotspot/share/gc/z/zTracer.hpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/zTracer.hpp	Mon Oct 21 09:55:58 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,10 +37,10 @@
 
   ZTracer();
 
-  void send_stat_counter(uint32_t counter_id, uint64_t increment, uint64_t value);
-  void send_stat_sampler(uint32_t sampler_id, uint64_t value);
+  void send_stat_counter(const ZStatCounter& counter, uint64_t increment, uint64_t value);
+  void send_stat_sampler(const ZStatSampler& sampler, uint64_t value);
   void send_thread_phase(const char* name, const Ticks& start, const Ticks& end);
-  void send_page_alloc(size_t size, size_t used, size_t free, size_t cache, bool nonblocking, bool noreserve);
+  void send_page_alloc(size_t size, size_t used, size_t free, size_t cache, ZAllocationFlags flags);
 
 public:
   static ZTracer* tracer();
@@ -48,7 +48,6 @@
 
   void report_stat_counter(const ZStatCounter& counter, uint64_t increment, uint64_t value);
   void report_stat_sampler(const ZStatSampler& sampler, uint64_t value);
-  void report_thread_phase(const ZStatPhase& phase, const Ticks& start, const Ticks& end);
   void report_thread_phase(const char* name, const Ticks& start, const Ticks& end);
   void report_page_alloc(size_t size, size_t used, size_t free, size_t cache, ZAllocationFlags flags);
 };
--- a/src/hotspot/share/gc/z/zTracer.inline.hpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/zTracer.inline.hpp	Mon Oct 21 09:55:58 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,12 +24,38 @@
 #ifndef SHARE_GC_Z_ZTRACER_INLINE_HPP
 #define SHARE_GC_Z_ZTRACER_INLINE_HPP
 
+#include "gc/z/zStat.hpp"
 #include "gc/z/zTracer.hpp"
+#include "jfr/jfrEvents.hpp"
 
 inline ZTracer* ZTracer::tracer() {
   return _tracer;
 }
 
+inline void ZTracer::report_stat_counter(const ZStatCounter& counter, uint64_t increment, uint64_t value) {
+  if (EventZStatisticsCounter::is_enabled()) {
+    send_stat_counter(counter, increment, value);
+  }
+}
+
+inline void ZTracer::report_stat_sampler(const ZStatSampler& sampler, uint64_t value) {
+  if (EventZStatisticsSampler::is_enabled()) {
+    send_stat_sampler(sampler, value);
+  }
+}
+
+inline void ZTracer::report_thread_phase(const char* name, const Ticks& start, const Ticks& end) {
+  if (EventZThreadPhase::is_enabled()) {
+    send_thread_phase(name, start, end);
+  }
+}
+
+inline void ZTracer::report_page_alloc(size_t size, size_t used, size_t free, size_t cache, ZAllocationFlags flags) {
+  if (EventZPageAllocation::is_enabled()) {
+    send_page_alloc(size, used, free, cache, flags);
+  }
+}
+
 inline ZTraceThreadPhase::ZTraceThreadPhase(const char* name) :
     _start(Ticks::now()),
     _name(name) {}
--- a/src/hotspot/share/gc/z/z_globals.hpp	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/hotspot/share/gc/z/z_globals.hpp	Mon Oct 21 09:55:58 2019 +0200
@@ -67,9 +67,6 @@
           "Time between statistics print outs (in seconds)")                \
           range(1, (uint)-1)                                                \
                                                                             \
-  diagnostic(bool, ZStatisticsForceTrace, false,                            \
-          "Force tracing of ZStats")                                        \
-                                                                            \
   diagnostic(bool, ZProactive, true,                                        \
           "Enable proactive GC cycles")                                     \
                                                                             \
--- a/src/jdk.jfr/share/conf/jfr/default.jfc	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/jdk.jfr/share/conf/jfr/default.jfc	Mon Oct 21 09:55:58 2019 +0200
@@ -689,13 +689,13 @@
     </event>
 
     <event name="jdk.ZStatisticsCounter">
-      <setting name="enabled">true</setting>
-      <setting name="threshold">10 ms</setting>
+      <setting name="enabled">false</setting>
+      <setting name="threshold">0 ms</setting>
     </event>
 
     <event name="jdk.ZStatisticsSampler">
-      <setting name="enabled">true</setting>
-      <setting name="threshold">10 ms</setting>
+      <setting name="enabled">false</setting>
+      <setting name="threshold">0 ms</setting>
     </event>
 
 
--- a/src/jdk.jfr/share/conf/jfr/profile.jfc	Mon Oct 21 09:55:48 2019 +0200
+++ b/src/jdk.jfr/share/conf/jfr/profile.jfc	Mon Oct 21 09:55:58 2019 +0200
@@ -689,13 +689,13 @@
     </event>
 
     <event name="jdk.ZStatisticsCounter">
-      <setting name="threshold">10 ms</setting>
-      <setting name="enabled">true</setting>
+      <setting name="threshold">0 ms</setting>
+      <setting name="enabled">false</setting>
     </event>
 
     <event name="jdk.ZStatisticsSampler">
-      <setting name="enabled">true</setting>
-      <setting name="threshold">10 ms</setting>
+      <setting name="enabled">false</setting>
+      <setting name="threshold">0 ms</setting>
     </event>