Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8328507: Move StackWatermark code from safepoint cleanup #18378

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/hotspot/share/gc/shared/collectedHeap.hpp
Original file line number Diff line number Diff line change
@@ -350,11 +350,6 @@ class CollectedHeap : public CHeapObj<mtGC> {
return 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.
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

7 changes: 1 addition & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
@@ -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 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
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:
8 changes: 3 additions & 5 deletions src/hotspot/share/gc/x/xCollectedHeap.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

4 changes: 1 addition & 3 deletions src/hotspot/share/gc/x/xCollectedHeap.hpp
Original file line number Diff line number Diff line change
@@ -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 @@ class XCollectedHeap : public CollectedHeap {
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<GCMemoryManager*> memory_managers() override;
GrowableArray<MemoryPool*> memory_pools() override;
8 changes: 3 additions & 5 deletions src/hotspot/share/gc/z/zCollectedHeap.cpp
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 1 addition & 3 deletions src/hotspot/share/gc/z/zCollectedHeap.hpp
Original file line number Diff line number Diff line change
@@ -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 @@ class ZCollectedHeap : public CollectedHeap {
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<GCMemoryManager*> memory_managers() override;
GrowableArray<MemoryPool*> memory_pools() override;
23 changes: 1 addition & 22 deletions src/hotspot/share/runtime/safepoint.cpp
Original file line number Diff line number Diff line change
@@ -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 @@ class ParallelCleanupTask : public WorkerTask {
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<uint>(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.
1 change: 0 additions & 1 deletion src/hotspot/share/runtime/safepoint.hpp
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions src/hotspot/share/runtime/stackWatermarkSet.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 5 additions & 1 deletion src/hotspot/share/runtime/stackWatermarkSet.hpp
Original file line number Diff line number Diff line change
@@ -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 @@ class StackWatermarkSet : public AllStatic {
// 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