8374695: ZGC: Convert zTLABUsage to use Atomic<T>

Reviewed-by: stefank, tschatzl
This commit is contained in:
Axel Boldt-Christmas 2026-01-27 10:26:29 +00:00
parent e0445c09f7
commit b1aea55205
2 changed files with 9 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 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
@ -23,24 +23,23 @@
#include "gc/z/zTLABUsage.hpp"
#include "logging/log.hpp"
#include "runtime/atomicAccess.hpp"
ZTLABUsage::ZTLABUsage()
: _used(0),
_used_history() {}
void ZTLABUsage::increase_used(size_t size) {
AtomicAccess::add(&_used, size, memory_order_relaxed);
_used.add_then_fetch(size, memory_order_relaxed);
}
void ZTLABUsage::decrease_used(size_t size) {
precond(size <= _used);
precond(size <= _used.load_relaxed());
AtomicAccess::sub(&_used, size, memory_order_relaxed);
_used.sub_then_fetch(size, memory_order_relaxed);
}
void ZTLABUsage::reset() {
const size_t used = AtomicAccess::xchg(&_used, (size_t) 0);
const size_t used = _used.exchange(0u);
// Avoid updates when nothing has been allocated since the last YC
if (used == 0) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 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
@ -24,6 +24,7 @@
#ifndef SHARE_GC_Z_ZTLABUSAGE_HPP
#define SHARE_GC_Z_ZTLABUSAGE_HPP
#include "runtime/atomic.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/numberSeq.hpp"
@ -42,9 +43,9 @@
class ZTLABUsage {
private:
// Accounting TLAB used until the next GC cycle
volatile size_t _used;
Atomic<size_t> _used;
// Sequence of historic used values
TruncatedSeq _used_history;
TruncatedSeq _used_history;
public:
ZTLABUsage();