mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8374695: ZGC: Convert zTLABUsage to use Atomic<T>
Reviewed-by: stefank, tschatzl
This commit is contained in:
parent
e0445c09f7
commit
b1aea55205
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,24 +23,23 @@
|
|||||||
|
|
||||||
#include "gc/z/zTLABUsage.hpp"
|
#include "gc/z/zTLABUsage.hpp"
|
||||||
#include "logging/log.hpp"
|
#include "logging/log.hpp"
|
||||||
#include "runtime/atomicAccess.hpp"
|
|
||||||
|
|
||||||
ZTLABUsage::ZTLABUsage()
|
ZTLABUsage::ZTLABUsage()
|
||||||
: _used(0),
|
: _used(0),
|
||||||
_used_history() {}
|
_used_history() {}
|
||||||
|
|
||||||
void ZTLABUsage::increase_used(size_t size) {
|
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) {
|
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() {
|
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
|
// Avoid updates when nothing has been allocated since the last YC
|
||||||
if (used == 0) {
|
if (used == 0) {
|
||||||
|
|||||||
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
#ifndef SHARE_GC_Z_ZTLABUSAGE_HPP
|
#ifndef SHARE_GC_Z_ZTLABUSAGE_HPP
|
||||||
#define SHARE_GC_Z_ZTLABUSAGE_HPP
|
#define SHARE_GC_Z_ZTLABUSAGE_HPP
|
||||||
|
|
||||||
|
#include "runtime/atomic.hpp"
|
||||||
#include "utilities/globalDefinitions.hpp"
|
#include "utilities/globalDefinitions.hpp"
|
||||||
#include "utilities/numberSeq.hpp"
|
#include "utilities/numberSeq.hpp"
|
||||||
|
|
||||||
@ -42,9 +43,9 @@
|
|||||||
class ZTLABUsage {
|
class ZTLABUsage {
|
||||||
private:
|
private:
|
||||||
// Accounting TLAB used until the next GC cycle
|
// Accounting TLAB used until the next GC cycle
|
||||||
volatile size_t _used;
|
Atomic<size_t> _used;
|
||||||
// Sequence of historic used values
|
// Sequence of historic used values
|
||||||
TruncatedSeq _used_history;
|
TruncatedSeq _used_history;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZTLABUsage();
|
ZTLABUsage();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user