[PATCH] Darwin, option to monitor anonymous pages

David CARLIER devnexen at gmail.com
Sat Aug 31 20:19:25 UTC 2019


Hi

Here a little patch proposal to be able to monitor anonymous pages
with tools like mmap

Kind regards.

# HG changeset patch
# User David Carlier <devnexen at gmail.com>
# Date 1567278245 -3600
#      Sat Aug 31 20:04:05 2019 +0100
# Node ID 7c566025b2e224b241704ec3a3f2fb8c70167c48
# Parent  1262b3ddd7e4f010bf81f2564bf86e7e2c00467a
Darwin, option to monitor anonymous pages

new flag AnonMapId, from 240 up to 255
to follow up Apple recommendations and flexibility
to avoid collisions with increasing code using it.

diff -r 1262b3ddd7e4 -r 7c566025b2e2 src/hotspot/os/bsd/globals_bsd.hpp
--- a/src/hotspot/os/bsd/globals_bsd.hpp Sat Aug 31 09:18:40 2019 -0700
+++ b/src/hotspot/os/bsd/globals_bsd.hpp Sat Aug 31 20:04:05 2019 +0100
@@ -46,6 +46,7 @@
   /*  overridden in Arguments::parse_each_vm_init_arg.            */
          \
   product(bool, UseBsdPosixThreadCPUClocks, true,
          \
           "enable fast Bsd Posix clocks where available")
          \
+  product(intx, AnonMapId, 240, "set anonymous page tag ID")
          \

 //
 // Defines Bsd-specific default values. The flags are available on all
diff -r 1262b3ddd7e4 -r 7c566025b2e2 src/hotspot/os/bsd/os_bsd.cpp
--- a/src/hotspot/os/bsd/os_bsd.cpp Sat Aug 31 09:18:40 2019 -0700
+++ b/src/hotspot/os/bsd/os_bsd.cpp Sat Aug 31 20:04:05 2019 +0100
@@ -104,6 +104,7 @@

 #ifdef __APPLE__
   #include <mach-o/dyld.h>
+  #include <mach/vm_statistics.h>
 #endif

 #ifndef MAP_ANONYMOUS
@@ -2066,18 +2067,26 @@
 static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
   char * addr;
   int flags;
+  int fd;

   flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
+  fd = -1;
   if (fixed) {
     assert((uintptr_t)requested_addr % os::Bsd::page_size() == 0,
"unaligned address");
     flags |= MAP_FIXED;
   }
+#ifdef __APPLE__
+  // Apple guarantees free IDs from 240 up to 255
+  // for userland applications.
+  if (AnonMapId >= 240 && AnonMapId < 255)
+    fd = VM_MAKE_TAG(AnonMapId);
+#endif

   // Map reserved/uncommitted pages PROT_NONE so we fail early if we
   // touch an uncommitted page. Otherwise, the read/write might
   // succeed if we have enough swap space to back the physical page.
   addr = (char*)::mmap(requested_addr, bytes, PROT_NONE,
-                       flags, -1, 0);
+                       flags, fd, 0);

   return addr == MAP_FAILED ? NULL : addr;
 }


More information about the hotspot-dev mailing list