From d802fd0da234275c79b67f74f2cfb15fbe18d7b9 Mon Sep 17 00:00:00 2001 From: Marc Chevalier Date: Wed, 30 Apr 2025 08:45:54 +0000 Subject: [PATCH] 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 --- src/hotspot/share/ci/ciMethod.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/ci/ciMethod.cpp b/src/hotspot/share/ci/ciMethod.cpp index 3b2670c3eb0..6b6f1b6f0a8 100644 --- a/src/hotspot/share/ci/ciMethod.cpp +++ b/src/hotspot/share/ci/ciMethod.cpp @@ -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(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; }