RFR: JDK-8326067: Remove os::remap_memory and simplify os::map_memory
Thomas Stuefe
stuefe at openjdk.org
Sat Feb 17 11:43:05 UTC 2024
We have `os::map_memory()` and `os::remap_memory()`.
`os::map_memory()` maps a file, using mmap() on POSIX, `MapViewOfFile()` on Windows.
Note: the fact that `mmap()` is used on POSIX can be considered as given since the way these APIs are formed (e.g., exposing `munmap()` via address range) makes them incompatible with System V shm. Therefore, even on AIX, this has to be mmap.
We also have `os::remap_memory()`, replacing an existing mapping with a new one.
`os::remap_memory()` was introduced to transparently handle Windows specialties: we cannot just replace an existing mapping. We need to unmap the old mapping first. The original implementation of `os::remap_memory()` on Windows did just that. However, this is not thread-safe, and [JDK-8222379](https://bugs.openjdk.org/browse/JDK-8222379) later removed the Windows implementation, replacing it with a "ShouldNotReachHere."
So:
- on Posix, remap_memory is an alias for map_memory
- on Windows, it must not be called
therefore we can replace the (one) caller of `os::remap_memory()` with `os::map_memory()`. It also makes sense: by contract, `os::map_memory()` replaces the mapping on Posix. Therefore, we don't need an extra function for that.
Other simplifications are possible, too, so this patch:
1) removes `os::remap_memory`
2) unifies `os::map_memory` for all Posix platforms
3) ditto for `os::unmap_memory`
Minor functional changes in `os::map_memory()`:
- On AIX, we allowed anonymous mappings (when fd==-1). That had never been active code since `os::map_memory()` is only used by CDS, and AIX does not ship with CDS. It also would be redundant: we already have a way to create anonymous mappings (`os::reserve_memory()`). Therefore, I removed that option; instead, I now require on all Posix platforms that a valid file descriptor is always given.
- On BSD and AIX, we had a weird logic whereby we mapped the mapping shared if it is read-only, and private if it is read-write. We explicitly don't do this on Linux (changed with [JDK-7142641](https://bugs.openjdk.org/browse/JDK-7142641). After the patch, all platforms behave the same: mappings are now private, regardless of writability.
-------------
Commit messages:
- JDK-8326067-Remove-os-remap_memory-and-simplify-os-map_memory
Changes: https://git.openjdk.org/jdk/pull/17893/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17893&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8326067
Stats: 227 lines in 8 files changed: 53 ins; 171 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/17893.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/17893/head:pull/17893
PR: https://git.openjdk.org/jdk/pull/17893
More information about the hotspot-runtime-dev
mailing list