Integrated: 8353564: Fail fatally if os::release_memory or os::uncommit_memory fails

Robert Toyonaga duke at openjdk.org
Fri Feb 13 04:50:53 UTC 2026


On Wed, 14 Jan 2026 23:30:14 GMT, Robert Toyonaga <duke at openjdk.org> wrote:

> This PR is a follow up to JDK-8341491. See original discussion: https://github.com/openjdk/jdk/pull/24084#issuecomment-2752513700
> 
> This PR makes `os::release_memory`, `os::uncommit_memory`, `os::release_memory_special`, and `os::unmap_memory` fail fatally if they encounter an error. These methods require obtaining the NMT lock. Fatally failing in these places would potentially allow for the tightening of NMT virtual memory locking scopes (future work, if this PR is accepted).  Already in most cases, the callers fail fatally or assert(false) when these os:: methods fail. Another reason to fatally fail is that if the OS memory operation fails, it can be difficult to know for sure what state the OS left the memory in and recover. 
> 
> `release_memory`/`uncommit_memory`/`release_memory_special`/`unmap_memory` can fail due to ① Bad arguments, or ② The OS encountered an issue out of control of the JVM.
> 
>> If there is a JVM bug, it's probably reasonable to fatally fail here. Or the caller could be intentionally passing arguments that may or may not be valid. I don't think there is any code like that currently, and this is probably a bad pattern to be following anyway.
> 
>> In platform dependent code: 
> With regard to mmap/munmap, the only errors that aren't due to bad arguments are ENOMEM and ones related to file descriptors (which are not applicable to uncommit or release).
> On Windows, VirtualFree only fails due to bad arguments.
> On AIX, shmdt and disclaim64 only fail due to bad arguments. msync could spontaneously fail with EIO: "An I/O error occurred while reading from or writing to the file system."
> On BSD, it seems like mprotect and madvise fail only due to bad arguments or invalid privileges.
> 
> In the [original discussion](https://github.com/openjdk/jdk/pull/24084#issuecomment-2752513700), the main question was whether ENOMEM upon os::uncommit_memory was recoverable. This may be possible if we uncommit the middle of a region - splitting it in two. This could exceed the limit of the number of mappings resulting in ENOMEM. 
> 
> If none of the scenarios in ② are recoverable, then perhaps fatally failing is OK. 
> 
> Testing:
> 	- Tier 1.
> 	- Manual testing to make sure we fatally fail and the correct messages are printed.

This pull request has now been integrated.

Changeset: 9c75afb6
Author:    Robert Toyonaga <rtoyonag at redhat.com>
Committer: Thomas Stuefe <stuefe at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/9c75afb6d0ea95c5356e3e29ae66cfc8b04c3564
Stats:     191 lines in 22 files changed: 43 ins; 62 del; 86 mod

8353564: Fail fatally if os::release_memory or os::uncommit_memory fails

Reviewed-by: stefank, stuefe, dholmes

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

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


More information about the shenandoah-dev mailing list