Skip to content

Commit 0a70da4

Browse files
author
Kim Barrett
committed
8372564: Convert StringDedup to use Atomic<T>
Reviewed-by: tschatzl, aboldtch, iwalulya
1 parent 400d8cf commit 0a70da4

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/hotspot/share/gc/shared/stringdedup/stringDedupProcessor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "memory/iterator.hpp"
3737
#include "nmt/memTag.hpp"
3838
#include "oops/access.inline.hpp"
39-
#include "runtime/atomicAccess.hpp"
4039
#include "runtime/cpuTimeCounters.hpp"
4140
#include "runtime/interfaceSupport.inline.hpp"
4241
#include "runtime/mutexLocker.hpp"
@@ -46,17 +45,17 @@
4645

4746
OopStorage* StringDedup::Processor::_storages[2] = {};
4847

49-
StringDedup::StorageUse* volatile StringDedup::Processor::_storage_for_requests = nullptr;
48+
Atomic<StringDedup::StorageUse*> StringDedup::Processor::_storage_for_requests{};
5049
StringDedup::StorageUse* StringDedup::Processor::_storage_for_processing = nullptr;
5150

5251
void StringDedup::Processor::initialize_storage() {
5352
assert(_storages[0] == nullptr, "storage already created");
5453
assert(_storages[1] == nullptr, "storage already created");
55-
assert(_storage_for_requests == nullptr, "storage already created");
54+
assert(_storage_for_requests.load_relaxed() == nullptr, "storage already created");
5655
assert(_storage_for_processing == nullptr, "storage already created");
5756
_storages[0] = OopStorageSet::create_weak("StringDedup Requests0 Weak", mtStringDedup);
5857
_storages[1] = OopStorageSet::create_weak("StringDedup Requests1 Weak", mtStringDedup);
59-
_storage_for_requests = new StorageUse(_storages[0]);
58+
_storage_for_requests.store_relaxed(new StorageUse(_storages[0]));
6059
_storage_for_processing = new StorageUse(_storages[1]);
6160
}
6261

@@ -75,15 +74,15 @@ void StringDedup::Processor::wait_for_requests() const {
7574
{
7675
ThreadBlockInVM tbivm(_thread);
7776
MonitorLocker ml(StringDedup_lock, Mutex::_no_safepoint_check_flag);
78-
OopStorage* storage = AtomicAccess::load(&_storage_for_requests)->storage();
77+
OopStorage* storage = _storage_for_requests.load_relaxed()->storage();
7978
while ((storage->allocation_count() == 0) &&
8079
!Table::is_dead_entry_removal_needed()) {
8180
ml.wait();
8281
}
8382
}
8483
// Swap the request and processing storage objects.
8584
log_trace(stringdedup)("swapping request storages");
86-
_storage_for_processing = AtomicAccess::xchg(&_storage_for_requests, _storage_for_processing);
85+
_storage_for_processing = _storage_for_requests.exchange(_storage_for_processing);
8786
GlobalCounter::write_synchronize();
8887
// Wait for the now current processing storage object to no longer be used
8988
// by an in-progress GC. Again here, the num-dead notification from the

src/hotspot/share/gc/shared/stringdedup/stringDedupProcessor.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -27,6 +27,7 @@
2727

2828
#include "gc/shared/stringdedup/stringDedup.hpp"
2929
#include "memory/allocation.hpp"
30+
#include "runtime/atomic.hpp"
3031
#include "services/cpuTimeUsage.hpp"
3132
#include "utilities/macros.hpp"
3233

@@ -51,7 +52,7 @@ class StringDedup::Processor : public CHeapObj<mtGC> {
5152
NONCOPYABLE(Processor);
5253

5354
static OopStorage* _storages[2];
54-
static StorageUse* volatile _storage_for_requests;
55+
static Atomic<StorageUse*> _storage_for_requests;
5556
static StorageUse* _storage_for_processing;
5657

5758
JavaThread* _thread;

src/hotspot/share/gc/shared/stringdedup/stringDedupStorageUse.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "gc/shared/stringdedup/stringDedupStorageUse.hpp"
26-
#include "runtime/atomicAccess.hpp"
2726
#include "runtime/javaThread.hpp"
2827
#include "utilities/debug.hpp"
2928
#include "utilities/globalCounter.inline.hpp"
@@ -34,18 +33,18 @@ StringDedup::StorageUse::StorageUse(OopStorage* storage) :
3433
{}
3534

3635
bool StringDedup::StorageUse::is_used_acquire() const {
37-
return AtomicAccess::load_acquire(&_use_count) > 0;
36+
return _use_count.load_acquire() > 0;
3837
}
3938

4039
StringDedup::StorageUse*
41-
StringDedup::StorageUse::obtain(StorageUse* volatile* ptr) {
40+
StringDedup::StorageUse::obtain(Atomic<StorageUse*>* ptr) {
4241
GlobalCounter::CriticalSection cs(Thread::current());
43-
StorageUse* storage = AtomicAccess::load(ptr);
44-
AtomicAccess::inc(&storage->_use_count);
42+
StorageUse* storage = ptr->load_relaxed();
43+
storage->_use_count.add_then_fetch(1u);
4544
return storage;
4645
}
4746

4847
void StringDedup::StorageUse::relinquish() {
49-
size_t result = AtomicAccess::sub(&_use_count, size_t(1));
50-
assert(result != SIZE_MAX, "use count underflow");
48+
size_t result = _use_count.fetch_then_sub(1u);
49+
assert(result != 0, "use count underflow");
5150
}

src/hotspot/share/gc/shared/stringdedup/stringDedupStorageUse.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -27,6 +27,7 @@
2727

2828
#include "gc/shared/stringdedup/stringDedup.hpp"
2929
#include "memory/allocation.hpp"
30+
#include "runtime/atomic.hpp"
3031
#include "utilities/globalDefinitions.hpp"
3132
#include "utilities/macros.hpp"
3233

@@ -35,7 +36,7 @@ class OopStorage;
3536
// Manage access to one of the OopStorage objects used for requests.
3637
class StringDedup::StorageUse : public CHeapObj<mtStringDedup> {
3738
OopStorage* const _storage;
38-
volatile size_t _use_count;
39+
Atomic<size_t> _use_count;
3940

4041
NONCOPYABLE(StorageUse);
4142

@@ -48,7 +49,7 @@ class StringDedup::StorageUse : public CHeapObj<mtStringDedup> {
4849
bool is_used_acquire() const;
4950

5051
// Get the current requests object, and increment its in-use count.
51-
static StorageUse* obtain(StorageUse* volatile* ptr);
52+
static StorageUse* obtain(Atomic<StorageUse*>* ptr);
5253

5354
// Discard a prior "obtain" request, decrementing the in-use count, and
5455
// permitting the deduplication thread to start processing if needed.

0 commit comments

Comments
 (0)