Skip to content

Commit

Permalink
8227060: Optimize safepoint cleanup subtask order
Browse files Browse the repository at this point in the history
Reviewed-by: kbarrett, pchilanomate
  • Loading branch information
coleenp committed Jul 19, 2022
1 parent 2cb659e commit 96a542f
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
Original file line number Diff line number Diff line change
@@ -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 @@ -252,7 +252,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
Original file line number Diff line number Diff line change
Expand Up @@ -516,19 +516,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(JavaThread::cast(thread), StackWatermarkKind::gc);
}
}
};

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

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

public:
ParallelSPCleanupTask(uint num_workers) :
ParallelCleanupTask() :
WorkerTask("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 @@ -595,6 +567,25 @@ class ParallelSPCleanupTask : public WorkerTask {
}
}

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_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 @@ -612,15 +603,13 @@ void SafepointSynchronize::do_cleanup_tasks() {

CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "heap not initialized yet?");
ParallelCleanupTask cleanup;
WorkerThreads* 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, 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 @@ -41,7 +41,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 96a542f

@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.