RFR: 8368089: G1: G1PeriodicGCTask::should_start_periodic_gc may use uninitialised value if os::loadavg is unsupported [v4]

Guanqiang Han ghan at openjdk.org
Wed Sep 24 14:58:06 UTC 2025


On Wed, 24 Sep 2025 14:00:28 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

>> Guanqiang Han has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Update g1PeriodicGCTask.cpp
>>   
>>   fix a small error
>
> src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp line 67:
> 
>> 65:                               recent_load, G1PeriodicGCSystemLoadThreshold);
>> 66:       return false;
>> 67:     }
> 
> Suggestion:
> 
>   if (G1PeriodicGCSystemLoadThreshold > 0.0) {
>     if (os::loadavg(&recent_load, 1) == -1) {
>       G1PeriodicGCSystemLoadThreshold = 0.0;
>       log_warning(gc, periodic)("System loadavg() call failed, disabling G1PeriodicGCSystemLoadThreshold check.");
>       // Fall through and start the periodic GC.
>     } else if (recent_load > G1PeriodicGCSystemLoadThreshold) {
>       log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.",
>                               recent_load, G1PeriodicGCSystemLoadThreshold);
>       return false;
>     }
> 
> 
> After detecting that `loadavg` is not supported, it would be preferable (more consistent) imo that the periodic gc would be started the first time too.
> Another option is to check `loadavg` support by a dummy call in argument processing, but here is good too.
> 
> As for the other change, I would prefer to have the "disabling" in active voice, making it clear that this code disables the check.

@tschatzl  Indeed, that’s more consistent. Thank you — fixed now.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27413#discussion_r2376085019


More information about the hotspot-gc-dev mailing list