RFR: 8367485: os::physical_memory is broken in 32-bit JVMs when running on 64-bit OSes
Anton Artemov
duke at openjdk.org
Wed Sep 17 09:55:20 UTC 2025
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 checking if the product (represented as `uint64_t`) exceeds the maximum value representable by `size_t`, and, if so `std::numeric_limits<size_t>::max()` is returned as physical memory. If there is no overflow detected, the product of _SC_PHYS_PAGES and _SC_PAGESIZE is returned.
Note that this change does not roll back to the old behavior (pre https://bugs.openjdk.org/browse/JDK-8357086). We keep consistency among memory functions return types.
Tested in tiers 1 - 3.
-------------
Commit messages:
- 8367485: Whitespace fix.
- 8367485: Fixed overflow issue in os::physical_memory on Linux.
Changes: https://git.openjdk.org/jdk/pull/27335/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27335&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8367485
Stats: 8 lines in 1 file changed: 7 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/27335.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/27335/head:pull/27335
PR: https://git.openjdk.org/jdk/pull/27335
More information about the hotspot-runtime-dev
mailing list