33
33
#include " gc/z/zStat.hpp"
34
34
#include " logging/log.hpp"
35
35
36
+ #include < limits>
37
+
36
38
ZDirector* ZDirector::_director;
37
39
38
40
constexpr double one_in_1000 = 3.290527 ;
@@ -453,16 +455,22 @@ static double calculate_extra_young_gc_time(const ZDirectorStats& stats) {
453
455
// relocation headroom into account to avoid in-place relocation.
454
456
const size_t old_used = stats._old_stats ._general ._used ;
455
457
const size_t old_live = stats._old_stats ._stat_heap ._live_at_mark_end ;
456
- const size_t old_garbage = old_used - old_live;
458
+ const double old_garbage = double ( old_used - old_live) ;
457
459
458
460
const double young_gc_time = gc_time (stats._young_stats );
459
461
460
462
// Calculate how much memory young collections are predicted to free.
461
- const size_t reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
463
+ const double reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
462
464
463
465
// Calculate current YC time and predicted YC time after an old collection.
464
- const double current_young_gc_time_per_bytes_freed = double (young_gc_time) / double (reclaimed_per_young_gc);
465
- const double potential_young_gc_time_per_bytes_freed = double (young_gc_time) / double (reclaimed_per_young_gc + old_garbage);
466
+ const double current_young_gc_time_per_bytes_freed = young_gc_time / reclaimed_per_young_gc;
467
+ const double potential_young_gc_time_per_bytes_freed = young_gc_time / (reclaimed_per_young_gc + old_garbage);
468
+
469
+ if (current_young_gc_time_per_bytes_freed == std::numeric_limits<double >::infinity ()) {
470
+ // Young collection's are not reclaiming any memory. Return infinity as a signal
471
+ // to trigger an old collection, regardless of the amount of old garbage.
472
+ return std::numeric_limits<double >::infinity ();
473
+ }
466
474
467
475
// Calculate extra time per young collection inflicted by *not* doing an
468
476
// old collection that frees up memory in the old generation.
@@ -483,13 +491,12 @@ static bool rule_major_allocation_rate(const ZDirectorStats& stats) {
483
491
const double young_gc_time = gc_time (stats._young_stats );
484
492
485
493
// Calculate how much memory collections are predicted to free.
486
- const size_t reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
487
- const size_t reclaimed_per_old_gc = stats._old_stats ._stat_heap ._reclaimed_avg ;
494
+ const double reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
495
+ const double reclaimed_per_old_gc = stats._old_stats ._stat_heap ._reclaimed_avg ;
488
496
489
497
// Calculate the GC cost for each reclaimed byte
490
- const double current_young_gc_time_per_bytes_freed = double (young_gc_time) / double (reclaimed_per_young_gc);
491
- const double current_old_gc_time_per_bytes_freed = reclaimed_per_old_gc == 0 ? std::numeric_limits<double >::infinity ()
492
- : (double (old_gc_time) / double (reclaimed_per_old_gc));
498
+ const double current_young_gc_time_per_bytes_freed = young_gc_time / reclaimed_per_young_gc;
499
+ const double current_old_gc_time_per_bytes_freed = old_gc_time / reclaimed_per_old_gc;
493
500
494
501
// Calculate extra time per young collection inflicted by *not* doing an
495
502
// old collection that frees up memory in the old generation.
@@ -531,10 +538,10 @@ static double calculate_young_to_old_worker_ratio(const ZDirectorStats& stats) {
531
538
532
539
const double young_gc_time = gc_time (stats._young_stats );
533
540
const double old_gc_time = gc_time (stats._old_stats );
534
- const size_t reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
535
- const size_t reclaimed_per_old_gc = stats._old_stats ._stat_heap ._reclaimed_avg ;
536
- const double current_young_bytes_freed_per_gc_time = double ( reclaimed_per_young_gc) / double ( young_gc_time) ;
537
- const double current_old_bytes_freed_per_gc_time = double ( reclaimed_per_old_gc) / double ( old_gc_time) ;
541
+ const double reclaimed_per_young_gc = stats._young_stats ._stat_heap ._reclaimed_avg ;
542
+ const double reclaimed_per_old_gc = stats._old_stats ._stat_heap ._reclaimed_avg ;
543
+ const double current_young_bytes_freed_per_gc_time = reclaimed_per_young_gc / young_gc_time;
544
+ const double current_old_bytes_freed_per_gc_time = reclaimed_per_old_gc / old_gc_time;
538
545
539
546
if (current_young_bytes_freed_per_gc_time == 0.0 ) {
540
547
if (current_old_bytes_freed_per_gc_time == 0.0 ) {
0 commit comments