8375971: G1: Convert G1EvacStats to use Atomic<T>

Reviewed-by: iwalulya, kbarrett
This commit is contained in:
Thomas Schatzl 2026-01-26 09:17:22 +00:00
parent c3360ff511
commit 0bc2dc3401
4 changed files with 74 additions and 44 deletions

View File

@ -31,6 +31,7 @@
#include "gc/g1/g1CollectorState.hpp" #include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1ConcurrentMark.inline.hpp" #include "gc/g1/g1ConcurrentMark.inline.hpp"
#include "gc/g1/g1EvacFailureRegions.hpp" #include "gc/g1/g1EvacFailureRegions.hpp"
#include "gc/g1/g1EvacStats.inline.hpp"
#include "gc/g1/g1HeapRegion.inline.hpp" #include "gc/g1/g1HeapRegion.inline.hpp"
#include "gc/g1/g1HeapRegionManager.inline.hpp" #include "gc/g1/g1HeapRegionManager.inline.hpp"
#include "gc/g1/g1HeapRegionRemSet.hpp" #include "gc/g1/g1HeapRegionRemSet.hpp"

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 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
@ -22,13 +22,24 @@
* *
*/ */
#include "gc/g1/g1EvacStats.hpp" #include "gc/g1/g1EvacStats.inline.hpp"
#include "gc/shared/gc_globals.hpp" #include "gc/shared/gc_globals.hpp"
#include "gc/shared/gcId.hpp" #include "gc/shared/gcId.hpp"
#include "logging/log.hpp" #include "logging/log.hpp"
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "runtime/globals.hpp" #include "runtime/globals.hpp"
void G1EvacStats::reset() {
PLABStats::reset();
_region_end_waste.store_relaxed(0);
_regions_filled.store_relaxed(0);
_num_plab_filled.store_relaxed(0);
_direct_allocated.store_relaxed(0);
_num_direct_allocated.store_relaxed(0);
_failure_used.store_relaxed(0);
_failure_waste.store_relaxed(0);
}
void G1EvacStats::log_plab_allocation() { void G1EvacStats::log_plab_allocation() {
log_debug(gc, plab)("%s PLAB allocation: " log_debug(gc, plab)("%s PLAB allocation: "
"allocated: %zuB, " "allocated: %zuB, "
@ -51,13 +62,13 @@ void G1EvacStats::log_plab_allocation() {
"failure used: %zuB, " "failure used: %zuB, "
"failure wasted: %zuB", "failure wasted: %zuB",
_description, _description,
_region_end_waste * HeapWordSize, region_end_waste() * HeapWordSize,
_regions_filled, regions_filled(),
_num_plab_filled, num_plab_filled(),
_direct_allocated * HeapWordSize, direct_allocated() * HeapWordSize,
_num_direct_allocated, num_direct_allocated(),
_failure_used * HeapWordSize, failure_used() * HeapWordSize,
_failure_waste * HeapWordSize); failure_waste() * HeapWordSize);
} }
void G1EvacStats::log_sizing(size_t calculated_words, size_t net_desired_words) { void G1EvacStats::log_sizing(size_t calculated_words, size_t net_desired_words) {
@ -109,7 +120,7 @@ size_t G1EvacStats::compute_desired_plab_size() const {
// threads do not allocate anything but a few rather large objects. In this // threads do not allocate anything but a few rather large objects. In this
// degenerate case the PLAB size would simply quickly tend to minimum PLAB size, // degenerate case the PLAB size would simply quickly tend to minimum PLAB size,
// which is an okay reaction. // which is an okay reaction.
size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; size_t const used_for_waste_calculation = used() > region_end_waste() ? used() - region_end_waste() : 0;
size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct; size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
return (size_t)((double)total_waste_allowed / (100 - G1LastPLABAverageOccupancy)); return (size_t)((double)total_waste_allowed / (100 - G1LastPLABAverageOccupancy));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 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
@ -27,6 +27,7 @@
#include "gc/shared/gcUtil.hpp" #include "gc/shared/gcUtil.hpp"
#include "gc/shared/plab.hpp" #include "gc/shared/plab.hpp"
#include "runtime/atomic.hpp"
// Records various memory allocation statistics gathered during evacuation. All sizes // Records various memory allocation statistics gathered during evacuation. All sizes
// are in HeapWords. // are in HeapWords.
@ -36,30 +37,21 @@ class G1EvacStats : public PLABStats {
AdaptiveWeightedAverage AdaptiveWeightedAverage
_net_plab_size_filter; // Integrator with decay _net_plab_size_filter; // Integrator with decay
size_t _region_end_waste; // Number of words wasted due to skipping to the next region. Atomic<size_t> _region_end_waste; // Number of words wasted due to skipping to the next region.
uint _regions_filled; // Number of regions filled completely. Atomic<uint> _regions_filled; // Number of regions filled completely.
size_t _num_plab_filled; // Number of PLABs filled and retired. Atomic<size_t> _num_plab_filled; // Number of PLABs filled and retired.
size_t _direct_allocated; // Number of words allocated directly into the regions. Atomic<size_t> _direct_allocated; // Number of words allocated directly into the regions.
size_t _num_direct_allocated; // Number of direct allocation attempts. Atomic<size_t> _num_direct_allocated; // Number of direct allocation attempts.
// Number of words in live objects remaining in regions that ultimately suffered an // Number of words in live objects remaining in regions that ultimately suffered an
// evacuation failure. This is used in the regions when the regions are made old regions. // evacuation failure. This is used in the regions when the regions are made old regions.
size_t _failure_used; Atomic<size_t> _failure_used;
// Number of words wasted in regions which failed evacuation. This is the sum of space // Number of words wasted in regions which failed evacuation. This is the sum of space
// for objects successfully copied out of the regions (now dead space) plus waste at the // for objects successfully copied out of the regions (now dead space) plus waste at the
// end of regions. // end of regions.
size_t _failure_waste; Atomic<size_t> _failure_waste;
virtual void reset() { virtual void reset();
PLABStats::reset();
_region_end_waste = 0;
_regions_filled = 0;
_num_plab_filled = 0;
_direct_allocated = 0;
_num_direct_allocated = 0;
_failure_used = 0;
_failure_waste = 0;
}
void log_plab_allocation(); void log_plab_allocation();
void log_sizing(size_t calculated_words, size_t net_desired_words); void log_sizing(size_t calculated_words, size_t net_desired_words);
@ -77,16 +69,16 @@ public:
// Should be called at the end of a GC pause. // Should be called at the end of a GC pause.
void adjust_desired_plab_size(); void adjust_desired_plab_size();
uint regions_filled() const { return _regions_filled; } uint regions_filled() const;
size_t num_plab_filled() const { return _num_plab_filled; } size_t num_plab_filled() const;
size_t region_end_waste() const { return _region_end_waste; } size_t region_end_waste() const;
size_t direct_allocated() const { return _direct_allocated; } size_t direct_allocated() const;
size_t num_direct_allocated() const { return _num_direct_allocated; } size_t num_direct_allocated() const;
// Amount of space in heapwords used in the failing regions when an evacuation failure happens. // Amount of space in heapwords used in the failing regions when an evacuation failure happens.
size_t failure_used() const { return _failure_used; } size_t failure_used() const;
// Amount of space in heapwords wasted (unused) in the failing regions when an evacuation failure happens. // Amount of space in heapwords wasted (unused) in the failing regions when an evacuation failure happens.
size_t failure_waste() const { return _failure_waste; } size_t failure_waste() const;
inline void add_num_plab_filled(size_t value); inline void add_num_plab_filled(size_t value);
inline void add_direct_allocated(size_t value); inline void add_direct_allocated(size_t value);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 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
@ -27,28 +27,54 @@
#include "gc/g1/g1EvacStats.hpp" #include "gc/g1/g1EvacStats.hpp"
#include "runtime/atomicAccess.hpp" inline uint G1EvacStats::regions_filled() const {
return _regions_filled.load_relaxed();
}
inline size_t G1EvacStats::num_plab_filled() const {
return _num_plab_filled.load_relaxed();
}
inline size_t G1EvacStats::region_end_waste() const {
return _region_end_waste.load_relaxed();
}
inline size_t G1EvacStats::direct_allocated() const {
return _direct_allocated.load_relaxed();
}
inline size_t G1EvacStats::num_direct_allocated() const {
return _num_direct_allocated.load_relaxed();
}
inline size_t G1EvacStats::failure_used() const {
return _failure_used.load_relaxed();
}
inline size_t G1EvacStats::failure_waste() const {
return _failure_waste.load_relaxed();
}
inline void G1EvacStats::add_direct_allocated(size_t value) { inline void G1EvacStats::add_direct_allocated(size_t value) {
AtomicAccess::add(&_direct_allocated, value, memory_order_relaxed); _direct_allocated.add_then_fetch(value, memory_order_relaxed);
} }
inline void G1EvacStats::add_num_plab_filled(size_t value) { inline void G1EvacStats::add_num_plab_filled(size_t value) {
AtomicAccess::add(&_num_plab_filled, value, memory_order_relaxed); _num_plab_filled.add_then_fetch(value, memory_order_relaxed);
} }
inline void G1EvacStats::add_num_direct_allocated(size_t value) { inline void G1EvacStats::add_num_direct_allocated(size_t value) {
AtomicAccess::add(&_num_direct_allocated, value, memory_order_relaxed); _num_direct_allocated.add_then_fetch(value, memory_order_relaxed);
} }
inline void G1EvacStats::add_region_end_waste(size_t value) { inline void G1EvacStats::add_region_end_waste(size_t value) {
AtomicAccess::add(&_region_end_waste, value, memory_order_relaxed); _region_end_waste.add_then_fetch(value, memory_order_relaxed);
AtomicAccess::inc(&_regions_filled, memory_order_relaxed); _regions_filled.add_then_fetch(1u, memory_order_relaxed);
} }
inline void G1EvacStats::add_failure_used_and_waste(size_t used, size_t waste) { inline void G1EvacStats::add_failure_used_and_waste(size_t used, size_t waste) {
AtomicAccess::add(&_failure_used, used, memory_order_relaxed); _failure_used.add_then_fetch(used, memory_order_relaxed);
AtomicAccess::add(&_failure_waste, waste, memory_order_relaxed); _failure_waste.add_then_fetch(waste, memory_order_relaxed);
} }
#endif // SHARE_GC_G1_G1EVACSTATS_INLINE_HPP #endif // SHARE_GC_G1_G1EVACSTATS_INLINE_HPP