@@ -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 {
519510private:
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
540530public:
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
0 commit comments