RFR: 8357086: os::xxx functions returning memory size should return size_t [v4]
Anton Artemov
duke at openjdk.org
Thu Jun 12 08:05:29 UTC 2025
On Wed, 11 Jun 2025 17:04:39 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> Hmm. Maybe I'm reading this wrong, but to me it looks like you can return -2 via this code:
Yes, you are correct that **that** code can return -2 in some cases. But we need to see where this code returns this value and if it is propagated further. I found only two places in os_linux.cpp where this value can be seen:
1) In `os::total_swap_space()`, but there is a check for non-negativity `if (OSContainer::memory_limit_in_bytes() > 0)`, which would be false in case `OSCONTAINER_ERROR` is returned, because under the hood `memory_limit_in_bytes()` uses same methods as you described. So value -2 will never be propagated outside of `os::total_swap_space()`.
2) In `os::free_swap_space()`, here both `mem_swap_limit `and `mem_limit `can be set to -2, but then there is a check `if (mem_swap_limit >= 0 && mem_limit >= 0)`, which would be false if -2 is in any of that variables. If so `host_free_swap_val` is returned, which has values >= -1.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25450#issuecomment-2965559885
More information about the hotspot-dev
mailing list