Skip to content

Commit

Permalink
8227060: Optimize safepoint cleanup subtask order
Browse files Browse the repository at this point in the history
Reviewed-by: phh
Backport-of: 96a542feb2064dba155ebf05311752995d164038
  • Loading branch information
shipilev committed May 24, 2023
1 parent 6033871 commit 464a32b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
3 changes: 1 addition & 2 deletions src/hotspot/share/compiler/compilationPolicy.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, 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
Expand Down Expand Up @@ -251,7 +251,6 @@ class CompilationPolicy : AllStatic {
static bool can_be_osr_compiled(const methodHandle& m, int comp_level = CompLevel_any);
static bool is_compilation_enabled();

static void do_safepoint_work() { }
static CompileTask* select_task_helper(CompileQueue* compile_queue);
// Return initial compile level to use with Xcomp (depends on compilation mode).
static void reprofile(ScopeDesc* trap_scope, bool is_osr);
Expand Down
57 changes: 23 additions & 34 deletions src/hotspot/share/runtime/safepoint.cpp
Expand Up @@ -506,19 +506,9 @@ bool SafepointSynchronize::is_cleanup_needed() {
return false;
}

class ParallelSPCleanupThreadClosure : public ThreadClosure {
public:
void do_thread(Thread* thread) {
if (thread->is_Java_thread()) {
StackWatermarkSet::start_processing(thread->as_Java_thread(), StackWatermarkKind::gc);
}
}
};

class ParallelSPCleanupTask : public AbstractGangTask {
class ParallelCleanupTask : public AbstractGangTask {
private:
SubTasksDone _subtasks;
uint _num_workers;
bool _do_lazy_roots;

class Tracer {
Expand All @@ -538,32 +528,14 @@ class ParallelSPCleanupTask : public AbstractGangTask {
};

public:
ParallelSPCleanupTask(uint num_workers) :
ParallelCleanupTask() :
AbstractGangTask("Parallel Safepoint Cleanup"),
_subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
_num_workers(num_workers),
_do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() &&
Universe::heap()->uses_stack_watermark_barrier()) {}

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");
ParallelSPCleanupThreadClosure cl;
Threads::threads_do(&cl);
}
}

if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
Tracer t("updating inline caches");
InlineCacheBuffer::update_inline_caches();
}

if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
Tracer t("compilation policy safepoint handler");
CompilationPolicy::do_safepoint_work();
}

// These tasks are ordered by relative length of time to execute so that potentially longer tasks start first.
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH)) {
if (SymbolTable::needs_rehashing()) {
Tracer t("rehashing symbol table");
Expand All @@ -585,6 +557,25 @@ class ParallelSPCleanupTask : public AbstractGangTask {
}
}

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(thread->as_Java_thread(), StackWatermarkKind::gc);
}
};
LazyRootClosure cl;
Threads::java_threads_do(&cl);
}
}

if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
Tracer t("updating inline caches");
InlineCacheBuffer::update_inline_caches();
}

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.
Expand All @@ -602,15 +593,13 @@ void SafepointSynchronize::do_cleanup_tasks() {

CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "heap not initialized yet?");
ParallelCleanupTask cleanup;
WorkGang* cleanup_workers = heap->safepoint_workers();
if (cleanup_workers != NULL) {
// Parallel cleanup using GC provided thread pool.
uint num_cleanup_workers = cleanup_workers->active_workers();
ParallelSPCleanupTask cleanup(num_cleanup_workers);
cleanup_workers->run_task(&cleanup);
} else {
// Serial cleanup using VMThread.
ParallelSPCleanupTask cleanup(1);
cleanup.work(0);
}

Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/runtime/safepoint.hpp
Expand Up @@ -72,7 +72,6 @@ class SafepointSynchronize : AllStatic {
enum SafepointCleanupTasks {
SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING,
SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
SAFEPOINT_CLEANUP_COMPILATION_POLICY,
SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/synchronizer.cpp
Expand Up @@ -1676,7 +1676,7 @@ void ObjectSynchronizer::do_final_audit_and_print_stats() {
; // empty
}
// The other audit_and_print_stats() call is done at the Debug
// level at a safepoint in ObjectSynchronizer::do_safepoint_work().
// level at a safepoint in SafepointSynchronize::do_cleanup_tasks.
ObjectSynchronizer::audit_and_print_stats(true /* on_exit */);
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/runtime/logging/SafepointCleanupTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, 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
Expand Down Expand Up @@ -40,7 +40,6 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
output.shouldContain("[safepoint,cleanup]");
output.shouldContain("safepoint cleanup tasks");
output.shouldContain("updating inline caches");
output.shouldContain("compilation policy safepoint handler");
output.shouldHaveExitValue(0);
}

Expand Down

1 comment on commit 464a32b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.