From 6d49983e3541d42c22710a970597ee5acfdeeab2 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 26 Jan 2026 14:55:00 +0100 Subject: [PATCH] 8376328 Hi all, please review this change to convert the `PLABStats` class to use `Atomic`. Testing: gha Thanks, Thomas --- src/hotspot/share/gc/g1/g1EvacStats.cpp | 12 ++++----- src/hotspot/share/gc/shared/plab.hpp | 27 +++++++++++---------- src/hotspot/share/gc/shared/plab.inline.hpp | 11 ++++----- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1EvacStats.cpp b/src/hotspot/share/gc/g1/g1EvacStats.cpp index 1d54b184e64..d93f63383c4 100644 --- a/src/hotspot/share/gc/g1/g1EvacStats.cpp +++ b/src/hotspot/share/gc/g1/g1EvacStats.cpp @@ -48,11 +48,11 @@ void G1EvacStats::log_plab_allocation() { "used: %zuB, " "undo waste: %zuB, ", _description, - _allocated * HeapWordSize, - _wasted * HeapWordSize, - _unused * HeapWordSize, + allocated() * HeapWordSize, + wasted() * HeapWordSize, + unused() * HeapWordSize, used() * HeapWordSize, - _undo_wasted * HeapWordSize); + undo_wasted() * HeapWordSize); log_debug(gc, plab)("%s other allocation: " "region end waste: %zuB, " "regions filled: %u, " @@ -157,13 +157,13 @@ void G1EvacStats::adjust_desired_plab_size() { assert(is_object_aligned(max_size()) && min_size() <= max_size(), "PLAB clipping computation may be incorrect"); - assert(_allocated != 0 || _unused == 0, + assert(allocated() != 0 || unused() == 0, "Inconsistency in PLAB stats: " "_allocated: %zu, " "_wasted: %zu, " "_unused: %zu, " "_undo_wasted: %zu", - _allocated, _wasted, _unused, _undo_wasted); + allocated(), wasted(), unused(), undo_wasted()); size_t plab_size = compute_desired_plab_size(); // Take historical weighted average diff --git a/src/hotspot/share/gc/shared/plab.hpp b/src/hotspot/share/gc/shared/plab.hpp index 2eebdeeadb4..5200f022633 100644 --- a/src/hotspot/share/gc/shared/plab.hpp +++ b/src/hotspot/share/gc/shared/plab.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2026, 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 @@ -27,6 +27,7 @@ #include "gc/shared/collectedHeap.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" // Forward declarations. @@ -149,16 +150,16 @@ class PLABStats : public CHeapObj { protected: const char* _description; // Identifying string. - size_t _allocated; // Total allocated - size_t _wasted; // of which wasted (internal fragmentation) - size_t _undo_wasted; // of which wasted on undo (is not used for calculation of PLAB size) - size_t _unused; // Unused in last buffer + Atomic _allocated; // Total allocated + Atomic _wasted; // of which wasted (internal fragmentation) + Atomic _undo_wasted; // of which wasted on undo (is not used for calculation of PLAB size) + Atomic _unused; // Unused in last buffer virtual void reset() { - _allocated = 0; - _wasted = 0; - _undo_wasted = 0; - _unused = 0; + _allocated.store_relaxed(0); + _wasted.store_relaxed(0); + _undo_wasted.store_relaxed(0); + _unused.store_relaxed(0); } public: @@ -172,11 +173,11 @@ public: virtual ~PLABStats() { } - size_t allocated() const { return _allocated; } - size_t wasted() const { return _wasted; } - size_t unused() const { return _unused; } + size_t allocated() const { return _allocated.load_relaxed(); } + size_t wasted() const { return _wasted.load_relaxed(); } + size_t undo_wasted() const { return _undo_wasted.load_relaxed(); } + size_t unused() const { return _unused.load_relaxed(); } size_t used() const { return allocated() - (wasted() + unused()); } - size_t undo_wasted() const { return _undo_wasted; } static size_t min_size() { return PLAB::min_size(); diff --git a/src/hotspot/share/gc/shared/plab.inline.hpp b/src/hotspot/share/gc/shared/plab.inline.hpp index 020738352d3..5f3e9c91e26 100644 --- a/src/hotspot/share/gc/shared/plab.inline.hpp +++ b/src/hotspot/share/gc/shared/plab.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -29,22 +29,21 @@ #include "gc/shared/collectedHeap.inline.hpp" #include "memory/allocation.inline.hpp" -#include "runtime/atomicAccess.hpp" void PLABStats::add_allocated(size_t v) { - AtomicAccess::add(&_allocated, v); + _allocated.add_then_fetch(v); } void PLABStats::add_unused(size_t v) { - AtomicAccess::add(&_unused, v); + _unused.add_then_fetch(v); } void PLABStats::add_wasted(size_t v) { - AtomicAccess::add(&_wasted, v); + _wasted.add_then_fetch(v); } void PLABStats::add_undo_wasted(size_t v) { - AtomicAccess::add(&_undo_wasted, v); + _undo_wasted.add_then_fetch(v); } #endif // SHARE_GC_SHARED_PLAB_INLINE_HPP