2828#include " gc/shared/gc_globals.hpp"
2929#include " runtime/globals.hpp"
3030#include " runtime/os.hpp"
31+ #include " services/cpuTimeUsage.hpp"
3132#include " utilities/debug.hpp"
3233#include " utilities/globalDefinitions.hpp"
3334#include " utilities/numberSeq.hpp"
@@ -73,6 +74,8 @@ G1Analytics::G1Analytics(const G1Predictions* predictor) :
7374 _concurrent_mark_cleanup_times_ms(NumPrevPausesForHeuristics),
7475 _alloc_rate_ms_seq(TruncatedSeqLength),
7576 _prev_collection_pause_end_ms(0.0 ),
77+ _gc_cpu_time_at_pause_end_ms(),
78+ _concurrent_gc_cpu_time_ms(),
7679 _concurrent_refine_rate_ms_seq(TruncatedSeqLength),
7780 _dirtied_cards_rate_ms_seq(TruncatedSeqLength),
7881 _dirtied_cards_in_thread_buffers_seq(TruncatedSeqLength),
@@ -88,8 +91,8 @@ G1Analytics::G1Analytics(const G1Predictions* predictor) :
8891 _young_other_cost_per_region_ms_seq(TruncatedSeqLength),
8992 _non_young_other_cost_per_region_ms_seq(TruncatedSeqLength),
9093 _recent_prev_end_times_for_all_gcs_sec(NumPrevPausesForHeuristics),
91- _long_term_pause_time_ratio (0.0 ),
92- _short_term_pause_time_ratio (0.0 ) {
94+ _long_term_gc_time_ratio (0.0 ),
95+ _short_term_gc_time_ratio (0.0 ) {
9396
9497 // Seed sequences with initial values.
9598 _recent_prev_end_times_for_all_gcs_sec.add (os::elapsedTime ());
@@ -149,6 +152,10 @@ int G1Analytics::num_alloc_rate_ms() const {
149152 return _alloc_rate_ms_seq.num ();
150153}
151154
155+ double G1Analytics::gc_cpu_time_ms () const {
156+ return (double )CPUTimeUsage::GC::gc_threads () / NANOSECS_PER_MILLISEC;
157+ }
158+
152159void G1Analytics::report_concurrent_mark_remark_times_ms (double ms) {
153160 _concurrent_mark_remark_times_ms.add (ms);
154161}
@@ -157,15 +164,27 @@ void G1Analytics::report_alloc_rate_ms(double alloc_rate) {
157164 _alloc_rate_ms_seq.add (alloc_rate);
158165}
159166
160- void G1Analytics::compute_pause_time_ratios (double end_time_sec, double pause_time_ms) {
167+ void G1Analytics::update_gc_time_ratios (double end_time_sec, double pause_time_ms) {
168+ // This estimates the wall-clock time "lost" by application mutator threads due to concurrent GC
169+ // activity. We do not account for contention on other shared resources such as memory bandwidth and
170+ // caches, therefore underestimate the impact of the concurrent GC activity on mutator threads.
171+ uint num_cpus = (uint)os::active_processor_count ();
172+ double concurrent_gc_impact_time = _concurrent_gc_cpu_time_ms / num_cpus;
173+
174+ double gc_time_ms = pause_time_ms + concurrent_gc_impact_time;
175+
161176 double long_interval_ms = (end_time_sec - oldest_known_gc_end_time_sec ()) * 1000.0 ;
162- double gc_pause_time_ms = _recent_gc_times_ms.sum () - _recent_gc_times_ms.oldest () + pause_time_ms;
163- _long_term_pause_time_ratio = gc_pause_time_ms / long_interval_ms;
164- _long_term_pause_time_ratio = clamp (_long_term_pause_time_ratio, 0.0 , 1.0 );
177+ double long_term_gc_time_ms = _recent_gc_times_ms.sum () - _recent_gc_times_ms.oldest () + gc_time_ms;
178+
179+ _long_term_gc_time_ratio = long_term_gc_time_ms / long_interval_ms;
180+ _long_term_gc_time_ratio = clamp (_long_term_gc_time_ratio, 0.0 , 1.0 );
165181
166182 double short_interval_ms = (end_time_sec - most_recent_gc_end_time_sec ()) * 1000.0 ;
167- _short_term_pause_time_ratio = pause_time_ms / short_interval_ms;
168- _short_term_pause_time_ratio = clamp (_short_term_pause_time_ratio, 0.0 , 1.0 );
183+
184+ _short_term_gc_time_ratio = gc_time_ms / short_interval_ms;
185+ _short_term_gc_time_ratio = clamp (_short_term_gc_time_ratio, 0.0 , 1.0 );
186+
187+ update_recent_gc_times (end_time_sec, gc_time_ms);
169188}
170189
171190void G1Analytics::report_concurrent_refine_rate_ms (double cards_per_ms) {
@@ -305,8 +324,8 @@ double G1Analytics::most_recent_gc_end_time_sec() const {
305324}
306325
307326void G1Analytics::update_recent_gc_times (double end_time_sec,
308- double pause_time_ms ) {
309- _recent_gc_times_ms.add (pause_time_ms );
327+ double gc_time_ms ) {
328+ _recent_gc_times_ms.add (gc_time_ms );
310329 _recent_prev_end_times_for_all_gcs_sec.add (end_time_sec);
311330}
312331
0 commit comments