Skip to content

Commit 464a32b

Browse files
committed
8227060: Optimize safepoint cleanup subtask order
Reviewed-by: phh Backport-of: 96a542feb2064dba155ebf05311752995d164038
1 parent 6033871 commit 464a32b

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
@@ -251,7 +251,6 @@ class CompilationPolicy : AllStatic {
251251
static bool can_be_osr_compiled(const methodHandle& m, int comp_level = CompLevel_any);
252252
static bool is_compilation_enabled();
253253

254-
static void do_safepoint_work() { }
255254
static CompileTask* select_task_helper(CompileQueue* compile_queue);
256255
// Return initial compile level to use with Xcomp (depends on compilation mode).
257256
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
@@ -506,19 +506,9 @@ bool SafepointSynchronize::is_cleanup_needed() {
506506
return false;
507507
}
508508

509-
class ParallelSPCleanupThreadClosure : public ThreadClosure {
510-
public:
511-
void do_thread(Thread* thread) {
512-
if (thread->is_Java_thread()) {
513-
StackWatermarkSet::start_processing(thread->as_Java_thread(), StackWatermarkKind::gc);
514-
}
515-
}
516-
};
517-
518-
class ParallelSPCleanupTask : public AbstractGangTask {
509+
class ParallelCleanupTask : public AbstractGangTask {
519510
private:
520511
SubTasksDone _subtasks;
521-
uint _num_workers;
522512
bool _do_lazy_roots;
523513

524514
class Tracer {
@@ -538,32 +528,14 @@ class ParallelSPCleanupTask : public AbstractGangTask {
538528
};
539529

540530
public:
541-
ParallelSPCleanupTask(uint num_workers) :
531+
ParallelCleanupTask() :
542532
AbstractGangTask("Parallel Safepoint Cleanup"),
543533
_subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
544-
_num_workers(num_workers),
545534
_do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() &&
546535
Universe::heap()->uses_stack_watermark_barrier()) {}
547536

548537
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-
ParallelSPCleanupThreadClosure cl;
553-
Threads::threads_do(&cl);
554-
}
555-
}
556-
557-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
558-
Tracer t("updating inline caches");
559-
InlineCacheBuffer::update_inline_caches();
560-
}
561-
562-
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
563-
Tracer t("compilation policy safepoint handler");
564-
CompilationPolicy::do_safepoint_work();
565-
}
566-
538+
// These tasks are ordered by relative length of time to execute so that potentially longer tasks start first.
567539
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH)) {
568540
if (SymbolTable::needs_rehashing()) {
569541
Tracer t("rehashing symbol table");
@@ -585,6 +557,25 @@ class ParallelSPCleanupTask : public AbstractGangTask {
585557
}
586558
}
587559

560+
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) {
561+
if (_do_lazy_roots) {
562+
Tracer t("lazy partial thread root processing");
563+
class LazyRootClosure : public ThreadClosure {
564+
public:
565+
void do_thread(Thread* thread) {
566+
StackWatermarkSet::start_processing(thread->as_Java_thread(), StackWatermarkKind::gc);
567+
}
568+
};
569+
LazyRootClosure cl;
570+
Threads::java_threads_do(&cl);
571+
}
572+
}
573+
574+
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
575+
Tracer t("updating inline caches");
576+
InlineCacheBuffer::update_inline_caches();
577+
}
578+
588579
if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) {
589580
// Don't bother reporting event or time for this very short operation.
590581
// To have any utility we'd also want to report whether needed.
@@ -602,15 +593,13 @@ void SafepointSynchronize::do_cleanup_tasks() {
602593

603594
CollectedHeap* heap = Universe::heap();
604595
assert(heap != NULL, "heap not initialized yet?");
596+
ParallelCleanupTask cleanup;
605597
WorkGang* cleanup_workers = heap->safepoint_workers();
606598
if (cleanup_workers != NULL) {
607599
// Parallel cleanup using GC provided thread pool.
608-
uint num_cleanup_workers = cleanup_workers->active_workers();
609-
ParallelSPCleanupTask cleanup(num_cleanup_workers);
610600
cleanup_workers->run_task(&cleanup);
611601
} else {
612602
// Serial cleanup using VMThread.
613-
ParallelSPCleanupTask cleanup(1);
614603
cleanup.work(0);
615604
}
616605

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
@@ -1676,7 +1676,7 @@ void ObjectSynchronizer::do_final_audit_and_print_stats() {
16761676
; // empty
16771677
}
16781678
// The other audit_and_print_stats() call is done at the Debug
1679-
// level at a safepoint in ObjectSynchronizer::do_safepoint_work().
1679+
// level at a safepoint in SafepointSynchronize::do_cleanup_tasks.
16801680
ObjectSynchronizer::audit_and_print_stats(true /* on_exit */);
16811681
}
16821682
}

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, 2020, 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
@@ -40,7 +40,6 @@ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
4040
output.shouldContain("[safepoint,cleanup]");
4141
output.shouldContain("safepoint cleanup tasks");
4242
output.shouldContain("updating inline caches");
43-
output.shouldContain("compilation policy safepoint handler");
4443
output.shouldHaveExitValue(0);
4544
}
4645

0 commit comments

Comments
 (0)