RFR: 8336911: ZGC: Division by zero in heuristics after JDK-8332717

Axel Boldt-Christmas aboldtch at openjdk.org
Wed Oct 9 11:47:04 UTC 2024


On Fri, 4 Oct 2024 07:33:06 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> src/hotspot/share/gc/z/zDirector.cpp line 539:
>> 
>>> 537:   const double current_old_bytes_freed_per_gc_time = double(reclaimed_per_old_gc) / double(old_gc_time);
>>> 538:   const double old_vs_young_efficiency_ratio = current_young_bytes_freed_per_gc_time == 0 ? std::numeric_limits<double>::infinity()
>>> 539:                                                                                           : current_old_bytes_freed_per_gc_time / current_young_bytes_freed_per_gc_time;
>> 
>> I think returning infinity here will cause problems with NaN down the line. It is also unclear what this means if both are `0`. To me something like the following makes sense. But I will discus this with my team.
>> Suggestion:
>> 
>> 
>>   if (current_young_bytes_freed_per_gc_time == 0.0) {
>>     if (current_old_bytes_freed_per_gc_time == 0.0) {
>>       // Neither young nor old collections have reclaimed any memory.
>>       // Give them equal priority.
>>       return 1.0;
>>     }
>> 
>>     // Only old collections have reclaimed memory.
>>     // Prioritize old.
>>     return ZOldGCThreads;
>>   }
>> 
>>   const double old_vs_young_efficiency_ratio = current_old_bytes_freed_per_gc_time / current_young_bytes_freed_per_gc_time;
>
> Hi Axel, thanks for the suggestion.
> Please discuss it in your team and tell me the outcome :-) !

I think you can go ahead and use my proposed change. And I will review it. 

@fisk, who has the most familiarity with the heuristics code, is currently on vacation. So we should wait until he is back and let him review this as well.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21304#discussion_r1793369646


More information about the hotspot-gc-dev mailing list