RFR: JDK-8284178: os::commit_memory() should assert the given range

Aleksey Shipilev shade at openjdk.java.net
Wed Apr 6 08:11:49 UTC 2022


On Fri, 1 Apr 2022 12:58:47 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> Trivial fix to assert that ranges given to os::commit/uncommit/release_memory are not empty.
> 
> I recently hunted an error where the memory reservation failed, was not handled, and the null pointer was accidentally passed to os::commit_memory(). The resulting `mmap()` failed and this looked like a commit error, when it really was a reservation error. An assert would have saved me time.

Changes requested by shade (Reviewer).

src/hotspot/share/runtime/os.cpp line 1679:

> 1677: 
> 1678: static void assert_nonempty_range(const char* addr, size_t bytes) {
> 1679:   assert(addr != nullptr && bytes > 0, "invalid range (" PTR_FORMAT ", " SIZE_FORMAT ")",

The message suggests it is *range*, i.e. `(begin, end)`. I wonder if we better print `p2i(addr) + bytes`?

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

PR: https://git.openjdk.java.net/jdk/pull/8075


More information about the hotspot-runtime-dev mailing list