Skip to content

Commit 6fda441

Browse files
committed
8374690: ZGC: Convert zRelocate to use Atomic<T>
Reviewed-by: stefank, tschatzl
1 parent bd92c68 commit 6fda441

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/hotspot/share/gc/z/zRelocate.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -64,31 +64,31 @@ ZRelocateQueue::ZRelocateQueue()
6464
_needs_attention(0) {}
6565

6666
bool ZRelocateQueue::needs_attention() const {
67-
return AtomicAccess::load(&_needs_attention) != 0;
67+
return _needs_attention.load_relaxed() != 0;
6868
}
6969

7070
void ZRelocateQueue::inc_needs_attention() {
71-
const int needs_attention = AtomicAccess::add(&_needs_attention, 1);
71+
const int needs_attention = _needs_attention.add_then_fetch(1);
7272
assert(needs_attention == 1 || needs_attention == 2, "Invalid state");
7373
}
7474

7575
void ZRelocateQueue::dec_needs_attention() {
76-
const int needs_attention = AtomicAccess::sub(&_needs_attention, 1);
76+
const int needs_attention = _needs_attention.sub_then_fetch(1);
7777
assert(needs_attention == 0 || needs_attention == 1, "Invalid state");
7878
}
7979

8080
void ZRelocateQueue::activate(uint nworkers) {
81-
_is_active = true;
81+
_is_active.store_relaxed(true);
8282
join(nworkers);
8383
}
8484

8585
void ZRelocateQueue::deactivate() {
86-
AtomicAccess::store(&_is_active, false);
86+
_is_active.store_relaxed(false);
8787
clear();
8888
}
8989

9090
bool ZRelocateQueue::is_active() const {
91-
return AtomicAccess::load(&_is_active);
91+
return _is_active.load_relaxed();
9292
}
9393

9494
void ZRelocateQueue::join(uint nworkers) {
@@ -453,7 +453,7 @@ static void retire_target_page(ZGeneration* generation, ZPage* page) {
453453
class ZRelocateSmallAllocator {
454454
private:
455455
ZGeneration* const _generation;
456-
volatile size_t _in_place_count;
456+
Atomic<size_t> _in_place_count;
457457

458458
public:
459459
ZRelocateSmallAllocator(ZGeneration* generation)
@@ -463,7 +463,7 @@ class ZRelocateSmallAllocator {
463463
ZPage* alloc_and_retire_target_page(ZForwarding* forwarding, ZPage* target) {
464464
ZPage* const page = alloc_page(forwarding);
465465
if (page == nullptr) {
466-
AtomicAccess::inc(&_in_place_count);
466+
_in_place_count.add_then_fetch(1u);
467467
}
468468

469469
if (target != nullptr) {
@@ -493,7 +493,7 @@ class ZRelocateSmallAllocator {
493493
}
494494

495495
size_t in_place_count() const {
496-
return _in_place_count;
496+
return _in_place_count.load_relaxed();
497497
}
498498
};
499499

@@ -503,7 +503,7 @@ class ZRelocateMediumAllocator {
503503
ZConditionLock _lock;
504504
ZRelocationTargets* _shared_targets;
505505
bool _in_place;
506-
volatile size_t _in_place_count;
506+
Atomic<size_t> _in_place_count;
507507

508508
public:
509509
ZRelocateMediumAllocator(ZGeneration* generation, ZRelocationTargets* shared_targets)
@@ -539,7 +539,7 @@ class ZRelocateMediumAllocator {
539539
ZPage* const to_page = alloc_page(forwarding);
540540
_shared_targets->set(partition_id, to_age, to_page);
541541
if (to_page == nullptr) {
542-
AtomicAccess::inc(&_in_place_count);
542+
_in_place_count.add_then_fetch(1u);
543543
_in_place = true;
544544
}
545545

@@ -579,7 +579,7 @@ class ZRelocateMediumAllocator {
579579
}
580580

581581
size_t in_place_count() const {
582-
return _in_place_count;
582+
return _in_place_count.load_relaxed();
583583
}
584584
};
585585

src/hotspot/share/gc/z/zRelocate.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
2828
#include "gc/z/zPageAge.hpp"
2929
#include "gc/z/zRelocationSet.hpp"
3030
#include "gc/z/zValue.hpp"
31+
#include "runtime/atomic.hpp"
3132

3233
class ZForwarding;
3334
class ZGeneration;
@@ -42,8 +43,8 @@ class ZRelocateQueue {
4243
uint _nworkers;
4344
uint _nsynchronized;
4445
bool _synchronize;
45-
volatile bool _is_active;
46-
volatile int _needs_attention;
46+
Atomic<bool> _is_active;
47+
Atomic<int> _needs_attention;
4748

4849
bool needs_attention() const;
4950
void inc_needs_attention();

0 commit comments

Comments
 (0)