From cc7c293bce8a564943606dbbcad64db96909d68a Mon Sep 17 00:00:00 2001 From: William Kemper Date: Mon, 6 Jan 2025 18:24:37 +0000 Subject: [PATCH] 8345970: pthread_getcpuclockid related crashes in shenandoah tests Reviewed-by: shade Backport-of: 2ce53e88481659734bc5424c643c5e31c116bc5d --- .../share/gc/shenandoah/shenandoahGenerationalHeap.cpp | 2 +- src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp | 6 +++++- src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp | 6 +++++- src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp index 5b8afc52b93..2ad35fcb288 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp @@ -180,8 +180,8 @@ void ShenandoahGenerationalHeap::gc_threads_do(ThreadClosure* tcl) const { } void ShenandoahGenerationalHeap::stop() { - regulator_thread()->stop(); ShenandoahHeap::stop(); + regulator_thread()->stop(); } void ShenandoahGenerationalHeap::evacuate_collection_set(bool concurrent) { diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index 6ef66926b72..b69ebdc7d14 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -538,7 +538,6 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) : _pacer(nullptr), _verifier(nullptr), _phase_timings(nullptr), - _mmu_tracker(), _monitoring_support(nullptr), _memory_pool(nullptr), _stw_memory_manager("Shenandoah Pauses"), @@ -632,6 +631,8 @@ class ShenandoahInitWorkerGCLABClosure : public ThreadClosure { void ShenandoahHeap::post_initialize() { CollectedHeap::post_initialize(); + + // Schedule periodic task to report on gc thread CPU utilization _mmu_tracker.initialize(); MutexLocker ml(Threads_lock); @@ -2084,6 +2085,9 @@ void ShenandoahHeap::stop() { // Step 0. Notify policy to disable event recording and prevent visiting gc threads during shutdown _shenandoah_policy->record_shutdown(); + // Step 0a. Stop reporting on gc thread cpu utilization + mmu_tracker()->stop(); + // Step 1. Notify control thread that we are in shutdown. // Note that we cannot do that with stop(), because stop() is blocking and waits for the actual shutdown. // Doing stop() here would wait for the normal GC cycle to complete, never falling through to cancel below. diff --git a/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp b/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp index f4cbdbdd493..d9cec36e6c9 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp @@ -48,6 +48,7 @@ class ThreadTimeAccumulator : public ThreadClosure { size_t total_time; ThreadTimeAccumulator() : total_time(0) {} void do_thread(Thread* thread) override { + assert(!thread->has_terminated(), "Cannot get cpu time for terminated thread: " UINTX_FORMAT, thread->osthread()->thread_id_for_printing()); total_time += os::thread_cpu_time(thread); } }; @@ -65,7 +66,6 @@ ShenandoahMmuTracker::ShenandoahMmuTracker() : } ShenandoahMmuTracker::~ShenandoahMmuTracker() { - _mmu_periodic_task->disenroll(); delete _mmu_periodic_task; } @@ -175,6 +175,10 @@ void ShenandoahMmuTracker::report() { log_debug(gc)("Periodic Sample: GCU = %.3f%%, MU = %.3f%% during most recent %.1fs", gcu * 100, mu * 100, time_delta); } +void ShenandoahMmuTracker::stop() const { + _mmu_periodic_task->disenroll(); +} + void ShenandoahMmuTracker::initialize() { // initialize static data _active_processors = os::initial_active_processor_count(); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp b/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp index 53b6fdada55..89dbf921cd4 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp @@ -101,6 +101,10 @@ class ShenandoahMmuTracker { // GCPauseIntervalMillis and defaults to 5 seconds. This method computes // the MMU over the elapsed interval and records it in a running average. void report(); + + // Unenrolls the periodic task that collects CPU utilization for GC threads. This must happen _before_ the + // gc threads are stopped and terminated. + void stop() const; }; #endif //SHARE_GC_SHENANDOAH_SHENANDOAHMMUTRACKER_HPP