src/hotspot/share/memory/metaspace/commitMask.cpp
branchstuefe-new-metaspace-branch
changeset 58683 2d5dd194c65c
parent 58099 5aeb07390c74
--- a/src/hotspot/share/memory/metaspace/commitMask.cpp	Wed Oct 16 17:41:03 2019 +0200
+++ b/src/hotspot/share/memory/metaspace/commitMask.cpp	Thu Oct 17 16:39:45 2019 +0200
@@ -24,7 +24,6 @@
  */
 
 
-#include <memory/metaspace/settings.hpp>
 #include "precompiled.hpp"
 
 #include "memory/metaspace/commitMask.hpp"
@@ -49,36 +48,44 @@
 
 #ifdef ASSERT
 
+// This is very expensive
 static const bool TEST_UNCOMMITTED_REGION = false;
 
 volatile u1 x;
 
-void CommitMask::verify(bool slow, bool do_touch_test) const {
+static void check_range_is_accessible(const MetaWord* p, size_t word_size) {
+  const MetaWord* const p_end = p + word_size;
+  u1 x2 = 0;
+  for (const MetaWord* q = p; q < p_end; q += os::vm_page_size() / BytesPerWord) {
+    x2 += *(u1*)q;
+  }
+  x = x2;
+}
+
+void CommitMask::verify(bool slow) const {
 
   // Walk the whole commit mask.
   // For each 1 bit, check if the associated granule is accessible.
   // For each 0 bit, check if the associated granule is not accessible. Slow mode only.
 
+  assert(_base != NULL && _word_size > 0 && _words_per_bit > 0, "Sanity");
   assert_is_aligned(_base, _words_per_bit * BytesPerWord);
   assert_is_aligned(_word_size, _words_per_bit);
 
-  if (do_touch_test) {
+  if (slow) {
     for (idx_t i = 0; i < size(); i ++) {
       const MetaWord* const p = _base + (i * _words_per_bit);
       if (at(i)) {
         // Should be accessible. Just touch it.
-        x ^= *(u1*)p;
+        check_range_is_accessible(p, _words_per_bit);
       } else {
-        // Should not be accessible.
-        if (slow) {
-          // Note: results may differ between platforms. On Linux, this should be true since
-          // we uncommit memory by setting protection to PROT_NONE. We may have to look if
-          // this works as expected on other platforms.
-          if (TEST_UNCOMMITTED_REGION && CanUseSafeFetch32()) {
-            assert(os::is_readable_pointer(p) == false,
-                   "index %u, pointer " PTR_FORMAT ", should not be accessible.",
-                   (unsigned)i, p2i(p));
-          }
+        // Note: results may differ between platforms. On Linux, this should be true since
+        // we uncommit memory by setting protection to PROT_NONE. We may have to look if
+        // this works as expected on other platforms.
+        if (TEST_UNCOMMITTED_REGION && CanUseSafeFetch32()) {
+          assert(os::is_readable_pointer(p) == false,
+                 "index %u, pointer " PTR_FORMAT ", should not be accessible.",
+                 (unsigned)i, p2i(p));
         }
       }
     }