RFR: 8370254: Add VM_MEMORY_JAVA mmap tag to MacOS mmap calls

Evgeny Astigeevich eastigeevich at openjdk.org
Wed Oct 29 17:42:07 UTC 2025


On Fri, 17 Oct 2025 17:01:02 GMT, Nityanand Rai <duke at openjdk.org> wrote:

> Add VM_MEMORY_JAVA tag to mmap calls in os_bsd.cpp for better memory tracking of java process on macOs

https://bugs.openjdk.org/browse/JDK-8370238

@nityarai08 ,

What macOS and Xcode versions are required to support `VM_MEMORY_JAVA` tag? 

OpenJDK macOS recommendation:
> It is recommended that you use at least macOS 14 and Xcode 15.4, but earlier versions may also work.

It would be nice to have a gtest.

src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp line 111:

> 109: #else
> 110:   const void* const res = mmap((void*)addr, length, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> 111: #endif

Maybe this code has better readability:
- A global constant

constexpr int mmap_fd =
#ifdef __APPLE__
VM_MAKE_TAG(VM_MEMORY_JAVA);
#else
-1;
#endif


In all `mmap` we replace `-1` with `mmap_fd`. This will minimize the number of `#ifdef`.

test/hotspot/gtest/runtime/test_os_bsd_memory_tagging.cpp line 3:

> 1: /*
> 2:  * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
> 3:  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

Correct lines are:


 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 ```

test/hotspot/gtest/runtime/test_os_bsd_memory_tagging.cpp line 34:

> 32: // Test that memory allocations on macOS are properly tagged with VM_MEMORY_JAVA
> 33: // This validates the VM_MAKE_TAG(VM_MEMORY_JAVA) changes in os_bsd.cpp
> 34: class BSDMemoryTaggingTest : public ::testing::Test {

This test does not test new JVM runtime code.
I found there are tests which might test this code:
- test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp
- test/hotspot/gtest//runtime/test_os.cpp

You need to check if they cover your changes. If not, you need to add tests to `test_os_bsd.cpp`.
Also there are tests for ZGC in `test/hotspot/gtest/gc/z`. You need to check if any of them cover your changes.

IMO, `is_memory_tagged_as_java` will be needed.

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

PR Comment: https://git.openjdk.org/jdk/pull/27868#issuecomment-3422396080
PR Comment: https://git.openjdk.org/jdk/pull/27868#issuecomment-3422444972
PR Review Comment: https://git.openjdk.org/jdk/pull/27868#discussion_r2474311804
PR Review Comment: https://git.openjdk.org/jdk/pull/27868#discussion_r2474262825
PR Review Comment: https://git.openjdk.org/jdk/pull/27868#discussion_r2474369331


More information about the hotspot-runtime-dev mailing list