< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page
rev 59077 : 8153224.v2.09b.patch combined with 8153224.v2.10.patch; merge with jdk-15+21.


 473   _wait_barrier->disarm();
 474 }
 475 
 476 // Wake up all threads, so they are ready to resume execution after the safepoint
 477 // operation has been carried out
 478 void SafepointSynchronize::end() {
 479   assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
 480   EventSafepointEnd event;
 481   assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
 482 
 483   disarm_safepoint();
 484 
 485   Universe::heap()->safepoint_synchronize_end();
 486 
 487   SafepointTracing::end();
 488 
 489   post_safepoint_end_event(event, safepoint_id());
 490 }
 491 
 492 bool SafepointSynchronize::is_cleanup_needed() {
 493   // Need a safepoint if there are many monitors to deflate.
 494   if (ObjectSynchronizer::is_cleanup_needed()) return true;

 495   // Need a safepoint if some inline cache buffers is non-empty
 496   if (!InlineCacheBuffer::is_empty()) return true;
 497   if (StringTable::needs_rehashing()) return true;
 498   if (SymbolTable::needs_rehashing()) return true;
 499   return false;
 500 }
 501 
 502 bool SafepointSynchronize::is_forced_cleanup_needed() {
 503   return ObjectSynchronizer::needs_monitor_scavenge();
 504 }
 505 
 506 class ParallelSPCleanupThreadClosure : public ThreadClosure {
 507 private:
 508   CodeBlobClosure* _nmethod_cl;
 509   DeflateMonitorCounters* _counters;
 510 
 511 public:
 512   ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
 513     _nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
 514     _counters(counters) {}
 515 
 516   void do_thread(Thread* thread) {




 517     ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
 518     if (_nmethod_cl != NULL && thread->is_Java_thread() &&
 519         ! thread->is_Code_cache_sweeper_thread()) {
 520       JavaThread* jt = (JavaThread*) thread;
 521       jt->nmethods_do(_nmethod_cl);
 522     }
 523   }
 524 };
 525 
 526 class ParallelSPCleanupTask : public AbstractGangTask {
 527 private:
 528   SubTasksDone _subtasks;
 529   ParallelSPCleanupThreadClosure _cleanup_threads_cl;
 530   uint _num_workers;
 531   DeflateMonitorCounters* _counters;
 532 public:
 533   ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) :
 534     AbstractGangTask("Parallel Safepoint Cleanup"),
 535     _subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
 536     _cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)),
 537     _num_workers(num_workers),
 538     _counters(counters) {}
 539 
 540   void work(uint worker_id) {
 541     uint64_t safepoint_id = SafepointSynchronize::safepoint_id();
 542     // All threads deflate monitors and mark nmethods (if necessary).
 543     Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
 544 
 545     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
 546       const char* name = "deflating global idle monitors";
 547       EventSafepointCleanupTask event;
 548       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 549       ObjectSynchronizer::deflate_idle_monitors(_counters);




 550 
 551       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 552     }
 553 
 554     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
 555       const char* name = "updating inline caches";
 556       EventSafepointCleanupTask event;
 557       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 558       InlineCacheBuffer::update_inline_caches();
 559 
 560       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 561     }
 562 
 563     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
 564       const char* name = "compilation policy safepoint handler";
 565       EventSafepointCleanupTask event;
 566       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 567       CompilationPolicy::policy()->do_safepoint_work();
 568 
 569       post_safepoint_cleanup_task_event(event, safepoint_id, name);




 473   _wait_barrier->disarm();
 474 }
 475 
 476 // Wake up all threads, so they are ready to resume execution after the safepoint
 477 // operation has been carried out
 478 void SafepointSynchronize::end() {
 479   assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
 480   EventSafepointEnd event;
 481   assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
 482 
 483   disarm_safepoint();
 484 
 485   Universe::heap()->safepoint_synchronize_end();
 486 
 487   SafepointTracing::end();
 488 
 489   post_safepoint_end_event(event, safepoint_id());
 490 }
 491 
 492 bool SafepointSynchronize::is_cleanup_needed() {
 493   // Need a cleanup safepoint if there are too many monitors in use
 494   // and the monitor deflation needs to be done at a safepoint.
 495   if (ObjectSynchronizer::is_safepoint_deflation_needed()) return true;
 496   // Need a safepoint if some inline cache buffers is non-empty
 497   if (!InlineCacheBuffer::is_empty()) return true;
 498   if (StringTable::needs_rehashing()) return true;
 499   if (SymbolTable::needs_rehashing()) return true;
 500   return false;
 501 }
 502 
 503 bool SafepointSynchronize::is_forced_cleanup_needed() {
 504   return ObjectSynchronizer::needs_monitor_scavenge();
 505 }
 506 
 507 class ParallelSPCleanupThreadClosure : public ThreadClosure {
 508 private:
 509   CodeBlobClosure* _nmethod_cl;
 510   DeflateMonitorCounters* _counters;
 511 
 512 public:
 513   ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
 514     _nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
 515     _counters(counters) {}
 516 
 517   void do_thread(Thread* thread) {
 518     // deflate_thread_local_monitors() handles or requests deflation of
 519     // this thread's idle monitors. If !AsyncDeflateIdleMonitors or if
 520     // there is a special cleanup request, deflation is handled now.
 521     // Otherwise, async deflation is requested via a flag.
 522     ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
 523     if (_nmethod_cl != NULL && thread->is_Java_thread() &&
 524         ! thread->is_Code_cache_sweeper_thread()) {
 525       JavaThread* jt = (JavaThread*) thread;
 526       jt->nmethods_do(_nmethod_cl);
 527     }
 528   }
 529 };
 530 
 531 class ParallelSPCleanupTask : public AbstractGangTask {
 532 private:
 533   SubTasksDone _subtasks;
 534   ParallelSPCleanupThreadClosure _cleanup_threads_cl;
 535   uint _num_workers;
 536   DeflateMonitorCounters* _counters;
 537 public:
 538   ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) :
 539     AbstractGangTask("Parallel Safepoint Cleanup"),
 540     _subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS),
 541     _cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)),
 542     _num_workers(num_workers),
 543     _counters(counters) {}
 544 
 545   void work(uint worker_id) {
 546     uint64_t safepoint_id = SafepointSynchronize::safepoint_id();
 547     // All threads deflate monitors and mark nmethods (if necessary).
 548     Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
 549 
 550     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
 551       const char* name = "deflating global idle monitors";
 552       EventSafepointCleanupTask event;
 553       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 554       // AsyncDeflateIdleMonitors only uses DeflateMonitorCounters
 555       // when a special cleanup has been requested.
 556       // Note: This logging output will include global idle monitor
 557       // elapsed times, but not global idle monitor deflation count.
 558       ObjectSynchronizer::do_safepoint_work(_counters);
 559 
 560       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 561     }
 562 
 563     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
 564       const char* name = "updating inline caches";
 565       EventSafepointCleanupTask event;
 566       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 567       InlineCacheBuffer::update_inline_caches();
 568 
 569       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 570     }
 571 
 572     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
 573       const char* name = "compilation policy safepoint handler";
 574       EventSafepointCleanupTask event;
 575       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 576       CompilationPolicy::policy()->do_safepoint_work();
 577 
 578       post_safepoint_cleanup_task_event(event, safepoint_id, name);


< prev index next >