8352422: [ubsan] Out-of-range reported in ciMethod.cpp:917:20: runtime error: 2.68435e+09 is outside the range of representable values of type 'int'

Reviewed-by: epeter, dlong
This commit is contained in:
Marc Chevalier 2025-04-30 08:45:54 +00:00 committed by Emanuel Peter
parent 7d9a43839a
commit d802fd0da2

View File

@ -914,8 +914,14 @@ int ciMethod::scale_count(int count, float prof_factor) {
method_life = counter_life;
}
if (counter_life > 0) {
count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);
count = (count > 0) ? count : 1;
double count_d = (double)count * prof_factor * method_life / counter_life + 0.5;
if (count_d >= static_cast<double>(INT_MAX)) {
// Clamp in case of overflowing int range.
count = INT_MAX;
} else {
count = int(count_d);
count = (count > 0) ? count : 1;
}
} else {
count = 1;
}