8221153: ZGC: Heap iteration and verification pollutes GC statistics
Reviewed-by: stefank, eosterlund
--- a/src/hotspot/share/gc/z/zHeap.cpp Thu Mar 28 19:43:59 2019 +0100
+++ b/src/hotspot/share/gc/z/zHeap.cpp Thu Mar 28 19:43:59 2019 +0100
@@ -540,16 +540,19 @@
class ZVerifyRootsTask : public ZTask {
private:
+ ZStatTimerDisable _disable;
ZRootsIterator _strong_roots;
ZWeakRootsIterator _weak_roots;
public:
ZVerifyRootsTask() :
ZTask("ZVerifyRootsTask"),
+ _disable(),
_strong_roots(),
_weak_roots() {}
virtual void work() {
+ ZStatTimerDisable disable;
ZVerifyOopClosure cl;
_strong_roots.oops_do(&cl);
_weak_roots.oops_do(&cl);
--- a/src/hotspot/share/gc/z/zHeapIterator.cpp Thu Mar 28 19:43:59 2019 +0100
+++ b/src/hotspot/share/gc/z/zHeapIterator.cpp Thu Mar 28 19:43:59 2019 +0100
@@ -28,6 +28,7 @@
#include "gc/z/zHeapIterator.hpp"
#include "gc/z/zOop.inline.hpp"
#include "gc/z/zRootsIterator.hpp"
+#include "gc/z/zStat.hpp"
#include "memory/iterator.inline.hpp"
#include "utilities/bitMap.inline.hpp"
#include "utilities/stack.inline.hpp"
@@ -170,6 +171,7 @@
// If we didn't do this the application would have expected to see
// ObjectFree events for phantom reachable objects in the tag map.
+ ZStatTimerDisable disable;
ZHeapIteratorRootOopClosure root_cl(this);
// Push strong roots onto stack
--- a/src/hotspot/share/gc/z/zStat.cpp Thu Mar 28 19:43:59 2019 +0100
+++ b/src/hotspot/share/gc/z/zStat.cpp Thu Mar 28 19:43:59 2019 +0100
@@ -749,6 +749,11 @@
}
//
+// Stat timer
+//
+__thread uint32_t ZStatTimerDisable::_active = 0;
+
+//
// Stat sample/inc
//
void ZStatSample(const ZStatSampler& sampler, uint64_t value, bool trace) {
--- 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);
+ }
}
};