diff --git a/src/hotspot/share/gc/shared/collectedHeap.hpp b/src/hotspot/share/gc/shared/collectedHeap.hpp index 511156170ee..b2ec4b67325 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.hpp +++ b/src/hotspot/share/gc/shared/collectedHeap.hpp @@ -347,11 +347,6 @@ protected: // collection or expansion activity. virtual size_t unsafe_max_tlab_alloc(Thread *thr) const = 0; - // If a GC uses a stack watermark barrier, the stack processing is lazy, concurrent, - // incremental and cooperative. In order for that to work well, mechanisms that stop - // another thread might want to ensure its roots are in a sane state. - virtual bool uses_stack_watermark_barrier() const { return false; } - // Perform a collection of the heap; intended for use in implementing // "System.gc". This probably implies as full a collection as the // "CollectedHeap" supports. diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index f0a2e53a12b..24a94e9d867 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -87,6 +87,7 @@ #include "runtime/java.hpp" #include "runtime/orderAccess.hpp" #include "runtime/safepointMechanism.hpp" +#include "runtime/stackWatermarkSet.hpp" #include "runtime/vmThread.hpp" #include "utilities/events.hpp" #include "utilities/powerOfTwo.hpp" @@ -2302,6 +2303,7 @@ bool ShenandoahHeap::uncommit_bitmap_slice(ShenandoahHeapRegion *r) { } void ShenandoahHeap::safepoint_synchronize_begin() { + StackWatermarkSet::safepoint_synchronize_begin(); SuspendibleThreadSet::synchronize(); } diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp index d3bddc8cc76..e30b1d12e77 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -539,11 +539,6 @@ public: void sync_pinned_region_status(); void assert_pinned_region_status() NOT_DEBUG_RETURN; -// ---------- Concurrent Stack Processing support -// -public: - bool uses_stack_watermark_barrier() const override { return true; } - // ---------- Allocation support // private: diff --git a/src/hotspot/share/gc/x/xCollectedHeap.cpp b/src/hotspot/share/gc/x/xCollectedHeap.cpp index cabe7c3c77b..d03b6312a67 100644 --- a/src/hotspot/share/gc/x/xCollectedHeap.cpp +++ b/src/hotspot/share/gc/x/xCollectedHeap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -43,6 +43,7 @@ #include "memory/universe.hpp" #include "oops/stackChunkOop.hpp" #include "runtime/continuationJavaClasses.hpp" +#include "runtime/stackWatermarkSet.hpp" #include "utilities/align.hpp" XCollectedHeap* XCollectedHeap::heap() { @@ -215,10 +216,6 @@ size_t XCollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const { return _heap.unsafe_max_tlab_alloc(); } -bool XCollectedHeap::uses_stack_watermark_barrier() const { - return true; -} - MemoryUsage XCollectedHeap::memory_usage() { return _heap.serviceability_memory_pool()->get_memory_usage(); } @@ -277,6 +274,7 @@ VirtualSpaceSummary XCollectedHeap::create_heap_space_summary() { } void XCollectedHeap::safepoint_synchronize_begin() { + StackWatermarkSet::safepoint_synchronize_begin(); SuspendibleThreadSet::synchronize(); } diff --git a/src/hotspot/share/gc/x/xCollectedHeap.hpp b/src/hotspot/share/gc/x/xCollectedHeap.hpp index 940524ab997..250c882d15e 100644 --- a/src/hotspot/share/gc/x/xCollectedHeap.hpp +++ b/src/hotspot/share/gc/x/xCollectedHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -87,8 +87,6 @@ public: size_t max_tlab_size() const override; size_t unsafe_max_tlab_alloc(Thread* thr) const override; - bool uses_stack_watermark_barrier() const override; - MemoryUsage memory_usage() override; GrowableArray memory_managers() override; GrowableArray memory_pools() override; diff --git a/src/hotspot/share/gc/z/zCollectedHeap.cpp b/src/hotspot/share/gc/z/zCollectedHeap.cpp index 12608a32c84..ccfa7af6b7d 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.cpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -50,6 +50,7 @@ #include "oops/stackChunkOop.hpp" #include "runtime/continuationJavaClasses.hpp" #include "runtime/jniHandles.inline.hpp" +#include "runtime/stackWatermarkSet.hpp" #include "services/memoryUsage.hpp" #include "utilities/align.hpp" @@ -240,10 +241,6 @@ size_t ZCollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const { return _heap.unsafe_max_tlab_alloc(); } -bool ZCollectedHeap::uses_stack_watermark_barrier() const { - return true; -} - MemoryUsage ZCollectedHeap::memory_usage() { const size_t initial_size = ZHeap::heap()->initial_capacity(); const size_t committed = ZHeap::heap()->capacity(); @@ -338,6 +335,7 @@ bool ZCollectedHeap::contains_null(const oop* p) const { } void ZCollectedHeap::safepoint_synchronize_begin() { + StackWatermarkSet::safepoint_synchronize_begin(); ZGeneration::young()->synchronize_relocation(); ZGeneration::old()->synchronize_relocation(); SuspendibleThreadSet::synchronize(); diff --git a/src/hotspot/share/gc/z/zCollectedHeap.hpp b/src/hotspot/share/gc/z/zCollectedHeap.hpp index 48ebae5388c..528bacd8df8 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.hpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -88,8 +88,6 @@ public: size_t max_tlab_size() const override; size_t unsafe_max_tlab_alloc(Thread* thr) const override; - bool uses_stack_watermark_barrier() const override; - MemoryUsage memory_usage() override; GrowableArray memory_managers() override; GrowableArray memory_pools() override; diff --git a/src/hotspot/share/runtime/safepoint.cpp b/src/hotspot/share/runtime/safepoint.cpp index 47db0bcb625..21f89519eaf 100644 --- a/src/hotspot/share/runtime/safepoint.cpp +++ b/src/hotspot/share/runtime/safepoint.cpp @@ -510,7 +510,6 @@ void SafepointSynchronize::end() { class ParallelCleanupTask : public WorkerTask { private: SubTasksDone _subtasks; - bool _do_lazy_roots; class Tracer { private: @@ -531,35 +530,15 @@ private: public: ParallelCleanupTask() : WorkerTask("Parallel Safepoint Cleanup"), - _subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS), - _do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() && - Universe::heap()->uses_stack_watermark_barrier()) {} + _subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS) {} uint expected_num_workers() const { uint workers = 0; - if (_do_lazy_roots) { - workers++; - } - return MAX2(1, workers); } void work(uint worker_id) { - if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) { - if (_do_lazy_roots) { - Tracer t("lazy partial thread root processing"); - class LazyRootClosure : public ThreadClosure { - public: - void do_thread(Thread* thread) { - StackWatermarkSet::start_processing(JavaThread::cast(thread), StackWatermarkKind::gc); - } - }; - LazyRootClosure cl; - Threads::java_threads_do(&cl); - } - } - if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) { // Don't bother reporting event or time for this very short operation. // To have any utility we'd also want to report whether needed. diff --git a/src/hotspot/share/runtime/safepoint.hpp b/src/hotspot/share/runtime/safepoint.hpp index 84db745d3ca..c8b80b34217 100644 --- a/src/hotspot/share/runtime/safepoint.hpp +++ b/src/hotspot/share/runtime/safepoint.hpp @@ -70,7 +70,6 @@ class SafepointSynchronize : AllStatic { // The enums are listed in the order of the tasks when done serially. enum SafepointCleanupTasks { - SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING, SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP, // Leave this one last. SAFEPOINT_CLEANUP_NUM_TASKS diff --git a/src/hotspot/share/runtime/stackWatermarkSet.cpp b/src/hotspot/share/runtime/stackWatermarkSet.cpp index a49b1bfc307..0595604932c 100644 --- a/src/hotspot/share/runtime/stackWatermarkSet.cpp +++ b/src/hotspot/share/runtime/stackWatermarkSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -31,6 +31,9 @@ #include "runtime/safepointMechanism.inline.hpp" #include "runtime/stackWatermark.inline.hpp" #include "runtime/stackWatermarkSet.inline.hpp" +#include "runtime/threadSMR.hpp" +#include "runtime/vmOperation.hpp" +#include "runtime/vmThread.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/preserveException.hpp" @@ -118,7 +121,6 @@ void StackWatermarkSet::on_safepoint(JavaThread* jt) { void StackWatermarkSet::start_processing(JavaThread* jt, StackWatermarkKind kind) { verify_processing_context(); - assert(!jt->is_terminated(), "Poll after termination is a bug"); StackWatermark* watermark = get(jt, kind); if (watermark != nullptr) { watermark->start_processing(); @@ -158,3 +160,13 @@ uintptr_t StackWatermarkSet::lowest_watermark(JavaThread* jt) { return watermark; } } + +void StackWatermarkSet::safepoint_synchronize_begin() { + if (VMThread::vm_operation()->skip_thread_oop_barriers()) { + return; + } + + for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) { + StackWatermarkSet::start_processing(thread, StackWatermarkKind::gc); + } +} diff --git a/src/hotspot/share/runtime/stackWatermarkSet.hpp b/src/hotspot/share/runtime/stackWatermarkSet.hpp index 11c27abb85e..1853d0e2897 100644 --- a/src/hotspot/share/runtime/stackWatermarkSet.hpp +++ b/src/hotspot/share/runtime/stackWatermarkSet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -88,6 +88,10 @@ public: // The lowest watermark among the watermarks in the set (the first encountered // watermark in the set as you unwind frames) static uintptr_t lowest_watermark(JavaThread* jt); + + // We are synchronizing a safepoint, so we might want to ensure processing has at least + // started, as safepoint operations sometimes assume that is the case + static void safepoint_synchronize_begin(); }; #endif // SHARE_RUNTIME_STACKWATERMARKSET_HPP