diff --git a/src/hotspot/share/gc/z/zHeap.cpp b/src/hotspot/share/gc/z/zHeap.cpp index e99e32db8a5..96679d0723b 100644 --- a/src/hotspot/share/gc/z/zHeap.cpp +++ b/src/hotspot/share/gc/z/zHeap.cpp @@ -132,11 +132,11 @@ size_t ZHeap::unused() const { } size_t ZHeap::tlab_capacity() const { - return _tlab_usage.capacity(); + return _tlab_usage.tlab_capacity(); } size_t ZHeap::tlab_used() const { - return _tlab_usage.used(); + return _tlab_usage.tlab_used(); } size_t ZHeap::max_tlab_size() const { diff --git a/src/hotspot/share/gc/z/zTLABUsage.cpp b/src/hotspot/share/gc/z/zTLABUsage.cpp index 30f2851fb13..cd8141e47ff 100644 --- a/src/hotspot/share/gc/z/zTLABUsage.cpp +++ b/src/hotspot/share/gc/z/zTLABUsage.cpp @@ -29,42 +29,42 @@ ZTLABUsage::ZTLABUsage() : _used(0), _used_history() {} - void ZTLABUsage::increase_used(size_t size) { Atomic::add(&_used, size, memory_order_relaxed); } void ZTLABUsage::decrease_used(size_t size) { precond(size <= _used); + Atomic::sub(&_used, size, memory_order_relaxed); } void ZTLABUsage::reset() { - const size_t current_used = Atomic::xchg(&_used, (size_t) 0); + const size_t used = Atomic::xchg(&_used, (size_t) 0); - // Avoid updates for the second young generation collection of a SystemGC - if (current_used == 0) { + // Avoid updates when nothing has been allocated since the last YC + if (used == 0) { return; } // Save the old values for logging - const size_t old_used = used(); - const size_t old_capacity = capacity(); + const size_t old_tlab_used = tlab_used(); + const size_t old_tlab_capacity = tlab_capacity(); // Update the usage history with the current value - _used_history.add(current_used); + _used_history.add(used); log_debug(gc, tlab)("TLAB usage update: used %zuM -> %zuM, capacity: %zuM -> %zuM", - old_used / M, - used() / M, - old_capacity / M, - capacity() / M); + old_tlab_used / M, + tlab_used() / M, + old_tlab_capacity / M, + tlab_capacity() / M); } -size_t ZTLABUsage::used() const { +size_t ZTLABUsage::tlab_used() const { return _used_history.last(); } -size_t ZTLABUsage::capacity() const { +size_t ZTLABUsage::tlab_capacity() const { return _used_history.davg(); } diff --git a/src/hotspot/share/gc/z/zTLABUsage.hpp b/src/hotspot/share/gc/z/zTLABUsage.hpp index bdfb8c4ef7d..3d1b084fe16 100644 --- a/src/hotspot/share/gc/z/zTLABUsage.hpp +++ b/src/hotspot/share/gc/z/zTLABUsage.hpp @@ -36,11 +36,14 @@ // ZGC does not have set generation sizes unlike most other GCs and because of // this there is no fixed TLAB capacity. For the common TLAB sizing heuristic // to work properly ZGC estimates the current capacity by using a weighted -// average of the last 10 used values. +// average of the last 10 used values. ZGC uses the last snapshotted value as +// the value returned as tlab_used(). class ZTLABUsage { private: + // Accounting TLAB used until the next GC cycle volatile size_t _used; + // Sequence of historic used values TruncatedSeq _used_history; public: @@ -50,8 +53,8 @@ public: void decrease_used(size_t size); void reset(); - size_t used() const; - size_t capacity() const; + size_t tlab_used() const; + size_t tlab_capacity() const; }; #endif // SHARE_GC_Z_ZTLABUSAGE_HPP