Skip to content

Commit aa595db

Browse files
committed
8328507: Move StackWatermark code from safepoint cleanup
Reviewed-by: aboldtch, coleenp
1 parent 2af0312 commit aa595db

File tree

11 files changed

+31
-53
lines changed

11 files changed

+31
-53
lines changed

src/hotspot/share/gc/shared/collectedHeap.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,6 @@ class CollectedHeap : public CHeapObj<mtGC> {
347347
// collection or expansion activity.
348348
virtual size_t unsafe_max_tlab_alloc(Thread *thr) const = 0;
349349

350-
// If a GC uses a stack watermark barrier, the stack processing is lazy, concurrent,
351-
// incremental and cooperative. In order for that to work well, mechanisms that stop
352-
// another thread might want to ensure its roots are in a sane state.
353-
virtual bool uses_stack_watermark_barrier() const { return false; }
354-
355350
// Perform a collection of the heap; intended for use in implementing
356351
// "System.gc". This probably implies as full a collection as the
357352
// "CollectedHeap" supports.

src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#include "runtime/java.hpp"
8888
#include "runtime/orderAccess.hpp"
8989
#include "runtime/safepointMechanism.hpp"
90+
#include "runtime/stackWatermarkSet.hpp"
9091
#include "runtime/vmThread.hpp"
9192
#include "utilities/events.hpp"
9293
#include "utilities/powerOfTwo.hpp"
@@ -2302,6 +2303,7 @@ bool ShenandoahHeap::uncommit_bitmap_slice(ShenandoahHeapRegion *r) {
23022303
}
23032304

23042305
void ShenandoahHeap::safepoint_synchronize_begin() {
2306+
StackWatermarkSet::safepoint_synchronize_begin();
23052307
SuspendibleThreadSet::synchronize();
23062308
}
23072309

src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -539,11 +539,6 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
539539
void sync_pinned_region_status();
540540
void assert_pinned_region_status() NOT_DEBUG_RETURN;
541541

542-
// ---------- Concurrent Stack Processing support
543-
//
544-
public:
545-
bool uses_stack_watermark_barrier() const override { return true; }
546-
547542
// ---------- Allocation support
548543
//
549544
private:

src/hotspot/share/gc/x/xCollectedHeap.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -43,6 +43,7 @@
4343
#include "memory/universe.hpp"
4444
#include "oops/stackChunkOop.hpp"
4545
#include "runtime/continuationJavaClasses.hpp"
46+
#include "runtime/stackWatermarkSet.hpp"
4647
#include "utilities/align.hpp"
4748

4849
XCollectedHeap* XCollectedHeap::heap() {
@@ -215,10 +216,6 @@ size_t XCollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const {
215216
return _heap.unsafe_max_tlab_alloc();
216217
}
217218

218-
bool XCollectedHeap::uses_stack_watermark_barrier() const {
219-
return true;
220-
}
221-
222219
MemoryUsage XCollectedHeap::memory_usage() {
223220
return _heap.serviceability_memory_pool()->get_memory_usage();
224221
}
@@ -277,6 +274,7 @@ VirtualSpaceSummary XCollectedHeap::create_heap_space_summary() {
277274
}
278275

279276
void XCollectedHeap::safepoint_synchronize_begin() {
277+
StackWatermarkSet::safepoint_synchronize_begin();
280278
SuspendibleThreadSet::synchronize();
281279
}
282280

src/hotspot/share/gc/x/xCollectedHeap.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -87,8 +87,6 @@ class XCollectedHeap : public CollectedHeap {
8787
size_t max_tlab_size() const override;
8888
size_t unsafe_max_tlab_alloc(Thread* thr) const override;
8989

90-
bool uses_stack_watermark_barrier() const override;
91-
9290
MemoryUsage memory_usage() override;
9391
GrowableArray<GCMemoryManager*> memory_managers() override;
9492
GrowableArray<MemoryPool*> memory_pools() override;

src/hotspot/share/gc/z/zCollectedHeap.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -50,6 +50,7 @@
5050
#include "oops/stackChunkOop.hpp"
5151
#include "runtime/continuationJavaClasses.hpp"
5252
#include "runtime/jniHandles.inline.hpp"
53+
#include "runtime/stackWatermarkSet.hpp"
5354
#include "services/memoryUsage.hpp"
5455
#include "utilities/align.hpp"
5556

@@ -240,10 +241,6 @@ size_t ZCollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const {
240241
return _heap.unsafe_max_tlab_alloc();
241242
}
242243

243-
bool ZCollectedHeap::uses_stack_watermark_barrier() const {
244-
return true;
245-
}
246-
247244
MemoryUsage ZCollectedHeap::memory_usage() {
248245
const size_t initial_size = ZHeap::heap()->initial_capacity();
249246
const size_t committed = ZHeap::heap()->capacity();
@@ -338,6 +335,7 @@ bool ZCollectedHeap::contains_null(const oop* p) const {
338335
}
339336

340337
void ZCollectedHeap::safepoint_synchronize_begin() {
338+
StackWatermarkSet::safepoint_synchronize_begin();
341339
ZGeneration::young()->synchronize_relocation();
342340
ZGeneration::old()->synchronize_relocation();
343341
SuspendibleThreadSet::synchronize();

src/hotspot/share/gc/z/zCollectedHeap.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, 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
@@ -88,8 +88,6 @@ class ZCollectedHeap : public CollectedHeap {
8888
size_t max_tlab_size() const override;
8989
size_t unsafe_max_tlab_alloc(Thread* thr) const override;
9090

91-
bool uses_stack_watermark_barrier() const override;
92-
9391
MemoryUsage memory_usage() override;
9492
GrowableArray<GCMemoryManager*> memory_managers() override;
9593
GrowableArray<MemoryPool*> memory_pools() override;

src/hotspot/share/runtime/safepoint.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ void SafepointSynchronize::end() {
510510
class ParallelCleanupTask : public WorkerTask {
511511
private:
512512
SubTasksDone _subtasks;
513-
bool _do_lazy_roots;
514513

515514
class Tracer {
516515
private:
@@ -531,35 +530,15 @@ class ParallelCleanupTask : public WorkerTask {
531530
public:
532531
ParallelCleanupTask() :
533532
WorkerTask("Parallel Safepoint Cleanup"),
534-
_subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
535-
_do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() &&
536-
Universe::heap()->uses_stack_watermark_barrier()) {}
533+
_subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS) {}
537534

538535
uint expected_num_workers() const {
539536
uint workers = 0;
540537

541-
if (_do_lazy_roots) {
542-
workers++;
543-
}
544-
545538
return MAX2<uint>(1, workers);
546539
}
547540

548541
void work(uint worker_id) {
549-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) {
550-
if (_do_lazy_roots) {
551-
Tracer t("lazy partial thread root processing");
552-
class LazyRootClosure : public ThreadClosure {
553-
public:
554-
void do_thread(Thread* thread) {
555-
StackWatermarkSet::start_processing(JavaThread::cast(thread), StackWatermarkKind::gc);
556-
}
557-
};
558-
LazyRootClosure cl;
559-
Threads::java_threads_do(&cl);
560-
}
561-
}
562-
563542
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) {
564543
// Don't bother reporting event or time for this very short operation.
565544
// To have any utility we'd also want to report whether needed.

src/hotspot/share/runtime/safepoint.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class SafepointSynchronize : AllStatic {
7070

7171
// The enums are listed in the order of the tasks when done serially.
7272
enum SafepointCleanupTasks {
73-
SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING,
7473
SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP,
7574
// Leave this one last.
7675
SAFEPOINT_CLEANUP_NUM_TASKS

src/hotspot/share/runtime/stackWatermarkSet.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, 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
@@ -31,6 +31,9 @@
3131
#include "runtime/safepointMechanism.inline.hpp"
3232
#include "runtime/stackWatermark.inline.hpp"
3333
#include "runtime/stackWatermarkSet.inline.hpp"
34+
#include "runtime/threadSMR.hpp"
35+
#include "runtime/vmOperation.hpp"
36+
#include "runtime/vmThread.hpp"
3437
#include "utilities/debug.hpp"
3538
#include "utilities/globalDefinitions.hpp"
3639
#include "utilities/preserveException.hpp"
@@ -118,7 +121,6 @@ void StackWatermarkSet::on_safepoint(JavaThread* jt) {
118121

119122
void StackWatermarkSet::start_processing(JavaThread* jt, StackWatermarkKind kind) {
120123
verify_processing_context();
121-
assert(!jt->is_terminated(), "Poll after termination is a bug");
122124
StackWatermark* watermark = get(jt, kind);
123125
if (watermark != nullptr) {
124126
watermark->start_processing();
@@ -158,3 +160,13 @@ uintptr_t StackWatermarkSet::lowest_watermark(JavaThread* jt) {
158160
return watermark;
159161
}
160162
}
163+
164+
void StackWatermarkSet::safepoint_synchronize_begin() {
165+
if (VMThread::vm_operation()->skip_thread_oop_barriers()) {
166+
return;
167+
}
168+
169+
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
170+
StackWatermarkSet::start_processing(thread, StackWatermarkKind::gc);
171+
}
172+
}

0 commit comments

Comments
 (0)