changeset 59353:88142d00ec1c

8245035: Clean up os::split_reserved_memory() Reviewed-by: coleenp, stefank
author stuefe
date Tue, 19 May 2020 21:04:44 +0200
parents 98d450e6aabf
children 10cf1d393996
files src/hotspot/os/aix/os_aix.inline.hpp src/hotspot/os/bsd/os_bsd.inline.hpp src/hotspot/os/linux/os_linux.inline.hpp src/hotspot/os/posix/os_posix.cpp src/hotspot/os/solaris/os_solaris.inline.hpp src/hotspot/os/windows/os_windows.cpp src/hotspot/share/gc/shared/genCollectedHeap.cpp src/hotspot/share/memory/virtualspace.cpp src/hotspot/share/memory/virtualspace.hpp src/hotspot/share/runtime/os.cpp src/hotspot/share/runtime/os.hpp
diffstat 11 files changed, 48 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/aix/os_aix.inline.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/aix/os_aix.inline.hpp	Tue May 19 21:04:44 2020 +0200
@@ -49,13 +49,6 @@
   return false;
 }
 
-// On Aix, reservations are made on a page by page basis, nothing to do.
-inline void os::pd_split_reserved_memory(char *base, size_t size,
-                                         size_t split, bool realloc) {
-  // TODO: Determine whether Sys V memory is split. If yes, we need to treat
-  // this the same way Windows treats its VirtualAlloc allocations.
-}
-
 // Bang the shadow pages if they need to be touched to be mapped.
 inline void os::map_stack_shadow_pages(address sp) {
 }
--- a/src/hotspot/os/bsd/os_bsd.inline.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/bsd/os_bsd.inline.hpp	Tue May 19 21:04:44 2020 +0200
@@ -52,13 +52,6 @@
 #endif
 }
 
-
-// On Bsd, reservations are made on a page by page basis, nothing to do.
-inline void os::pd_split_reserved_memory(char *base, size_t size,
-                                      size_t split, bool realloc) {
-}
-
-
 // Bang the shadow pages if they need to be touched to be mapped.
 inline void os::map_stack_shadow_pages(address sp) {
 }
--- a/src/hotspot/os/linux/os_linux.inline.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/linux/os_linux.inline.hpp	Tue May 19 21:04:44 2020 +0200
@@ -44,13 +44,6 @@
   return true;
 }
 
-
-// On Linux, reservations are made on a page by page basis, nothing to do.
-inline void os::pd_split_reserved_memory(char *base, size_t size,
-                                      size_t split, bool realloc) {
-}
-
-
 // Bang the shadow pages if they need to be touched to be mapped.
 inline void os::map_stack_shadow_pages(address sp) {
 }
--- a/src/hotspot/os/posix/os_posix.cpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/posix/os_posix.cpp	Tue May 19 21:04:44 2020 +0200
@@ -362,6 +362,16 @@
   return aligned_base;
 }
 
+// On Posix platforms, reservations are done using mmap which can be released in parts. So splitting is a no-op.
+void os::split_reserved_memory(char *base, size_t size, size_t split) {
+  char* const split_address = base + split;
+  assert(size > 0, "Sanity");
+  assert(size > split, "Sanity");
+  assert(split > 0, "Sanity");
+  assert(is_aligned(base, os::vm_allocation_granularity()), "Sanity");
+  assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity");
+}
+
 int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
   // All supported POSIX platforms provide C99 semantics.
   int result = ::vsnprintf(buf, len, fmt, args);
--- a/src/hotspot/os/solaris/os_solaris.inline.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/solaris/os_solaris.inline.hpp	Tue May 19 21:04:44 2020 +0200
@@ -49,12 +49,6 @@
 }
 
 
-// On Solaris, reservations are made on a page by page basis, nothing to do.
-inline void os::pd_split_reserved_memory(char *base, size_t size,
-                                      size_t split, bool realloc) {
-}
-
-
 // Bang the shadow pages if they need to be touched to be mapped.
 inline void os::map_stack_shadow_pages(address sp) {
 }
--- a/src/hotspot/os/windows/os_windows.cpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/os/windows/os_windows.cpp	Tue May 19 21:04:44 2020 +0200
@@ -3071,17 +3071,19 @@
 // On win32, one cannot release just a part of reserved memory, it's an
 // all or nothing deal.  When we split a reservation, we must break the
 // reservation into two reservations.
-void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
-                                  bool realloc) {
-  if (size > 0) {
-    release_memory(base, size);
-    if (realloc) {
-      reserve_memory(split, base);
-    }
-    if (size != split) {
-      reserve_memory(size - split, base + split);
-    }
-  }
+void os::split_reserved_memory(char *base, size_t size, size_t split) {
+
+  char* const split_address = base + split;
+  assert(size > 0, "Sanity");
+  assert(size > split, "Sanity");
+  assert(split > 0, "Sanity");
+  assert(is_aligned(base, os::vm_allocation_granularity()), "Sanity");
+  assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity");
+
+  release_memory(base, size);
+  reserve_memory(split, base);
+  reserve_memory(size - split, split_address);
+
 }
 
 // Multiple threads can race in this code but it's not possible to unmap small sections of
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Tue May 19 21:04:44 2020 +0200
@@ -122,11 +122,11 @@
   bs->initialize();
   BarrierSet::set_barrier_set(bs);
 
-  ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size(), false, false);
+  ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size());
   _young_gen = _young_gen_spec->init(young_rs, rem_set());
   ReservedSpace old_rs = heap_rs.last_part(_young_gen_spec->max_size());
 
