Fix bug in zap_range and add virtual space test stuefe-new-metaspace-branch
authorstuefe
Tue, 19 Nov 2019 16:58:25 +0100
branchstuefe-new-metaspace-branch
changeset 59135 84464aa83a29
parent 59134 b67820888eb3
child 59138 714474295e0a
Fix bug in zap_range and add virtual space test
src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp
test/hotspot/gtest/metaspace/metaspaceTestsCommon.cpp
test/hotspot/gtest/metaspace/test_virtualspacenode.cpp
--- a/src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp	Tue Nov 19 16:53:17 2019 +0100
+++ b/src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp	Tue Nov 19 16:58:25 2019 +0100
@@ -125,8 +125,6 @@
                    SizeCounter* reserve_counter,
                    SizeCounter* commit_counter);
 
-  MetaWord* base() const        { return _base; }
-
 public:
 
   // Create a node of a given size
@@ -145,6 +143,8 @@
 
   ~VirtualSpaceNode();
 
+  // Note: public for gtests only, could be private.
+  MetaWord* base() const        { return _base; }
 
   // Reserved size of the whole node.
   size_t word_size() const      { return _word_size; }
--- a/test/hotspot/gtest/metaspace/metaspaceTestsCommon.cpp	Tue Nov 19 16:53:17 2019 +0100
+++ b/test/hotspot/gtest/metaspace/metaspaceTestsCommon.cpp	Tue Nov 19 16:58:25 2019 +0100
@@ -100,8 +100,8 @@
 
 
 void zap_range(MetaWord* p, size_t word_size) {
-  for (MetaWord* pzap = p; pzap < p + word_size; pzap += os::vm_page_size()) {
-    *pzap = 0;
+  for (MetaWord* pzap = p; pzap < p + word_size; pzap += os::vm_page_size() / BytesPerWord) {
+    *pzap = (MetaWord)0xFEFEFEFE;
   }
 }
 
--- a/test/hotspot/gtest/metaspace/test_virtualspacenode.cpp	Tue Nov 19 16:53:17 2019 +0100
+++ b/test/hotspot/gtest/metaspace/test_virtualspacenode.cpp	Tue Nov 19 16:58:25 2019 +0100
@@ -468,6 +468,54 @@
 
 };
 
+
+
+TEST_VM(metaspace, virtual_space_node_test_basics) {
+
+  MutexLocker fcl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag);
+
+  const size_t word_size = metaspace::chklvl::MAX_CHUNK_WORD_SIZE * 10;
+
+  SizeCounter scomm;
+  SizeCounter sres;
+  CommitLimiter cl (word_size * 2); // basically, no commit limiter.
+
+  VirtualSpaceNode* node = VirtualSpaceNode::create_node(42, word_size, &cl, &sres, &scomm);
+  ASSERT_NOT_NULL(node);
+  ASSERT_EQ(node->committed_words(), (size_t)0);
+  ASSERT_EQ(node->committed_words(), scomm.get());
+  DEBUG_ONLY(node->verify(true);)
+
+  bool b = node->ensure_range_is_committed(node->base(), node->word_size());
+  ASSERT_TRUE(b);
+  ASSERT_EQ(node->committed_words(), word_size);
+  ASSERT_EQ(node->committed_words(), scomm.get());
+  DEBUG_ONLY(node->verify(true);)
+  zap_range(node->base(), node->word_size());
+
+  node->uncommit_range(node->base(), node->word_size());
+  ASSERT_EQ(node->committed_words(), (size_t)0);
+  ASSERT_EQ(node->committed_words(), scomm.get());
+  DEBUG_ONLY(node->verify(true);)
+
+  const int num_granules = (int)(word_size / Settings::commit_granule_words());
+  for (int i = 1; i < num_granules; i += 4) {
+    b = node->ensure_range_is_committed(node->base(), i * Settings::commit_granule_words());
+    ASSERT_TRUE(b);
+    ASSERT_EQ(node->committed_words(), i * Settings::commit_granule_words());
+    ASSERT_EQ(node->committed_words(), scomm.get());
+    DEBUG_ONLY(node->verify(true);)
+    zap_range(node->base(), i * Settings::commit_granule_words());
+  }
+
+  node->uncommit_range(node->base(), node->word_size());
+  ASSERT_EQ(node->committed_words(), (size_t)0);
+  ASSERT_EQ(node->committed_words(), scomm.get());
+  DEBUG_ONLY(node->verify(true);)
+
+}
+
+
 // Note: we unfortunately need TEST_VM even though the system tested
 // should be pretty independent since we need things like os::vm_page_size()
 // which in turn need OS layer initialization.
@@ -508,7 +556,7 @@
   }
 }
 
-TEST_VM(metaspace, virtual_space_node_test_6) {
+TEST_VM(metaspace, virtual_space_node_test_7) {
   // Test large allocation and freeing.
   {
     VirtualSpaceNodeTest test(metaspace::chklvl::MAX_CHUNK_WORD_SIZE * 100,