changeset 7311:340ca8812af9

8067469: G1 ignores AlwaysPreTouch Summary: Factor out pretouch code of the various virtual space management classes and use them everywhere including in G1. Reviewed-by: stefank, ehelin, dholmes
author tschatzl
date Thu, 18 Dec 2014 09:37:02 +0100
parents 41a855ff6305
children c2ce24504334
files src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp src/share/vm/gc_implementation/shared/mutableSpace.cpp src/share/vm/runtime/os.cpp src/share/vm/runtime/os.hpp src/share/vm/runtime/virtualspace.cpp
diffstat 5 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp	Mon Sep 15 10:57:22 2014 +0200
+++ b/src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp	Thu Dec 18 09:37:02 2014 +0100
@@ -144,6 +144,9 @@
   }
   _committed.set_range(start, end);
 
+  if (AlwaysPreTouch) {
+    os::pretouch_memory(page_start(start), page_start(start) + byte_size_for_pages(size_in_pages));
+  }
   return zero_filled;
 }
 
--- a/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Mon Sep 15 10:57:22 2014 +0200
+++ b/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Thu Dec 18 09:37:02 2014 +0100
@@ -62,9 +62,7 @@
 }
 
 void MutableSpace::pretouch_pages(MemRegion mr) {
-  for (volatile char *p = (char*)mr.start(); p < (char*)mr.end(); p += os::vm_page_size()) {
-    char t = *p; *p = t;
-  }
+  os::pretouch_memory((char*)mr.start(), (char*)mr.end());
 }
 
 void MutableSpace::initialize(MemRegion mr,
--- a/src/share/vm/runtime/os.cpp	Mon Sep 15 10:57:22 2014 +0200
+++ b/src/share/vm/runtime/os.cpp	Thu Dec 18 09:37:02 2014 +0100
@@ -1513,6 +1513,11 @@
   return res;
 }
 
+void os::pretouch_memory(char* start, char* end) {
+  for (volatile char *p = start; p < end; p += os::vm_page_size()) {
+    *p = 0;
+  }
+}
 
 char* os::map_memory(int fd, const char* file_name, size_t file_offset,
                            char *addr, size_t bytes, bool read_only,
--- a/src/share/vm/runtime/os.hpp	Mon Sep 15 10:57:22 2014 +0200
+++ b/src/share/vm/runtime/os.hpp	Thu Dec 18 09:37:02 2014 +0100
@@ -319,6 +319,12 @@
   static bool   uncommit_memory(char* addr, size_t bytes);
   static bool   release_memory(char* addr, size_t bytes);
 
+  // Touch memory pages that cover the memory range from start to end (exclusive)
+  // to make the OS back the memory range with actual memory.
+  // Current implementation may not touch the last page if unaligned addresses
+  // are passed.
+  static void   pretouch_memory(char* start, char* end);
+
   enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX };
   static bool   protect_memory(char* addr, size_t bytes, ProtType prot,
                                bool is_committed = true);
--- a/src/share/vm/runtime/virtualspace.cpp	Mon Sep 15 10:57:22 2014 +0200
+++ b/src/share/vm/runtime/virtualspace.cpp	Thu Dec 18 09:37:02 2014 +0100
@@ -630,19 +630,7 @@
   }
 
   if (pre_touch || AlwaysPreTouch) {
-    int vm_ps = os::vm_page_size();
-    for (char* curr = previous_high;
-         curr < unaligned_new_high;
-         curr += vm_ps) {
-      // Note the use of a write here; originally we tried just a read, but
-      // since the value read was unused, the optimizer removed the read.
-      // If we ever have a concurrent touchahead thread, we'll want to use
-      // a read, to avoid the potential of overwriting data (if a mutator
-      // thread beats the touchahead thread to a page).  There are various
-      // ways of making sure this read is not optimized away: for example,
-      // generating the code for a read procedure at runtime.
-      *curr = 0;
-    }
+    os::pretouch_memory(previous_high, unaligned_new_high);
   }
 
   _high += bytes;