3333#include " gc/z/zStat.hpp"
3434#include " logging/log.hpp"
3535
36+ #include < limits>
37+
3638ZDirector* ZDirector::_director;
3739
3840constexpr double one_in_1000 = 3.290527 ;
@@ -453,16 +455,22 @@ static double calculate_extra_young_gc_time(const ZDirectorStats& stats) {
453455 // relocation headroom into account to avoid in-place relocation.
454456 const size_t old_used = stats._old_stats ._general ._used ;
455457 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) ;
457459
458460 const double young_gc_time = gc_time (stats._young_stats );
459461
460462 // 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 ;
462464
463465 // 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+ }
466474
467475 // Calculate extra time per young collection inflicted by *not* doing an
468476 // old collection that frees up memory in the old generation.
@@ -483,13 +491,12 @@ static bool rule_major_allocation_rate(const ZDirectorStats& stats) {
483491 const double young_gc_time = gc_time (stats._young_stats );
484492
485493 // 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 ;
488496
489497 // 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;
493500
494501 // Calculate extra time per young collection inflicted by *not* doing an
495502 // 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) {
531538
532539 const double young_gc_time = gc_time (stats._young_stats );
533540 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;
538545
539546 if (current_young_bytes_freed_per_gc_time == 0.0 ) {
540547 if (current_old_bytes_freed_per_gc_time == 0.0 ) {
0 commit comments