RFR: 8357086: os::xxx functions returning memory size should return size_t [v13]

Stefan Karlsson stefank at openjdk.org
Wed Jul 30 14:35:59 UTC 2025


On Wed, 30 Jul 2025 14:16:16 GMT, Anton Artemov <duke at openjdk.org> wrote:

>> src/hotspot/share/compiler/compileBroker.cpp line 1062:
>> 
>>> 1060:   // Now, we do the more expensive operations.
>>> 1061:   size_t free_memory = 0;
>>> 1062:   os::free_memory(free_memory);
>> 
>> I wonder if this should be changed to something like this:
>> Suggestion:
>> 
>>   // Return value ignored - defaulting to 0 on failure.
>>   (void)os::free_memory(free_memory);
>> 
>> to clearly indicate the intent to skip the error check?
>
> This is a valid point, but then we'll need to address it somehow else once a pattern with `[[nodiscard]]` or enum class return value is introduced. Or, simply add an empty clause for failure. For now, I will just put a comment there as suggested.

Note that the main point here was the cast to (void) used to indicate that the return value is explicitly discarded. Does that not work with the [[nodiscard]]?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25450#discussion_r2242915387


More information about the hotspot-dev mailing list