diff --git a/src/hotspot/share/gc/shared/space.cpp b/src/hotspot/share/gc/shared/space.cpp index 011a0f5cfd8..84ba21527fd 100644 --- a/src/hotspot/share/gc/shared/space.cpp +++ b/src/hotspot/share/gc/shared/space.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -30,7 +30,6 @@ #include "memory/iterator.inline.hpp" #include "memory/universe.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/java.hpp" #include "runtime/safepoint.hpp" #include "utilities/align.hpp" @@ -69,7 +68,7 @@ void ContiguousSpace::clear(bool mangle_space) { #ifndef PRODUCT void ContiguousSpace::mangle_unused_area() { - mangle_unused_area(MemRegion(_top, _end)); + mangle_unused_area(MemRegion(top(), _end)); } void ContiguousSpace::mangle_unused_area(MemRegion mr) { @@ -128,11 +127,8 @@ inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size) { HeapWord* obj = top(); if (pointer_delta(end(), obj) >= size) { HeapWord* new_top = obj + size; - HeapWord* result = AtomicAccess::cmpxchg(top_addr(), obj, new_top); - // result can be one of two: - // the old top value: the exchange succeeded - // otherwise: the new value of the top is returned. - if (result == obj) { + // Retry if we did not successfully updated the top pointers. + if (_top.compare_set(obj, new_top)) { assert(is_object_aligned(obj) && is_object_aligned(new_top), "checking alignment"); return obj; } diff --git a/src/hotspot/share/gc/shared/space.hpp b/src/hotspot/share/gc/shared/space.hpp index 7f2887275b3..05b22f680bf 100644 --- a/src/hotspot/share/gc/shared/space.hpp +++ b/src/hotspot/share/gc/shared/space.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -32,6 +32,7 @@ #include "memory/iterator.hpp" #include "memory/memRegion.hpp" #include "oops/markWord.hpp" +#include "runtime/atomic.hpp" #include "runtime/mutexLocker.hpp" #include "utilities/align.hpp" #include "utilities/macros.hpp" @@ -53,7 +54,7 @@ class ContiguousSpace: public CHeapObj { private: HeapWord* _bottom; HeapWord* _end; - HeapWord* _top; + Atomic _top; // Allocation helpers (return null if full). inline HeapWord* allocate_impl(size_t word_size); @@ -64,12 +65,12 @@ public: // Accessors HeapWord* bottom() const { return _bottom; } - HeapWord* end() const { return _end; } - HeapWord* top() const { return _top; } + HeapWord* end() const { return _end; } + HeapWord* top() const { return _top.load_relaxed(); } void set_bottom(HeapWord* value) { _bottom = value; } void set_end(HeapWord* value) { _end = value; } - void set_top(HeapWord* value) { _top = value; } + void set_top(HeapWord* value) { _top.store_relaxed(value); } // Testers bool is_empty() const { return used() == 0; } @@ -121,9 +122,6 @@ public: // Iteration void object_iterate(ObjectClosure* blk); - // Addresses for inlined allocation - HeapWord** top_addr() { return &_top; } - // Debugging void verify() const; }; diff --git a/src/hotspot/share/gc/shared/vmStructs_gc.hpp b/src/hotspot/share/gc/shared/vmStructs_gc.hpp index db968e28f67..6a29eb25b37 100644 --- a/src/hotspot/share/gc/shared/vmStructs_gc.hpp +++ b/src/hotspot/share/gc/shared/vmStructs_gc.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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 @@ -97,7 +97,7 @@ \ nonstatic_field(ContiguousSpace, _bottom, HeapWord*) \ nonstatic_field(ContiguousSpace, _end, HeapWord*) \ - nonstatic_field(ContiguousSpace, _top, HeapWord*) \ + nonstatic_field(ContiguousSpace, _top, Atomic) \ \ nonstatic_field(MemRegion, _start, HeapWord*) \ nonstatic_field(MemRegion, _word_size, size_t) diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp index 4ecc8f9ca01..02572e16728 100644 --- a/src/hotspot/share/runtime/vmStructs.cpp +++ b/src/hotspot/share/runtime/vmStructs.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -901,6 +901,7 @@ /*****************************/ \ \ declare_toplevel_type(void*) \ + declare_toplevel_type(Atomic) \ declare_toplevel_type(int*) \ declare_toplevel_type(char*) \ declare_toplevel_type(char**) \