From 2ae3ea2ad93b83deec1922159d80b94da0397357 Mon Sep 17 00:00:00 2001 From: Guanqiang Han Date: Tue, 26 Aug 2025 08:35:52 +0000 Subject: [PATCH] 8366035: Simplify CPUTimeCounters::publish_gc_total_cpu_time Reviewed-by: ayang, kbarrett --- src/hotspot/share/runtime/cpuTimeCounters.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/runtime/cpuTimeCounters.cpp b/src/hotspot/share/runtime/cpuTimeCounters.cpp index 5b2e76fed7f..0248db8fec3 100644 --- a/src/hotspot/share/runtime/cpuTimeCounters.cpp +++ b/src/hotspot/share/runtime/cpuTimeCounters.cpp @@ -75,15 +75,9 @@ void CPUTimeCounters::inc_gc_total_cpu_time(jlong diff) { void CPUTimeCounters::publish_gc_total_cpu_time() { CPUTimeCounters* instance = CPUTimeCounters::get_instance(); - // Ensure that we are only incrementing atomically by using Atomic::cmpxchg - // to set the value to zero after we obtain the new CPU time difference. - jlong old_value; - jlong fetched_value = Atomic::load(&(instance->_gc_total_cpu_time_diff)); + // Atomically fetch the current _gc_total_cpu_time_diff and reset it to zero. jlong new_value = 0; - do { - old_value = fetched_value; - fetched_value = Atomic::cmpxchg(&(instance->_gc_total_cpu_time_diff), old_value, new_value); - } while (old_value != fetched_value); + jlong fetched_value = Atomic::xchg(&(instance->_gc_total_cpu_time_diff), new_value); get_counter(CPUTimeGroups::CPUTimeType::gc_total)->inc(fetched_value); }