RFR: 8357086: os::xxx functions returning memory size should return size_t [v13]
Kim Barrett
kbarrett at openjdk.org
Tue Jul 29 01:44:45 UTC 2025
On Fri, 27 Jun 2025 07:30:26 GMT, Anton Artemov <duke at openjdk.org> wrote:
>> Hi,
>>
>> in this PR the output value types for functions which return memory are changed, namely:
>>
>>
>> static julong available_memory(); --> static bool available_memory(size_t& value);
>> static julong used_memory(); --> static bool used_memory(size_t& value);
>> static julong free_memory(); --> static bool free_memory(size_t& value);
>> static jlong total_swap_space(); --> static bool total_swap_space(size_t& value);
>> static jlong free_swap_space(); --> static bool free_swap_space(size_t& value);
>> static julong physical_memory(); --> static bool physical_memory(size_t& value);
>>
>>
>> The return boolean value indicates success, whereas the actual value is assigned to the input argument. The following recommended usage pattern is introduced: where applicable, and unsuccessful call is logged.
>>
>> Later, the return value can be attributed with `[[nodiscard]]` to enforce the pattern.
>>
>> Tested in GHA and Tiers 1-5.
>
> Anton Artemov has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 12 commits:
>
> - 8357086: Fxied return value
> - 8357086: Fixed whitespaces
> - 8357086: Introduced usage pattern
> - 8357086: Fixed typo
> - 8357086: Refactored physical_memory in different OS
> - 8357086: Small fixes 2
> - 8357086: Small fixes 1.
> - 8357086: Refactored physical_memory()
> - 8357086: Refactored free_swap_space()
> - 8357086: Refactored total_swap_space()
> - ... and 2 more: https://git.openjdk.org/jdk/compare/75ce44aa...e4698333
Maybe we should have an `ATTRIBUTE_NODISCARD` macro with an always empty
definition, and add it to all the functions being changed? Otherwise, once
`[[nodiscard]]` becomes available, someone is going to have to hunt down all
the relevant functions. Once we have C++17 we can revisit. It might take some
preliminary call-site fixes before we can change the macro (or more likely,
remove it and just use `[[nodiscard]]` directly).
@toxaart - Before you do anything about that, what do other reviewers think?
-------------
PR Review: https://git.openjdk.org/jdk/pull/25450#pullrequestreview-3064900011
More information about the hotspot-dev
mailing list