RFR: 8367485: os::physical_memory is broken in 32-bit JVMs when running on 64-bit OSes [v13]
Joel Sikström
jsikstro at openjdk.org
Thu Sep 25 14:58:38 UTC 2025
On Thu, 25 Sep 2025 10:24:24 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 new line after typedef.
> - 8367485: Fixed comment in global definitions.
I'm not a huge fan of the verbosity the long typename brings with it but I think this is a good compromise.
src/hotspot/share/utilities/globalDefinitions.hpp line 423:
> 421: // This typedef is to address the issue of running a 32-bit VM on a 64-bit platform. In this case
> 422: // the amount of physical memory may not fit in size_t, so we have to have a larger type. Once 32-bit
> 423: // is depricated, one can use size_t.
It's not only 32-bit VM on a 64-bit platform, it's 32-bit VM in general, since we can have an issue on both: 1) a 64-bit platform, and 2) a 32-bit (ARM) platform with LPAE enabled.
-------------
Marked as reviewed by jsikstro (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/27335#pullrequestreview-3268169759
PR Review Comment: https://git.openjdk.org/jdk/pull/27335#discussion_r2379430634
More information about the hotspot-dev
mailing list