From 52e550462798c568a8a5457af2f9554fd784cd8a Mon Sep 17 00:00:00 2001 From: Guanqiang Han Date: Thu, 25 Sep 2025 11:55:18 +0000 Subject: [PATCH] 8368089: G1: G1PeriodicGCTask::should_start_periodic_gc may use uninitialised value if os::loadavg is unsupported Reviewed-by: ayang, tschatzl, iwalulya --- src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp b/src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp index afbd0f35ce6..0a7367fcab5 100644 --- a/src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp +++ b/src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp @@ -54,11 +54,17 @@ bool G1PeriodicGCTask::should_start_periodic_gc(G1CollectedHeap* g1h, // Check if load is lower than max. double recent_load; - if ((G1PeriodicGCSystemLoadThreshold > 0.0f) && - (os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) { - log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.", - recent_load, G1PeriodicGCSystemLoadThreshold); - return false; + 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; + } } // Record counters with GC safepoints blocked, to get a consistent snapshot.