8374687: ZGC: Convert zNMethodTableIteration to use Atomic<T>

Reviewed-by: stefank, tschatzl
This commit is contained in:
Axel Boldt-Christmas 2026-01-27 08:36:41 +00:00
parent 5c05d6f230
commit bd92c68ef0
2 changed files with 9 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 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,7 +24,6 @@
#include "gc/z/zNMethodTableEntry.hpp" #include "gc/z/zNMethodTableEntry.hpp"
#include "gc/z/zNMethodTableIteration.hpp" #include "gc/z/zNMethodTableIteration.hpp"
#include "memory/iterator.hpp" #include "memory/iterator.hpp"
#include "runtime/atomicAccess.hpp"
#include "utilities/debug.hpp" #include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp" #include "utilities/globalDefinitions.hpp"
@ -42,11 +41,11 @@ void ZNMethodTableIteration::nmethods_do_begin(ZNMethodTableEntry* table, size_t
_table = table; _table = table;
_size = size; _size = size;
_claimed = 0; _claimed.store_relaxed(0u);
} }
void ZNMethodTableIteration::nmethods_do_end() { void ZNMethodTableIteration::nmethods_do_end() {
assert(_claimed >= _size, "Failed to claim all table entries"); assert(_claimed.load_relaxed() >= _size, "Failed to claim all table entries");
// Finish iteration // Finish iteration
_table = nullptr; _table = nullptr;
@ -57,7 +56,7 @@ void ZNMethodTableIteration::nmethods_do(NMethodClosure* cl) {
// Claim table partition. Each partition is currently sized to span // Claim table partition. Each partition is currently sized to span
// two cache lines. This number is just a guess, but seems to work well. // two cache lines. This number is just a guess, but seems to work well.
const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry); const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry);
const size_t partition_start = MIN2(AtomicAccess::fetch_then_add(&_claimed, partition_size), _size); const size_t partition_start = MIN2(_claimed.fetch_then_add(partition_size), _size);
const size_t partition_end = MIN2(partition_start + partition_size, _size); const size_t partition_end = MIN2(partition_start + partition_size, _size);
if (partition_start == partition_end) { if (partition_start == partition_end) {
// End of table // End of table

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 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
@ -25,6 +25,7 @@
#define SHARE_GC_Z_ZNMETHODTABLEITERATION_HPP #define SHARE_GC_Z_ZNMETHODTABLEITERATION_HPP
#include "gc/z/zGlobals.hpp" #include "gc/z/zGlobals.hpp"
#include "runtime/atomic.hpp"
class NMethodClosure; class NMethodClosure;
class ZNMethodTableEntry; class ZNMethodTableEntry;
@ -33,7 +34,7 @@ class ZNMethodTableIteration {
private: private:
ZNMethodTableEntry* _table; ZNMethodTableEntry* _table;
size_t _size; size_t _size;
ZCACHE_ALIGNED volatile size_t _claimed; ZCACHE_ALIGNED Atomic<size_t> _claimed;
bool in_progress() const; bool in_progress() const;