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