< prev index next >

src/hotspot/share/runtime/safepoint.cpp

Print this page
rev 56776 : v2.00 -> v2.07 (CR7/v2.07/10-for-jdk14) patches combined into one; merge with 8230876.patch (2019.10.17) and jdk-14+21.


 506   _wait_barrier->disarm();
 507 }
 508 
 509 // Wake up all threads, so they are ready to resume execution after the safepoint
 510 // operation has been carried out
 511 void SafepointSynchronize::end() {
 512   assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
 513   EventSafepointEnd event;
 514   assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
 515 
 516   disarm_safepoint();
 517 
 518   Universe::heap()->safepoint_synchronize_end();
 519 
 520   SafepointTracing::end();
 521 
 522   post_safepoint_end_event(event, safepoint_id());
 523 }
 524 
 525 bool SafepointSynchronize::is_cleanup_needed() {
 526   // Need a safepoint if there are many monitors to deflate.
 527   if (ObjectSynchronizer::is_cleanup_needed()) return true;

 528   // Need a safepoint if some inline cache buffers is non-empty
 529   if (!InlineCacheBuffer::is_empty()) return true;
 530   if (StringTable::needs_rehashing()) return true;
 531   if (SymbolTable::needs_rehashing()) return true;
 532   return false;
 533 }
 534 
 535 class ParallelSPCleanupThreadClosure : public ThreadClosure {
 536 private:
 537   CodeBlobClosure* _nmethod_cl;
 538   DeflateMonitorCounters* _counters;
 539 
 540 public:
 541   ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
 542     _nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
 543     _counters(counters) {}
 544 
 545   void do_thread(Thread* thread) {




 546     ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
 547     if (_nmethod_cl != NULL && thread->is_Java_thread() &&
 548         ! thread->is_Code_cache_sweeper_thread()) {
 549       JavaThread* jt = (JavaThread*) thread;
 550       jt->nmethods_do(_nmethod_cl);
 551     }
 552   }
 553 };
 554 
 555 class ParallelSPCleanupTask : public AbstractGangTask {
 556 private:
 557   SubTasksDone _subtasks;
 558   ParallelSPCleanupThreadClosure _cleanup_threads_cl;
 559   uint _num_workers;
 560   DeflateMonitorCounters* _counters;
 561 public:
 562   ParallelSPCleanupTask(uint num_workers, DeflateMonitorCounters* counters) :
 563     AbstractGangTask("Parallel Safepoint Cleanup"),
 564     _subtasks(SubTasksDone(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS)),
 565     _cleanup_threads_cl(ParallelSPCleanupThreadClosure(counters)),
 566     _num_workers(num_workers),
 567     _counters(counters) {}
 568 
 569   void work(uint worker_id) {
 570     uint64_t safepoint_id = SafepointSynchronize::safepoint_id();
 571     // All threads deflate monitors and mark nmethods (if necessary).
 572     Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
 573 
 574     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_DEFLATE_MONITORS)) {
 575       const char* name = "deflating global idle monitors";
 576       EventSafepointCleanupTask event;
 577       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 578       ObjectSynchronizer::deflate_idle_monitors(_counters);




 579 
 580       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 581     }
 582 
 583     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) {
 584       const char* name = "updating inline caches";
 585       EventSafepointCleanupTask event;
 586       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 587       InlineCacheBuffer::update_inline_caches();
 588 
 589       post_safepoint_cleanup_task_event(event, safepoint_id, name);
 590     }
 591 
 592     if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) {
 593       const char* name = "compilation policy safepoint handler";
 594       EventSafepointCleanupTask event;
 595       TraceTime timer(name, TRACETIME_LOG(Info, safepoint, cleanup));
 596       CompilationPolicy::policy()->do_safepoint_work();
 597 
 598       post_safepoint_cleanup_task_event(event, safepoint_id, name);




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


< prev index next >