Integrated: JDK-8326067: Remove os::remap_memory and simplify os::map_memory

Thomas Stuefe stuefe at openjdk.org
Mon Feb 19 19:35:58 UTC 2024


On Fri, 16 Feb 2024 17:15:44 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> 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.

This pull request has now been integrated.

Changeset: 20a25f60
Author:    Thomas Stuefe <stuefe at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/20a25f60ea56ecd28da1ab377f8f2ca8b2098a3b
Stats:     227 lines in 8 files changed: 53 ins; 171 del; 3 mod

8326067: Remove os::remap_memory and simplify os::map_memory

Reviewed-by: eosterlund, iklam

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

PR: https://git.openjdk.org/jdk/pull/17893


More information about the hotspot-runtime-dev mailing list