8374679: ZGC: Convert zForwardingAllocator to use Atomic<T>

Reviewed-by: stefank, tschatzl
This commit is contained in:
Axel Boldt-Christmas 2026-01-26 14:13:48 +00:00
parent 512f95cf26
commit fef85ff932
3 changed files with 11 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -34,6 +34,7 @@ ZForwardingAllocator::~ZForwardingAllocator() {
}
void ZForwardingAllocator::reset(size_t size) {
_start = _top = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC);
_start = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC);
_top.store_relaxed(_start);
_end = _start + size;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -24,13 +24,14 @@
#ifndef SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP
#define SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP
#include "runtime/atomic.hpp"
#include "utilities/globalDefinitions.hpp"
class ZForwardingAllocator {
private:
char* _start;
char* _end;
char* _top;
char* _start;
char* _end;
Atomic<char*> _top;
public:
ZForwardingAllocator();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -26,7 +26,6 @@
#include "gc/z/zForwardingAllocator.hpp"
#include "runtime/atomicAccess.hpp"
#include "utilities/debug.hpp"
inline size_t ZForwardingAllocator::size() const {
@ -34,11 +33,11 @@ inline size_t ZForwardingAllocator::size() const {
}
inline bool ZForwardingAllocator::is_full() const {
return _top == _end;
return _top.load_relaxed() == _end;
}
inline void* ZForwardingAllocator::alloc(size_t size) {
char* const addr = AtomicAccess::fetch_then_add(&_top, size);
char* const addr = _top.fetch_then_add(size);
assert(addr + size <= _end, "Allocation should never fail");
return addr;
}