< prev index next >

test/hotspot/gtest/memory/test_virtualspace.cpp

Print this page
rev 52125 : 8171097: Convert TestReservedSpace_test to Gtest
Reviewed-by: duke
rev 52126 : 8177709: Convert TestVirtualSpace_test to GTest
Reviewed-by: duke
rev 52127 : [mq]: 8177709-2

@@ -191,10 +191,19 @@
     Disable,
     Reserve,
     Commit
   };
 
+  class ReservedSpaceReleaser {
+    ReservedSpace* const _rs;
+   public:
+    ReservedSpaceReleaser(ReservedSpace* rs) : _rs(rs) { }
+    ~ReservedSpaceReleaser() {
+      _rs->release();
+    }
+  };
+
   ReservedSpace reserve_memory(size_t reserve_size_aligned, TestLargePages mode) {
     switch(mode) {
       default:
       case Default:
       case Reserve:

@@ -224,10 +233,11 @@
                                                 TestLargePages mode = Default) {
     size_t granularity = os::vm_allocation_granularity();
     size_t reserve_size_aligned = align_up(reserve_size, granularity);
 
     ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
+    ReservedSpaceReleaser releaser(&reserved);
 
     ASSERT_TRUE(reserved.is_reserved());
 
     VirtualSpace vs;
     ASSERT_TRUE(initialize_virtual_space(vs, reserved, mode)) << "Failed to initialize VirtualSpace";

@@ -242,12 +252,10 @@
       // if large pages has been disabled for this VirtualSpace.
       size_t commit_granularity = (mode == Disable || !UseLargePages) ?
                                    os::vm_page_size() : os::large_page_size();
       EXPECT_LT(vs.actual_committed_size(), commit_size + commit_granularity);
     }
-
-    reserved.release();
   }
 };
 
 TEST_VM(VirtualSpace, actual_committed_space) {
   EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(4 * K,  0));

@@ -282,19 +290,18 @@
   }
 
   size_t large_page_size = os::large_page_size();
 
   ReservedSpace reserved(large_page_size, large_page_size, true, false);
+  ReservedSpaceReleaser releaser(&reserved);
   ASSERT_TRUE(reserved.is_reserved());
 
   VirtualSpace vs;
   ASSERT_TRUE(vs.initialize(reserved, 0)) << "Failed to initialize VirtualSpace";
   vs.expand_by(large_page_size, false);
 
   EXPECT_EQ(large_page_size, vs.actual_committed_size());
-
-  reserved.release();
 }
 
 TEST_VM(VirtualSpace, disable_large_pages) {
   if (!UseLargePages) {
     return;
< prev index next >