Skip to content

Commit

Permalink
8291753: Add JFR event for GC CPU Time
Browse files Browse the repository at this point in the history
Reviewed-by: phh
Backport-of: 14eb5ad0dc987ffe3621f4eeeebeb6b5a2cd691b
  • Loading branch information
GoeLin committed Mar 11, 2024
1 parent f221ff3 commit 833e2bb
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ bool G1CollectedHeap::do_full_collection(bool explicit_gc,

G1FullGCMark gc_mark;
GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause(), true);
G1FullCollector collector(this, explicit_gc, do_clear_all_soft_refs, do_maximum_compaction);
G1FullCollector collector(this, explicit_gc, do_clear_all_soft_refs, do_maximum_compaction, gc_mark.tracer());

collector.prepare_collection();
collector.collect();
Expand Down Expand Up @@ -2981,7 +2981,7 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus

// Inner scope for scope based logging, timers, and stats collection
{
GCTraceCPUTime tcpu;
GCTraceCPUTime tcpu(_gc_tracer_stw);

char young_gc_name[MaxYoungGCNameLength];
set_young_gc_name(young_gc_name);
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ class G1ConcurrentMark : public CHeapObj<mtGC> {

ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }

G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }

private:
// Rebuilds the remembered sets for chosen regions in parallel and concurrently to the application.
void rebuild_rem_set_concurrently();
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/gc/g1/g1FullCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ uint G1FullCollector::calc_active_workers() {
G1FullCollector::G1FullCollector(G1CollectedHeap* heap,
bool explicit_gc,
bool clear_soft_refs,
bool do_maximum_compaction) :
bool do_maximum_compaction,
G1FullGCTracer* tracer) :
_heap(heap),
_scope(heap->g1mm(), explicit_gc, clear_soft_refs, do_maximum_compaction),
_scope(heap->g1mm(), explicit_gc, clear_soft_refs, do_maximum_compaction, tracer),
_num_workers(calc_active_workers()),
_oop_queue_set(_num_workers),
_array_queue_set(_num_workers),
Expand Down
7 changes: 5 additions & 2 deletions src/hotspot/share/gc/g1/g1FullCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class G1FullGCSubjectToDiscoveryClosure: public BoolObjectClosure {
// to have the same structure as the Young GC logging.
class G1FullGCMark : StackObj {
GCIdMark _gc_id;
G1FullGCTracer _tracer;
GCTraceCPUTime _cpu_time;
public:
G1FullGCMark() : _gc_id(), _cpu_time() { }
G1FullGCMark() : _gc_id(), _tracer(), _cpu_time(&_tracer) { }
G1FullGCTracer* tracer() { return &_tracer; }
};

// The G1FullCollector holds data associated with the current Full GC.
Expand Down Expand Up @@ -93,7 +95,8 @@ class G1FullCollector : StackObj {
G1FullCollector(G1CollectedHeap* heap,
bool explicit_gc,
bool clear_soft_refs,
bool do_maximum_compaction);
bool do_maximum_compaction,
G1FullGCTracer* tracer);
~G1FullCollector();

void prepare_collection();
Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/share/gc/g1/g1FullGCScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ G1FullGCJFRTracerMark::~G1FullGCJFRTracerMark() {
G1FullGCScope::G1FullGCScope(G1MonitoringSupport* monitoring_support,
bool explicit_gc,
bool clear_soft,
bool do_maximum_compaction) :
bool do_maximum_compaction,
G1FullGCTracer* tracer) :
_rm(),
_explicit_gc(explicit_gc),
_g1h(G1CollectedHeap::heap()),
_svc_marker(SvcGCMarker::FULL),
_timer(),
_tracer(),
_tracer(tracer),
_active(),
_tracer_mark(&_timer, &_tracer),
_tracer_mark(&_timer, _tracer),
_soft_refs(clear_soft, _g1h->soft_ref_policy()),
_monitoring_scope(monitoring_support, true /* full_gc */, true /* all_memory_pools_affected */),
_heap_printer(_g1h),
Expand Down Expand Up @@ -75,7 +76,7 @@ STWGCTimer* G1FullGCScope::timer() {
}

G1FullGCTracer* G1FullGCScope::tracer() {
return &_tracer;
return _tracer;
}

size_t G1FullGCScope::region_compaction_threshold() {
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/gc/g1/g1FullGCScope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class G1FullGCScope : public StackObj {
G1CollectedHeap* _g1h;
SvcGCMarker _svc_marker;
STWGCTimer _timer;
G1FullGCTracer _tracer;
G1FullGCTracer* _tracer;
IsGCActiveMark _active;
G1FullGCJFRTracerMark _tracer_mark;
ClearedAllSoftRefs _soft_refs;
Expand All @@ -63,7 +63,8 @@ class G1FullGCScope : public StackObj {
G1FullGCScope(G1MonitoringSupport* monitoring_support,
bool explicit_gc,
bool clear_soft,
bool do_maximal_compaction);
bool do_maximal_compaction,
G1FullGCTracer* tracer);
~G1FullGCScope();

bool is_explicit_gc();
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/gc/g1/g1VMOperations.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,7 @@
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
#include "gc/g1/g1Policy.hpp"
#include "gc/g1/g1VMOperations.hpp"
#include "gc/g1/g1Trace.hpp"
#include "gc/shared/concurrentGCBreakpoints.hpp"
#include "gc/shared/gcCause.hpp"
#include "gc/shared/gcId.hpp"
Expand Down Expand Up @@ -161,8 +162,8 @@ void VM_G1CollectForAllocation::doit() {

void VM_G1PauseConcurrent::doit() {
GCIdMark gc_id_mark(_gc_id);
GCTraceCPUTime tcpu;
G1CollectedHeap* g1h = G1CollectedHeap::heap();
GCTraceCPUTime tcpu(g1h->concurrent_mark()->gc_tracer_cm());

// GCTraceTime(...) only supports sub-phases, so a more verbose version
// is needed when we report the top-level pause phase.
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/psParallelCompact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
Threads::number_of_non_daemon_threads());
ParallelScavengeHeap::heap()->workers().update_active_workers(active_workers);

GCTraceCPUTime tcpu;
GCTraceCPUTime tcpu(&_gc_tracer);
GCTraceTime(Info, gc) tm("Pause Full", NULL, gc_cause, true);

heap->pre_full_gc_dump(&_gc_timer);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/psScavenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bool PSScavenge::invoke_no_policy() {
{
ResourceMark rm;

GCTraceCPUTime tcpu;
GCTraceCPUTime tcpu(&_gc_tracer);
GCTraceTime(Info, gc) tm("Pause Young", NULL, gc_cause, true);
TraceCollectorStats tcs(counters());
TraceMemoryManagerStats tms(heap->young_gc_manager(), gc_cause, "end of minor GC");
Expand Down
17 changes: 9 additions & 8 deletions src/hotspot/share/gc/serial/defNewGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ DefNewGeneration::DefNewGeneration(ReservedSpace rs,
_pretenure_size_threshold_words = PretenureSizeThreshold >> LogHeapWordSize;

_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();

_gc_tracer = new (ResourceObj::C_HEAP, mtGC) DefNewTracer();
}

void DefNewGeneration::compute_space_boundaries(uintx minimum_eden_size,
Expand Down Expand Up @@ -531,8 +533,7 @@ void DefNewGeneration::collect(bool full,
SerialHeap* heap = SerialHeap::heap();

_gc_timer->register_gc_start();
DefNewTracer gc_tracer;
gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer->gc_start());
_gc_tracer->report_gc_start(heap->gc_cause(), _gc_timer->gc_start());

_old_gen = heap->old_gen();

Expand All @@ -550,7 +551,7 @@ void DefNewGeneration::collect(bool full,

GCTraceTime(Trace, gc, phases) tm("DefNew", NULL, heap->gc_cause());

heap->trace_heap_before_gc(&gc_tracer);
heap->trace_heap_before_gc(_gc_tracer);

// These can be shared for all code paths
IsAliveClosure is_alive(this);
Expand Down Expand Up @@ -594,8 +595,8 @@ void DefNewGeneration::collect(bool full,
ReferenceProcessorPhaseTimes pt(_gc_timer, rp->max_num_queues());
SerialGCRefProcProxyTask task(is_alive, keep_alive, evacuate_followers);
const ReferenceProcessorStats& stats = rp->process_discovered_references(task, pt);
gc_tracer.report_gc_reference_stats(stats);
gc_tracer.report_tenuring_threshold(tenuring_threshold());
_gc_tracer->report_gc_reference_stats(stats);
_gc_tracer->report_tenuring_threshold(tenuring_threshold());
pt.print_all_references();

assert(heap->no_allocs_since_save_marks(), "save marks have not been newly set.");
Expand Down Expand Up @@ -647,19 +648,19 @@ void DefNewGeneration::collect(bool full,

// Inform the next generation that a promotion failure occurred.
_old_gen->promotion_failure_occurred();
gc_tracer.report_promotion_failed(_promotion_failed_info);
_gc_tracer->report_promotion_failed(_promotion_failed_info);

// Reset the PromotionFailureALot counters.
NOT_PRODUCT(heap->reset_promotion_should_fail();)
}
// We should have processed and cleared all the preserved marks.
_preserved_marks_set.reclaim();

heap->trace_heap_after_gc(&gc_tracer);
heap->trace_heap_after_gc(_gc_tracer);

_gc_timer->register_gc_end();

gc_tracer.report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());
_gc_tracer->report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());
}

void DefNewGeneration::init_assuming_no_promotion_failure() {
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/gc/serial/defNewGeneration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ContiguousSpace;
class CSpaceCounters;
class DefNewYoungerGenClosure;
class DefNewScanClosure;
class DefNewTracer;
class ScanWeakRefClosure;
class SerialHeap;
class STWGCTimer;
Expand Down Expand Up @@ -139,6 +140,8 @@ class DefNewGeneration: public Generation {

STWGCTimer* _gc_timer;

DefNewTracer* _gc_tracer;

enum SomeProtectedConstants {
// Generations are GenGrain-aligned and have size that are multiples of
// GenGrain.
Expand Down Expand Up @@ -330,6 +333,8 @@ class DefNewGeneration: public Generation {
return _promo_failure_scan_stack.is_empty();
}

DefNewTracer* gc_tracer() const { return _gc_tracer; }

protected:
// If clear_space is true, clear the survivor spaces. Eden is
// cleared if the minimum size of eden is 0. If mangle_space
Expand Down
10 changes: 9 additions & 1 deletion src/hotspot/share/gc/shared/gcTrace.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,6 +37,10 @@
#include "utilities/macros.hpp"
#include "utilities/ticks.hpp"

bool GCTracer::should_report_cpu_time_event() const {
return should_send_cpu_time_event();
}

void GCTracer::report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp) {
_shared_gc_info.set_cause(cause);
_shared_gc_info.set_start_timestamp(timestamp);
Expand All @@ -59,6 +63,10 @@ void GCTracer::report_gc_end(const Ticks& timestamp, TimePartitions* time_partit
report_gc_end_impl(timestamp, time_partitions);
}

void GCTracer::report_cpu_time_event(double user_time, double system_time, double real_time) const {
send_cpu_time_event(user_time, system_time, real_time);
}

void GCTracer::report_gc_reference_stats(const ReferenceProcessorStats& rps) const {
send_reference_stats_event(REF_SOFT, rps.soft_count());
send_reference_stats_event(REF_WEAK, rps.weak_count());
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/gc/shared/gcTrace.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -97,25 +97,29 @@ class GCTracer : public ResourceObj {
SharedGCInfo _shared_gc_info;

public:
bool should_report_cpu_time_event() const;
void report_gc_start(GCCause::Cause cause, const Ticks& timestamp);
void report_gc_end(const Ticks& timestamp, TimePartitions* time_partitions);
void report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
void report_metaspace_summary(GCWhen::Type when, const MetaspaceSummary& metaspace_summary) const;
void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
void report_object_count_after_gc(BoolObjectClosure* object_filter, WorkGang* workers) NOT_SERVICES_RETURN;
void report_cpu_time_event(double user_time, double system_time, double real_time) const;

protected:
GCTracer(GCName name) : _shared_gc_info(name) {}
virtual void report_gc_start_impl(GCCause::Cause cause, const Ticks& timestamp);
virtual void report_gc_end_impl(const Ticks& timestamp, TimePartitions* time_partitions);

private:
bool should_send_cpu_time_event() const;
void send_garbage_collection_event() const;
void send_gc_heap_summary_event(GCWhen::Type when, const GCHeapSummary& heap_summary) const;
void send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const;
void send_metaspace_chunk_free_list_summary(GCWhen::Type when, Metaspace::MetadataType mdtype, const MetaspaceChunkFreeListSummary& summary) const;
void send_reference_stats_event(ReferenceType type, size_t count) const;
void send_phase_events(TimePartitions* time_partitions) const;
void send_cpu_time_event(double user_time, double system_time, double real_time) const;
};

class YoungGCTracer : public GCTracer {
Expand Down
17 changes: 16 additions & 1 deletion src/hotspot/share/gc/shared/gcTraceSend.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -36,6 +36,10 @@

typedef uintptr_t TraceAddress;

bool GCTracer::should_send_cpu_time_event() const {
return EventGCCPUTime::is_enabled();
}

void GCTracer::send_garbage_collection_event() const {
EventGarbageCollection event(UNTIMED);
if (event.should_commit()) {
Expand All @@ -50,6 +54,17 @@ void GCTracer::send_garbage_collection_event() const {
}
}

void GCTracer::send_cpu_time_event(double user_time, double system_time, double real_time) const {
EventGCCPUTime e;
if (e.should_commit()) {
e.set_gcId(GCId::current());
e.set_userTime((size_t)(user_time * NANOUNITS));
e.set_systemTime((size_t)(system_time * NANOUNITS));
e.set_realTime((size_t)(real_time * NANOUNITS));
e.commit();
}
}

void GCTracer::send_reference_stats_event(ReferenceType type, size_t count) const {
EventGCReferenceStatistics e;
if (e.should_commit()) {
Expand Down
Loading

1 comment on commit 833e2bb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.