@@ -306,8 +306,7 @@ static bool is_young_small(const ZDirectorStats& stats) {
306
306
return young_used_percent <= 5.0 ;
307
307
}
308
308
309
- template <typename PrintFn = void (*)(size_t , double )>
310
- static bool is_high_usage (const ZDirectorStats& stats, PrintFn* print_function = nullptr ) {
309
+ static bool is_high_usage (const ZDirectorStats& stats, bool log = false ) {
311
310
// Calculate amount of free memory available. Note that we take the
312
311
// relocation headroom into account to avoid in-place relocation.
313
312
const size_t soft_max_capacity = stats._heap ._soft_max_heap_size ;
@@ -316,8 +315,9 @@ static bool is_high_usage(const ZDirectorStats& stats, PrintFn* print_function =
316
315
const size_t free = free_including_headroom - MIN2 (free_including_headroom, ZHeuristics::relocation_headroom ());
317
316
const double free_percent = percent_of (free, soft_max_capacity);
318
317
319
- if (print_function != nullptr ) {
320
- (*print_function)(free, free_percent);
318
+ if (log) {
319
+ log_debug (gc, director)(" Rule Minor: High Usage, Free: %zuMB(%.1f%%)" ,
320
+ free / M, free_percent);
321
321
}
322
322
323
323
// The heap has high usage if there is less than 5% free memory left
@@ -377,19 +377,7 @@ static bool rule_minor_high_usage(const ZDirectorStats& stats) {
377
377
// such that the allocation rate rule doesn't trigger, but the amount of free
378
378
// memory is still slowly but surely heading towards zero. In this situation,
379
379
// we start a GC cycle to avoid a potential allocation stall later.
380
-
381
- const size_t soft_max_capacity = stats._heap ._soft_max_heap_size ;
382
- const size_t used = stats._heap ._used ;
383
- const size_t free_including_headroom = soft_max_capacity - MIN2 (soft_max_capacity, used);
384
- const size_t free = free_including_headroom - MIN2 (free_including_headroom, ZHeuristics::relocation_headroom ());
385
- const double free_percent = percent_of (free, soft_max_capacity);
386
-
387
- auto print_function = [&](size_t free, double free_percent) {
388
- log_debug (gc, director)(" Rule Minor: High Usage, Free: %zuMB(%.1f%%)" ,
389
- free / M, free_percent);
390
- };
391
-
392
- return is_high_usage (stats, &print_function);
380
+ return is_high_usage (stats, true /* log */ );
393
381
}
394
382
395
383
// Major GC rules
0 commit comments