RFR: 8367485: os::physical_memory is broken in 32-bit JVMs when running on 64-bit OSes [v12]
Stefan Karlsson
stefank at openjdk.org
Thu Sep 25 09:59:12 UTC 2025
On Thu, 25 Sep 2025 09:53:32 GMT, Anton Artemov <duke at openjdk.org> wrote:
>> Hi, please consider the following changes:
>>
>> In this PR we address the overflow issue in `os::physical_memory()` on Linux, which can occur when running a 32-bit JVM on a 64-bit machine, introduced by https://bugs.openjdk.org/browse/JDK-8357086. The problem is that the product of _SC_PHYS_PAGES and _SC_PAGESIZE can overflow according to the documentation.
>>
>> The issue is addressed by changing the output type of all related functions to `physical_memory_size_type`, which is an alias to `uint64_t`.
>>
>> Tested in tiers 1 - 5.
>
> Anton Artemov has updated the pull request incrementally with two additional commits since the last revision:
>
> - 8367485: Fixed whitespace error.
> - 8367485: Added print formar for mem funcs vals.
src/hotspot/share/utilities/globalDefinitions.hpp line 421:
> 419: typedef unsigned int uint; NEEDS_CLEANUP
> 420:
> 421: //----------------------------------------------------------------------------------------------------
If you look at the file there's a bunch of sections starting with dashes. I don't think you need a new section for a single typedef
Suggestion:
src/hotspot/share/utilities/globalDefinitions.hpp line 422:
> 420:
> 421: //----------------------------------------------------------------------------------------------------
> 422: // Type defenition for memory functions
There's a typo here defenition > definition. With that said, this comment mimics the comments for the sections above and below:
// VM type definitions
// Java type definitions
but we don't need a new section, so I think we should not follow those patterns. Instead it would be good to have a motivation for having this typedef. Something that explains that the amount of physical memory doesn't necessarily fit in a 32-bit size_t for 32-bit JVMs and that we have this typedef to mark the places where we have to deal with that quirk as long as we support 32-bit JVMs.
src/hotspot/share/utilities/globalDefinitions.hpp line 423:
> 421: //----------------------------------------------------------------------------------------------------
> 422: // Type defenition for memory functions
> 423: typedef uint64_t physical_memory_size_type;
When adding code make sure have a blank line between the new code and the surrounding code.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27335#discussion_r2378484837
PR Review Comment: https://git.openjdk.org/jdk/pull/27335#discussion_r2378501102
PR Review Comment: https://git.openjdk.org/jdk/pull/27335#discussion_r2378474586
More information about the hotspot-dev
mailing list