Compare commits

...

2 Commits

Author SHA1 Message Date
Jonas Norlinder
aeb4ad045f Refactor shared logic into CollectedHeap, remove nominal logging and cost->usage 2025-06-12 17:19:35 +02:00
Jonas Norlinder
b9a3432f7a Remove unnecessary assert 2025-06-12 16:07:13 +02:00
9 changed files with 22 additions and 67 deletions

View File

@ -1480,26 +1480,6 @@ void G1CollectedHeap::stop() {
_cm_thread->stop(); _cm_thread->stop();
} }
class G1VCPUThreadClosure : public ThreadClosure {
private:
volatile jlong _vtime = 0;
public:
virtual void do_thread(Thread *thread) {
Atomic::add(&_vtime, os::thread_cpu_time(thread));
}
jlong vtime() { return _vtime; };
};
double G1CollectedHeap::elapsed_gc_vtime() {
G1VCPUThreadClosure cl;
_cr->threads_do(&cl);
_cm->threads_do(&cl);
_workers->threads_do(&cl);
return ((double) cl.vtime() + os::thread_cpu_time(_service_thread) + os::thread_cpu_time(_cm_thread) + Universe::heap()->vm_vtime()) / NANOSECS_PER_SEC;
}
void G1CollectedHeap::safepoint_synchronize_begin() { void G1CollectedHeap::safepoint_synchronize_begin() {
SuspendibleThreadSet::synchronize(); SuspendibleThreadSet::synchronize();
} }

View File

@ -932,8 +932,6 @@ public:
GrowableArray<GCMemoryManager*> memory_managers() override; GrowableArray<GCMemoryManager*> memory_managers() override;
GrowableArray<MemoryPool*> memory_pools() override; GrowableArray<MemoryPool*> memory_pools() override;
double elapsed_gc_vtime() override;
void fill_with_dummy_object(HeapWord* start, HeapWord* end, bool zap) override; void fill_with_dummy_object(HeapWord* start, HeapWord* end, bool zap) override;
static void start_codecache_marking_cycle_if_inactive(bool concurrent_mark_start); static void start_codecache_marking_cycle_if_inactive(bool concurrent_mark_start);

View File

@ -164,23 +164,6 @@ void ParallelScavengeHeap::stop() {
log_gc_vtime(); log_gc_vtime();
} }
class ParallelVCPUThreadClosure : public ThreadClosure {
private:
volatile jlong _vtime = 0;
public:
virtual void do_thread(Thread *thread) {
Atomic::add(&_vtime, os::thread_cpu_time(thread));
}
jlong vtime() { return _vtime; };
};
double ParallelScavengeHeap::elapsed_gc_vtime() {
ParallelVCPUThreadClosure cl;
workers().threads_do(&cl);
return (double)(cl.vtime() + Universe::heap()->vm_vtime()) / NANOSECS_PER_SEC;
}
void ParallelScavengeHeap::safepoint_synchronize_begin() { void ParallelScavengeHeap::safepoint_synchronize_begin() {
if (UseStringDeduplication) { if (UseStringDeduplication) {
SuspendibleThreadSet::synchronize(); SuspendibleThreadSet::synchronize();

View File

@ -215,7 +215,6 @@ public:
void print_tracing_info() const override; void print_tracing_info() const override;
void stop() override; void stop() override;
double elapsed_gc_vtime() override;
WorkerThreads* safepoint_workers() override { return &_workers; } WorkerThreads* safepoint_workers() override { return &_workers; }

View File

@ -201,6 +201,23 @@ void CollectedHeap::print_relative_to_gc(GCWhen::Type when) const {
} }
} }
class VCPUThreadClosure : public ThreadClosure {
private:
volatile jlong _vtime = 0;
public:
virtual void do_thread(Thread *thread) {
Atomic::add(&_vtime, os::thread_cpu_time(thread));
}
jlong vtime() { return _vtime; };
};
double CollectedHeap::elapsed_gc_vtime() {
VCPUThreadClosure cl;
gc_threads_do(&cl);
return (double)(cl.vtime() + Universe::heap()->vm_vtime()) / NANOSECS_PER_SEC;
}
void CollectedHeap::print_before_gc() const { void CollectedHeap::print_before_gc() const {
print_relative_to_gc(GCWhen::BeforeGC); print_relative_to_gc(GCWhen::BeforeGC);
} }
@ -221,17 +238,15 @@ void CollectedHeap::log_gc_vtime() {
if (process_vtime == -1 || gc_vtime == -1) return; if (process_vtime == -1 || gc_vtime == -1) return;
log_info(gc, cpu)("Process CPU time: %fs", process_vtime); double usage = -1;
log_info(gc, cpu)("GC CPU time: %fs", gc_vtime);
double cost = -1;
if (gc_vtime > process_vtime || process_vtime == 0 || gc_vtime == 0) { if (gc_vtime > process_vtime || process_vtime == 0 || gc_vtime == 0) {
// This can happen e.g. for short running processes with // This can happen e.g. for short running processes with
// low CPU utilization // low CPU utilization
cost = 0; usage = 0;
} else { } else {
cost = 100 * gc_vtime / process_vtime; usage = 100 * gc_vtime / process_vtime;
} }
log_info(gc)("GC CPU cost: %2.2f%%", cost); log_info(gc)("GC CPU usage: %2.2f%%", usage);
} }
} }

View File

@ -465,7 +465,7 @@ protected:
// Default implementation does nothing. // Default implementation does nothing.
virtual void print_tracing_info() const = 0; virtual void print_tracing_info() const = 0;
virtual double elapsed_gc_vtime() { return -1; }; virtual double elapsed_gc_vtime();
void log_gc_vtime(); void log_gc_vtime();
void print_before_gc() const; void print_before_gc() const;

View File

@ -48,7 +48,6 @@ inline VTimeScope::~VTimeScope() {
} }
if (UsePerfData) { if (UsePerfData) {
assert(_thread == this, "Assumes VM thread");
CPUTimeCounters::get_instance()->update_counter(CPUTimeGroups::CPUTimeType::vm, end); CPUTimeCounters::get_instance()->update_counter(CPUTimeGroups::CPUTimeType::vm, end);
} }
} }

View File

@ -2220,23 +2220,6 @@ void ShenandoahHeap::stop() {
} }
} }
class ShenandoahCPUThreadClosure : public ThreadClosure {
private:
volatile jlong _vtime = 0;
public:
virtual void do_thread(Thread *thread) {
Atomic::add(&_vtime, os::thread_cpu_time(thread));
}
jlong vtime() { return _vtime; };
};
double ShenandoahHeap::elapsed_gc_vtime() {
ShenandoahCPUThreadClosure cl;
ShenandoahHeap::heap()->gc_threads_do(&cl);
return (double)(cl.vtime() + Universe::heap()->vm_vtime()) / NANOSECS_PER_SEC;
}
void ShenandoahHeap::stw_unload_classes(bool full_gc) { void ShenandoahHeap::stw_unload_classes(bool full_gc) {
if (!unload_classes()) return; if (!unload_classes()) return;
ClassUnloadingContext ctx(_workers->active_workers(), ClassUnloadingContext ctx(_workers->active_workers(),

View File

@ -209,8 +209,6 @@ public:
void stop() override; void stop() override;
double elapsed_gc_vtime() override;
void prepare_for_verify() override; void prepare_for_verify() override;
void verify(VerifyOption vo) override; void verify(VerifyOption vo) override;