From 51347fc12d63e252f2fd97530827b0a9f251a361 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Tue, 25 Feb 2025 11:35:28 +0100 Subject: [PATCH] 8350643 Hi all, in the G1SurvRateGroup class there are three loops that use a `size_t` loop iteration variable that is compared to `uint`s in the condition, causing some implicit narrowing. Change the loop variables to also use `uints`. Pointed out by @kimbarrett during review of JDK-8349906. Testing: local compilation, github testing, checking other loop variables to match type Thanks, Thomas --- src/hotspot/share/gc/g1/g1SurvRateGroup.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1SurvRateGroup.cpp b/src/hotspot/share/gc/g1/g1SurvRateGroup.cpp index 1eaaf44a1fbde..c01c76856e4fe 100644 --- a/src/hotspot/share/gc/g1/g1SurvRateGroup.cpp +++ b/src/hotspot/share/gc/g1/g1SurvRateGroup.cpp @@ -46,7 +46,7 @@ void G1SurvRateGroup::reset() { // The call to stop_adding_regions() will use "new" to refill // the _surv_rate_pred array, so we need to make sure to call // "delete". - for (size_t i = 0; i < _stats_arrays_length; ++i) { + for (uint i = 0; i < _stats_arrays_length; ++i) { delete _surv_rate_predictors[i]; } _stats_arrays_length = 0; @@ -68,7 +68,7 @@ void G1SurvRateGroup::stop_adding_regions() { _accum_surv_rate_pred = REALLOC_C_HEAP_ARRAY(double, _accum_surv_rate_pred, _num_added_regions, mtGC); _surv_rate_predictors = REALLOC_C_HEAP_ARRAY(TruncatedSeq*, _surv_rate_predictors, _num_added_regions, mtGC); - for (size_t i = _stats_arrays_length; i < _num_added_regions; ++i) { + for (uint i = _stats_arrays_length; i < _num_added_regions; ++i) { // Initialize predictors and accumulated survivor rate predictions. _surv_rate_predictors[i] = new TruncatedSeq(10); _surv_rate_predictors[i]->add(InitialSurvivorRate); @@ -110,7 +110,7 @@ double G1SurvRateGroup::accum_surv_rate_pred(uint age) const { void G1SurvRateGroup::fill_in_last_surv_rates() { if (_num_added_regions > 0) { // conservative double surv_rate = _surv_rate_predictors[_num_added_regions-1]->last(); - for (size_t i = _num_added_regions; i < _stats_arrays_length; ++i) { + for (uint i = _num_added_regions; i < _stats_arrays_length; ++i) { _surv_rate_predictors[i]->add(surv_rate); } } @@ -119,7 +119,7 @@ void G1SurvRateGroup::fill_in_last_surv_rates() { void G1SurvRateGroup::finalize_predictions(const G1Predictions& predictor) { double accum = 0.0; double pred = 0.0; - for (size_t i = 0; i < _stats_arrays_length; ++i) { + for (uint i = 0; i < _stats_arrays_length; ++i) { pred = predictor.predict_in_unit_interval(_surv_rate_predictors[i]); accum += pred; _accum_surv_rate_pred[i] = accum;