8376335: Convert PreservedMarks classes to use Atomic<T>

Reviewed-by: stefank, iwalulya
This commit is contained in:
Thomas Schatzl 2026-01-29 08:54:37 +00:00
parent 92072a93bf
commit f9cc104249
2 changed files with 16 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,7 @@
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/atomicAccess.hpp"
#include "runtime/atomic.hpp"
#include "utilities/macros.hpp"
void PreservedMarks::restore() {
@ -55,15 +55,6 @@ void PreservedMarks::adjust_during_full_gc() {
}
}
void PreservedMarks::restore_and_increment(volatile size_t* const total_size_addr) {
const size_t stack_size = size();
restore();
// Only do the atomic add if the size is > 0.
if (stack_size > 0) {
AtomicAccess::add(total_size_addr, stack_size);
}
}
#ifndef PRODUCT
void PreservedMarks::assert_empty() {
assert(_stack.is_empty(), "stack expected to be empty, size = %zu",
@ -93,7 +84,7 @@ void PreservedMarksSet::init(uint num) {
class RestorePreservedMarksTask : public WorkerTask {
PreservedMarksSet* const _preserved_marks_set;
SequentialSubTasksDone _sub_tasks;
volatile size_t _total_size;
Atomic<size_t> _total_size;
#ifdef ASSERT
size_t _total_size_before;
#endif // ASSERT
@ -102,7 +93,12 @@ public:
void work(uint worker_id) override {
uint task_id = 0;
while (_sub_tasks.try_claim_task(task_id)) {
_preserved_marks_set->get(task_id)->restore_and_increment(&_total_size);
PreservedMarks* next = _preserved_marks_set->get(task_id);
size_t num_restored = next->size();
next->restore();
if (num_restored > 0) {
_total_size.add_then_fetch(num_restored);
}
}
}
@ -121,9 +117,11 @@ public:
}
~RestorePreservedMarksTask() {
assert(_total_size == _total_size_before, "total_size = %zu before = %zu", _total_size, _total_size_before);
size_t mem_size = _total_size * (sizeof(oop) + sizeof(markWord));
log_trace(gc)("Restored %zu marks, occupying %zu %s", _total_size,
size_t local_total_size = _total_size.load_relaxed();
assert(local_total_size == _total_size_before, "total_size = %zu before = %zu", local_total_size, _total_size_before);
size_t mem_size = local_total_size * (sizeof(oop) + sizeof(markWord));
log_trace(gc)("Restored %zu marks, occupying %zu %s", local_total_size,
byte_size_in_proper_unit(mem_size),
proper_unit_for_byte_size(mem_size));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -59,8 +59,7 @@ public:
size_t size() const { return _stack.size(); }
inline void push_if_necessary(oop obj, markWord m);
inline void push_always(oop obj, markWord m);
// Iterate over the stack, restore all preserved marks, and
// reclaim the memory taken up by the stack segments.
// Restore all preserved marks, and reclaim the memory taken up by the stack segments.
void restore();
// Adjust the preserved mark according to its
@ -71,8 +70,6 @@ public:
// to their forwarding location stored in the mark.
void adjust_during_full_gc();
void restore_and_increment(volatile size_t* const _total_size_addr);
// Assert the stack is empty and has no cached segments.
void assert_empty() PRODUCT_RETURN;