RFR: 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' [v2]
Marc Chevalier
mchevalier at openjdk.org
Tue Apr 29 16:37:02 UTC 2025
> The double `(double)count * prof_factor * method_life / counter_life + 0.5`
> can overflow a 32-bit int, causing UB on casting, but in practice computing
> a wrong scale, probably.
>
> We just need to compare that the cast is not going to overflow. This is possible
> because `INT_MAX` is exactly representable in a `double`. It is also good to
> notice that the expression `(double)count * prof_factor * method_life / counter_life + 0.5`
> cannot overflow a `double`:
> - `count` is a int, max value = 2^31-1 < 2.2e9
> - `method_lie` is a int, max value < 2.2e9
> - `prof_factor` is a float, max value < 3.5e38
> - `counter_life` is a int, positive at this point, so min value = 1
> So, the whole expression is bounded by 16.94e56 + 0.5, which is much smaller than the
> max value of a double (about 1.8e308). We probably would have precision issues, but
> it probably doesn't matter a lot.
>
> The semantic I picked here is basically `min(INT_MAX, count_d)`, so it'd always fit.
>
> Thanks,
> Marc
Marc Chevalier has updated the pull request incrementally with one additional commit since the last revision:
+comment
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/24824/files
- new: https://git.openjdk.org/jdk/pull/24824/files/b5d80813..125d9c12
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=24824&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=24824&range=00-01
Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/24824.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24824/head:pull/24824
PR: https://git.openjdk.org/jdk/pull/24824
More information about the hotspot-compiler-dev
mailing list