Hi all,

  please review this change to convert the `PLABStats` class to use `Atomic<T>`.

Testing: gha

Thanks,
  Thomas
This commit is contained in:
Thomas Schatzl 2026-01-26 14:55:00 +01:00
parent 37cb22826a
commit 6d49983e35
3 changed files with 25 additions and 25 deletions

View File

@ -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

View File

@ -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<mtGC> {
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<size_t> _allocated; // Total allocated
Atomic<size_t> _wasted; // of which wasted (internal fragmentation)
Atomic<size_t> _undo_wasted; // of which wasted on undo (is not used for calculation of PLAB size)
Atomic<size_t> _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();

View File

@ -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