RFR: 8370254: Add VM_MEMORY_JAVA mmap tag to MacOS mmap calls [v15]

Thomas Stuefe stuefe at openjdk.org
Sat Nov 15 10:33:08 UTC 2025


On Sat, 15 Nov 2025 05:51:03 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Nityanand Rai has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   cleanup
>
> src/hotspot/os/bsd/os_bsd.hpp line 43:
> 
>> 41: // Bsd_OS defines the interface to Bsd operating systems
>> 42: 
>> 43: static constexpr int bsd_mmap_fd =
> 
> I don't have familiarity in this area, but looking at the man page of `mmap` on my local macos, it states this:
> 
> 
> void *
> mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
> ...
> MAP_ANON          Map anonymous memory not associated with any specific file.  The offset argument is ignored.  Mac OS X specific: the file descriptor used for
>                    creating MAP_ANON regions can be used to pass some Mach VM flags, and can be specified as -1 if no such flags are associated with the region.
>                    Mach VM flags are defined in <mach/vm_statistics.h> and the ones that currently apply to mmap are:
> 
>                    VM_FLAGS_PURGABLE   to create Mach purgable (i.e. volatile) memory.
> 
>                    VM_MAKE_TAG(tag)    to associate an 8-bit tag with the region.
>                    <mach/vm_statistics.h> defines some preset tags (with a VM_MEMORY_ prefix).  Users are encouraged to use tags between 240 and 255.  Tags are used
>                    by tools such as vmmap(1) to help identify specific memory regions.
> 
> 
> So this special value handling of `fd` value is only applicable if `MAP_ANON` is part of the `flags`.
> Given this, should the name of constexpr be a bit more specific and the call sites, where this gets used, verify/assert that the flags indeed contains the `MAP_ANON` flag?
> Plus, this is very macos specific, calling it `bsd_...` feels much more generic. Maybe we should consider naming it `macos_mmap_anon_fd`?

@jaikiran If `MAP_ANON` is not set, a file descriptor will be given. Contract for MAP_ANON (or MAP_ANONYMOUS on Linux).

About the bsd.. naming:

I think this is okay. The source split between xxBSD and Mac is long overdue. I think there is (was?) someone from the FreeBSD foundation working on it. 

That said, I think this should not be a global constant but live in the os::BSD namespace/class.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27868#discussion_r2529763594


More information about the hotspot-dev mailing list