508
509 bool SafepointSynchronize::is_cleanup_needed() {
510 // Need a safepoint if there are many monitors to deflate.
511 if (ObjectSynchronizer::is_cleanup_needed()) return true;
512 // Need a safepoint if some inline cache buffers is non-empty
513 if (!InlineCacheBuffer::is_empty()) return true;
514 return false;
515 }
516
517 class ParallelSPCleanupThreadClosure : public ThreadClosure {
518 private:
519 CodeBlobClosure* _nmethod_cl;
520 DeflateMonitorCounters* _counters;
521
522 public:
523 ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
524 _nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
525 _counters(counters) {}
526
527 void do_thread(Thread* thread) {
528 ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
529 if (_nmethod_cl != NULL && thread->is_Java_thread() &&
530 ! thread->is_Code_cache_sweeper_thread()) {
531 JavaThread* jt = (JavaThread*) thread;
532 jt->nmethods_do(_nmethod_cl);
533 }
534 }
535 };
536
537 class ParallelSPCleanupTask : public AbstractGangTask {
538 private:
539 SubTasksDone _subtasks;
540 ParallelSPCleanupThreadClosure _cleanup_threads_cl;
541 uint _num_workers;
542 DeflateMonitorCounters* _counters;
543 public:
544 ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) :
545 AbstractGangTask("Parallel Safepoint Cleanup"),
546 _subtasks(SubTasksDone(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS)),
547 _cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)),
548 _num_workers(num_workers),
549 _counters(counters) {}
550
551 void work(uint worker_id) {
552 uint64_t safepoint_id = SafepointSynchronize::safepoint_counter();
553 // All threads deflate monitors and mark nmethods (if necessary).
554 Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
555
556 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
557 const char* name = "deflating global idle monitors";
558 EventSafepointCleanupTask event;
559 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
560 ObjectSynchronizer::deflate_idle_monitors(_counters);
561
562 post_safepoint_cleanup_task_event(event, safepoint_id, name);
563 }
564
565 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
566 const char* name = "updating inline caches";
567 EventSafepointCleanupTask event;
568 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
569 InlineCacheBuffer::update_inline_caches();
570
571 post_safepoint_cleanup_task_event(event, safepoint_id, name);
572 }
573
574 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
575 const char* name = "compilation policy safepoint handler";
576 EventSafepointCleanupTask event;
577 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
578 CompilationPolicy::policy()->do_safepoint_work();
579
580 post_safepoint_cleanup_task_event(event, safepoint_id, name);
|
508
509 bool SafepointSynchronize::is_cleanup_needed() {
510 // Need a safepoint if there are many monitors to deflate.
511 if (ObjectSynchronizer::is_cleanup_needed()) return true;
512 // Need a safepoint if some inline cache buffers is non-empty
513 if (!InlineCacheBuffer::is_empty()) return true;
514 return false;
515 }
516
517 class ParallelSPCleanupThreadClosure : public ThreadClosure {
518 private:
519 CodeBlobClosure* _nmethod_cl;
520 DeflateMonitorCounters* _counters;
521
522 public:
523 ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
524 _nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
525 _counters(counters) {}
526
527 void do_thread(Thread* thread) {
528 // deflate_thread_local_monitors() handles or requests deflation of
529 // this thread's idle monitors. If !AsyncDeflateIdleMonitors or if
530 // there is a special cleanup request, deflation is handled now.
531 // Otherwise, async deflation is requested via a flag.
532 ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
533 if (_nmethod_cl != NULL && thread->is_Java_thread() &&
534 ! thread->is_Code_cache_sweeper_thread()) {
535 JavaThread* jt = (JavaThread*) thread;
536 jt->nmethods_do(_nmethod_cl);
537 }
538 }
539 };
540
541 class ParallelSPCleanupTask : public AbstractGangTask {
542 private:
543 SubTasksDone _subtasks;
544 ParallelSPCleanupThreadClosure _cleanup_threads_cl;
545 uint _num_workers;
546 DeflateMonitorCounters* _counters;
547 public:
548 ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) :
549 AbstractGangTask("Parallel Safepoint Cleanup"),
550 _subtasks(SubTasksDone(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS)),
551 _cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)),
552 _num_workers(num_workers),
553 _counters(counters) {}
554
555 void work(uint worker_id) {
556 uint64_t safepoint_id = SafepointSynchronize::safepoint_counter();
557 // All threads deflate monitors and mark nmethods (if necessary).
558 Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
559
560 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
561 const char* name = "deflating global idle monitors";
562 EventSafepointCleanupTask event;
563 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
564 // AsyncDeflateIdleMonitors only uses DeflateMonitorCounters
565 // when a special cleanup has been requested.
566 // Note: This logging output will include global idle monitor
567 // elapsed times, but not global idle monitor deflation count.
568 ObjectSynchronizer::do_safepoint_work(_counters);
569
570 post_safepoint_cleanup_task_event(event, safepoint_id, name);
571 }
572
573 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
574 const char* name = "updating inline caches";
575 EventSafepointCleanupTask event;
576 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
577 InlineCacheBuffer::update_inline_caches();
578
579 post_safepoint_cleanup_task_event(event, safepoint_id, name);
580 }
581
582 if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
583 const char* name = "compilation policy safepoint handler";
584 EventSafepointCleanupTask event;
585 TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
586 CompilationPolicy::policy()->do_safepoint_work();
587
588 post_safepoint_cleanup_task_event(event, safepoint_id, name);
|