Skip to content

Commit

Permalink
8345970: pthread_getcpuclockid related crashes in shenandoah tests
Browse files Browse the repository at this point in the history
Reviewed-by: shade
Backport-of: 2ce53e8
  • Loading branch information
William Kemper committed Jan 6, 2025
1 parent 33971ec commit cc7c293
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand All @@ -65,7 +66,6 @@ ShenandoahMmuTracker::ShenandoahMmuTracker() :
}

ShenandoahMmuTracker::~ShenandoahMmuTracker() {
_mmu_periodic_task->disenroll();
delete _mmu_periodic_task;
}

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahMmuTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc7c293

Please sign in to comment.