RFR: 8367485: os::physical_memory is broken in 32-bit JVMs when running on 64-bit OSes [v6]

Joel Sikström jsikstro at openjdk.org
Thu Sep 18 15:01:44 UTC 2025


On Thu, 18 Sep 2025 14:58: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 `uint64_t`.
>> 
>> Tested in tiers 1 - 5.
>
> Anton Artemov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8367485: Addressed reviewers' comments.

src/hotspot/share/gc/shared/gcInitLogger.cpp line 66:

> 64: void GCInitLogger::print_memory() {
> 65:   uint64_t memory = os::physical_memory();
> 66:   log_info_p(gc, init)("Memory: " UINT64_FORMAT, memory);

I don't think this is alright. We should just revert this to what it was before [JDK-8357086](https://bugs.openjdk.org/browse/JDK-8357086), with UINT64_FORMAT instead.

log_info_p(gc, init)("Memory: " UINT64_FORMAT "%s",
                     byte_size_in_proper_unit(memory), proper_unit_for_byte_size(memory));


Right now it looks like this:

[0.007s][info][gc,init] Memory: 38654705664

When it previously looked like this:

[0.023s][info][gc,init] Memory: 36864M

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27335#discussion_r2359749983


More information about the hotspot-runtime-dev mailing list