RFR: 8353468: [ubsan] arguments.cpp:2422:23: runtime error: 2.14748e+11 is outside the range of representable values of type 'int' [v2]
Stefan Karlsson
stefank at openjdk.org
Tue Aug 26 09:43:34 UTC 2025
On Thu, 21 Aug 2025 09:49:09 GMT, Afshin Zafari <azafari at openjdk.org> wrote:
>> In converting values of `-XMinf` and `-XMaxf` options to `int`, overflow was not checked.
>> The values are checked against INT_MAX and clamped.
>>
>> Tests: tiers 1-5.
>
> Afshin Zafari has updated the pull request incrementally with one additional commit since the last revision:
>
> negative underflow checked.
I was looking and I'm starting to have some doubts about this surrounding code.
If I run with the following command line (before the proposed changes):
$ ~/java/jdk-21/bin/java -Xminf5 -version
uintx MinHeapFreeRatio=500 is outside the allowed range [ 0 ... 100 ]
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
So, this indicate that the user should not specify a percentage when setting -Xminf. The user should be setting a value that is a 100th of the percentage they want to use. So, this sounds like a ratio? The code then takes the ratio value and multiplies with 100 (so that it gets a percentage) and then passes it into a flag called MinHeapFreeRatio! Fine, that flag is weirdly named, but see what happens in the next command line:
$ ~/java/jdk-21/bin/java -Xminf=5 -version
Bad min heap free percentage size: -Xminf=5
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
The error handling code talks about the format of -Xminf and complains that it isn't a percentage. But it shouldn't be a percentage it should be a ratio (that afterwards gets multiplied by 100 to get a percentage). So, the error message is wrong.
Note also that today and I guess with this PR we get this weird output if you specify a negative value:
$ java -Xminf-5 -version
uintx MinHeapFreeRatio=18446744073709551116 is outside the allowed range [ 0 ... 100 ]
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Here the user gets a `18446744073709551116` reported even though that's not what the user specified on the command line.
I wonder if it wouldn't be better if we take care of checking that -Xminf and -Xmaxf is within [0.0, 1.0] and error out if it is not. And do all that before we even try to set Min/MaxHeapFreeRatio, so that we don't get error messages that isn't obvious how it correlates with the user's input.
I'd prefer to solve this bug as part of a cleanup like this, but I'm also fine with checking in what you have here and taking care of this as a follow-up PR.
-------------
PR Review: https://git.openjdk.org/jdk/pull/26859#pullrequestreview-3154834118
More information about the hotspot-runtime-dev
mailing list