Skip to content

Commit 96a542f

Browse files
committed
8227060: Optimize safepoint cleanup subtask order
Reviewed-by: kbarrett, pchilanomate
1 parent 2cb659e commit 96a542f

File tree

5 files changed

+26
-40
lines changed

5 files changed

+26
-40
lines changed

src/hotspot/share/compiler/compilationPolicy.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, 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
@@ -252,7 +252,6 @@ class CompilationPolicy : AllStatic {
252252
static bool can_be_osr_compiled(const methodHandle& m, int comp_level = CompLevel_any);
253253
static bool is_compilation_enabled();
254254

255-
static void do_safepoint_work() { }
256255
static CompileTask* select_task_helper(CompileQueue* compile_queue);
257256
// Return initial compile level to use with Xcomp (depends on compilation mode).
258257
static void reprofile(ScopeDesc* trap_scope, bool is_osr);

src/hotspot/share/runtime/safepoint.cpp

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -516,19 +516,9 @@ bool SafepointSynchronize::is_cleanup_needed() {
516516
return false;
517517
}
518518

519-
class ParallelSPCleanupThreadClosure : public ThreadClosure {
520-
public:
521-
void do_thread(Thread* thread) {
522-
if (thread->is_Java_thread()) {
523-
StackWatermarkSet::start_processing(JavaThread::cast(thread), StackWatermarkKind::gc);
524-
}
525-
}
526-
};
527-
528-
class ParallelSPCleanupTask : public WorkerTask {
519+
class ParallelCleanupTask : public WorkerTask {
529520
private:
530521
SubTasksDone _subtasks;
531-
uint _num_workers;
532522
bool _do_lazy_roots;
533523

534524
class Tracer {
@@ -548,32 +538,14 @@ class ParallelSPCleanupTask : public WorkerTask {
548538
};
549539

550540
public:
551-
ParallelSPCleanupTask(uint num_workers) :
541+
ParallelCleanupTask() :
552542
WorkerTask("Parallel Safepoint Cleanup"),
553543
_subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
554-
_num_workers(num_workers),
555544
_do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() &&
556545
Universe::heap()->uses_stack_watermark_barrier()) {}
557546

558547
void work(uint worker_id) {
559-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) {
560-
if (_do_lazy_roots) {
561-
Tracer t("lazy partial thread root processing");
562-
ParallelSPCleanupThreadClosure cl;
563-
Threads::threads_do(&cl);
564-
}
565-
}
566-
567-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
568-
Tracer t("updating inline caches");
569-
InlineCacheBuffer::update_inline_caches();
570-
}
571-
572-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
573-
Tracer t("compilation policy safepoint handler");
574-
CompilationPolicy::do_safepoint_work();
575-
}
576-
548+
// These tasks are ordered by relative length of time to execute so that potentially longer tasks start first.
577549
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH)) {
578550
if (SymbolTable::needs_rehashing()) {
579551
Tracer t("rehashing symbol table");
@@ -595,6 +567,25 @@ class ParallelSPCleanupTask : public WorkerTask {
595567
}
596568
}
597569

570+
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) {
571+
if (_do_lazy_roots) {
572+
Tracer t("lazy partial thread root processing");
573+
class LazyRootClosure : public ThreadClosure {
574+
public:
575+
void do_thread(Thread* thread) {
576+
StackWatermarkSet::start_processing(JavaThread::cast(thread), StackWatermarkKind::gc);
577+
}
578+
};
579+
LazyRootClosure cl;
580+
Threads::java_threads_do(&cl);
581+
}
582+
}
583+
584+
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
585+
Tracer t("updating inline caches");
586+
InlineCacheBuffer::update_inline_caches();
587+
}
588+
598589
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) {
599590
// Don't bother reporting event or time for this very short operation.
600591
// To have any utility we'd also want to report whether needed.
@@ -612,15 +603,13 @@ void SafepointSynchronize::do_cleanup_tasks() {
612603

613604
CollectedHeap* heap = Universe::heap();
614605
assert(heap != NULL, "heap not initialized yet?");
606+
ParallelCleanupTask cleanup;
615607
WorkerThreads* cleanup_workers = heap->safepoint_workers();
616608
if (cleanup_workers != NULL) {
617609
// Parallel cleanup using GC provided thread pool.
618-
uint num_cleanup_workers = cleanup_workers->active_workers();
619-
ParallelSPCleanupTask cleanup(num_cleanup_workers);
620610
cleanup_workers->run_task(&cleanup);
621611
} else {
622612
// Serial cleanup using VMThread.
623-
ParallelSPCleanupTask cleanup(1);
624613
cleanup.work(0);
625614
}
626615

src/hotspot/share/runtime/safepoint.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class SafepointSynchronize : AllStatic {
7272
enum SafepointCleanupTasks {
7373
SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING,
7474
SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
75-
SAFEPOINT_CLEANUP_COMPILATION_POLICY,
7675
SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
7776
SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
7877
SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,

src/hotspot/share/runtime/synchronizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ void ObjectSynchronizer::do_final_audit_and_print_stats() {
16711671
; // empty
16721672
}
16731673
// The other audit_and_print_stats() call is done at the Debug
1674-
// level at a safepoint in ObjectSynchronizer::do_safepoint_work().
1674+
// level at a safepoint in SafepointSynchronize::do_cleanup_tasks.
16751675
ObjectSynchronizer::audit_and_print_stats(true /* on_exit */);
16761676
}
16771677
}

test/hotspot/jtreg/runtime/logging/SafepointCleanupTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2022, 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
@@ -41,7 +41,6 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
4141
output.shouldContain("[safepoint,cleanup]");
4242
output.shouldContain("safepoint cleanup tasks");
4343
output.shouldContain("updating inline caches");
44-
output.shouldContain("compilation policy safepoint handler");
4544
output.shouldHaveExitValue(0);
4645
}
4746

0 commit comments

Comments
 (0)