-  old_rs = old_rs.first_part(_old_gen_spec->max_size(), false, false);
+  old_rs = old_rs.first_part(_old_gen_spec->max_size());
   _old_gen = _old_gen_spec->init(old_rs, rem_set());
   clear_incremental_collection_failed();
 
--- a/src/hotspot/share/memory/virtualspace.cpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/share/memory/virtualspace.cpp	Tue May 19 21:04:44 2020 +0200
@@ -226,11 +226,10 @@
   }
 }
 
-ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment,
-                                        bool split, bool realloc) {
+ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment, bool split) {
   assert(partition_size <= size(), "partition failed");
-  if (split) {
-    os::split_reserved_memory(base(), size(), partition_size, realloc);
+  if (split && partition_size > 0 && partition_size < size()) {
+    os::split_reserved_memory(base(), size(), partition_size);
   }
   ReservedSpace result(base(), partition_size, alignment, special(),
                        executable());
--- a/src/hotspot/share/memory/virtualspace.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/share/memory/virtualspace.hpp	Tue May 19 21:04:44 2020 +0200
@@ -75,13 +75,16 @@
   void release();
 
   // Splitting
-  ReservedSpace first_part(size_t partition_size, size_t alignment,
-                           bool split = false, bool realloc = true);
+  // This splits the space into two spaces, the first part of which will be returned.
+  // If split==true, the resulting two spaces can be released independently from each other.
+  //  This may cause the original space to loose its content.
+  // If split==false, the resulting space will be just a hotspot-internal representation
+  //  of a sub section of the underlying mapping.
+  ReservedSpace first_part(size_t partition_size, size_t alignment, bool split = false);
   ReservedSpace last_part (size_t partition_size, size_t alignment);
 
   // These simply call the above using the default alignment.
-  inline ReservedSpace first_part(size_t partition_size,
-                                  bool split = false, bool realloc = true);
+  inline ReservedSpace first_part(size_t partition_size, bool split = false);
   inline ReservedSpace last_part (size_t partition_size);
 
   // Alignment
@@ -94,9 +97,9 @@
 };
 
 ReservedSpace
-ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
+ReservedSpace::first_part(size_t partition_size, bool split)
 {
-  return first_part(partition_size, alignment(), split, realloc);
+  return first_part(partition_size, alignment(), split);
 }
 
 ReservedSpace ReservedSpace::last_part(size_t partition_size)
--- a/src/hotspot/share/runtime/os.cpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/share/runtime/os.cpp	Tue May 19 21:04:44 2020 +0200
@@ -1697,11 +1697,6 @@
   return result;
 }
 
-void os::split_reserved_memory(char *base, size_t size,
-                                 size_t split, bool realloc) {
-  pd_split_reserved_memory(base, size, split, realloc);
-}
-
 bool os::commit_memory(char* addr, size_t bytes, bool executable) {
   bool res = pd_commit_memory(addr, bytes, executable);
   if (res) {
--- a/src/hotspot/share/runtime/os.hpp	Tue May 19 11:20:13 2020 -0700
+++ b/src/hotspot/share/runtime/os.hpp	Tue May 19 21:04:44 2020 +0200
@@ -119,8 +119,6 @@
                                   size_t alignment_hint = 0);
   static char*  pd_attempt_reserve_memory_at(size_t bytes, char* addr);
   static char*  pd_attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc);
-  static void   pd_split_reserved_memory(char *base, size_t size,
-                                      size_t split, bool realloc);
   static bool   pd_commit_memory(char* addr, size_t bytes, bool executable);
   static bool   pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
                                  bool executable);
@@ -320,8 +318,17 @@
                                size_t alignment_hint, MEMFLAGS flags);
   static char*  reserve_memory_aligned(size_t size, size_t alignment, int file_desc = -1);
   static char*  attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1);
-  static void   split_reserved_memory(char *base, size_t size,
-                                      size_t split, bool realloc);
+
+
+  // Split a reserved memory region [base, base+size) into two regions [base, base+split) and
+  //  [base+split, base+size).
+  //  This may remove the original mapping, so its content may be lost.
+  // Both base and split point must be aligned to allocation granularity; split point shall
+  //  be >0 and <size.
+  // Splitting guarantees that the resulting two memory regions can be released independently
+  //  from each other using os::release_memory().
+  static void   split_reserved_memory(char *base, size_t size, size_t split);
+
   static bool   commit_memory(char* addr, size_t bytes, bool executable);
   static bool   commit_memory(char* addr, size_t size, size_t alignment_hint,
                               bool executable);