< prev index next >

test/hotspot/gtest/metaspace/test_metaspacearena.cpp

Print this page
*** 25,10 ***
--- 25,11 ---
  
  #include "precompiled.hpp"
  #include "memory/metaspace/commitLimiter.hpp"
  #include "memory/metaspace/counters.hpp"
  #include "memory/metaspace/internalStats.hpp"
+ #include "memory/metaspace/metaspaceAlignment.hpp"
  #include "memory/metaspace/metaspaceArena.hpp"
  #include "memory/metaspace/metaspaceArenaGrowthPolicy.hpp"
  #include "memory/metaspace/metaspaceSettings.hpp"
  #include "memory/metaspace/metaspaceStatistics.hpp"
  #include "runtime/mutex.hpp"

*** 48,32 ***
  using metaspace::MetaspaceArena;
  using metaspace::SizeAtomicCounter;
  using metaspace::Settings;
  using metaspace::ArenaStats;
  
- // See metaspaceArena.cpp : needed for predicting commit sizes.
- namespace metaspace {
-   extern size_t get_raw_word_size_for_requested_word_size(size_t net_word_size);
- }
- 
  class MetaspaceArenaTestHelper {
  
    MetaspaceGtestContext& _context;
  
    Mutex* _lock;
    const ArenaGrowthPolicy* _growth_policy;
    SizeAtomicCounter _used_words_counter;
    MetaspaceArena* _arena;
  
!   void initialize(const ArenaGrowthPolicy* growth_policy, const char* name = "gtest-MetaspaceArena") {
      _growth_policy = growth_policy;
      _lock = new Mutex(Monitor::nosafepoint, "gtest-MetaspaceArenaTest_lock");
      // Lock during space creation, since this is what happens in the VM too
      //  (see ClassLoaderData::metaspace_non_null(), which we mimick here).
      {
        MutexLocker ml(_lock,  Mutex::_no_safepoint_check_flag);
!       _arena = new MetaspaceArena(&_context.cm(), _growth_policy, _lock, &_used_words_counter, name);
      }
      DEBUG_ONLY(_arena->verify());
  
    }
  
--- 49,29 ---
  using metaspace::MetaspaceArena;
  using metaspace::SizeAtomicCounter;
  using metaspace::Settings;
  using metaspace::ArenaStats;
  
  class MetaspaceArenaTestHelper {
  
    MetaspaceGtestContext& _context;
  
    Mutex* _lock;
    const ArenaGrowthPolicy* _growth_policy;
    SizeAtomicCounter _used_words_counter;
+   int _alignment_words;
    MetaspaceArena* _arena;
  
!   void initialize(const ArenaGrowthPolicy* growth_policy, int alignment_words,
+                   const char* name = "gtest-MetaspaceArena") {
      _growth_policy = growth_policy;
      _lock = new Mutex(Monitor::nosafepoint, "gtest-MetaspaceArenaTest_lock");
      // Lock during space creation, since this is what happens in the VM too
      //  (see ClassLoaderData::metaspace_non_null(), which we mimick here).
      {
        MutexLocker ml(_lock,  Mutex::_no_safepoint_check_flag);
!       _arena = new MetaspaceArena(&_context.cm(), _growth_policy, alignment_words, _lock, &_used_words_counter, name);
      }
      DEBUG_ONLY(_arena->verify());
  
    }
  

*** 83,19 ***
    MetaspaceArenaTestHelper(MetaspaceGtestContext& helper,
                              Metaspace::MetaspaceType space_type, bool is_class,
                              const char* name = "gtest-MetaspaceArena") :
      _context(helper)
    {
!     initialize(ArenaGrowthPolicy::policy_for_space_type(space_type, is_class), name);
    }
  
    // Create a helper; growth policy is directly specified
    MetaspaceArenaTestHelper(MetaspaceGtestContext& helper, const ArenaGrowthPolicy* growth_policy,
                             const char* name = "gtest-MetaspaceArena") :
      _context(helper)
    {
!     initialize(growth_policy, name);
    }
  
    ~MetaspaceArenaTestHelper() {
      delete_arena_with_tests();
      delete _lock;
--- 81,19 ---
    MetaspaceArenaTestHelper(MetaspaceGtestContext& helper,
                              Metaspace::MetaspaceType space_type, bool is_class,
                              const char* name = "gtest-MetaspaceArena") :
      _context(helper)
    {
!     initialize(ArenaGrowthPolicy::policy_for_space_type(space_type, is_class), metaspace::MetaspaceMinAlignmentWords, name);
    }
  
    // Create a helper; growth policy is directly specified
    MetaspaceArenaTestHelper(MetaspaceGtestContext& helper, const ArenaGrowthPolicy* growth_policy,
                             const char* name = "gtest-MetaspaceArena") :
      _context(helper)
    {
!     initialize(growth_policy, metaspace::MetaspaceMinAlignmentWords, name);
    }
  
    ~MetaspaceArenaTestHelper() {
      delete_arena_with_tests();
      delete _lock;

*** 279,11 ***
    size_t allocated = 0;
    while (allocated <= MAX_CHUNK_WORD_SIZE &&
           metaspace::InternalStats::num_chunks_enlarged() == n1) {
      size_t s = IntRange(32, 128).random_value();
      helper.allocate_from_arena_with_tests_expect_success(s);
!     allocated += metaspace::get_raw_word_size_for_requested_word_size(s);
    }
  
    EXPECT_GT(metaspace::InternalStats::num_chunks_enlarged(), n1);
  
  }
--- 277,11 ---
    size_t allocated = 0;
    while (allocated <= MAX_CHUNK_WORD_SIZE &&
           metaspace::InternalStats::num_chunks_enlarged() == n1) {
      size_t s = IntRange(32, 128).random_value();
      helper.allocate_from_arena_with_tests_expect_success(s);
!     allocated += metaspace::get_raw_word_size_for_requested_word_size(s, metaspace::MetaspaceMinAlignmentWords);
    }
  
    EXPECT_GT(metaspace::InternalStats::num_chunks_enlarged(), n1);
  
  }

*** 336,11 ***
  
    size_t allocated = 0;
    while (allocated <= MAX_CHUNK_WORD_SIZE) {
      size_t s = IntRange(32, 128).random_value();
      helper.allocate_from_arena_with_tests_expect_success(s);
!     allocated += metaspace::get_raw_word_size_for_requested_word_size(s);
      if (allocated <= MAX_CHUNK_WORD_SIZE) {
        // Chunk should have been enlarged in place
        ASSERT_EQ(1, helper.get_number_of_chunks());
      } else {
        // Next chunk should have started
--- 334,11 ---
  
    size_t allocated = 0;
    while (allocated <= MAX_CHUNK_WORD_SIZE) {
      size_t s = IntRange(32, 128).random_value();
      helper.allocate_from_arena_with_tests_expect_success(s);
!     allocated += metaspace::get_raw_word_size_for_requested_word_size(s, metaspace::MetaspaceMinAlignmentWords);
      if (allocated <= MAX_CHUNK_WORD_SIZE) {
        // Chunk should have been enlarged in place
        ASSERT_EQ(1, helper.get_number_of_chunks());
      } else {
        // Next chunk should have started

*** 593,11 ***
      if (!test_in_place_enlargement) {
        smhelper_harrasser.allocate_from_arena_with_tests_expect_success(alloc_words * 2);
      }
  
      smhelper.allocate_from_arena_with_tests_expect_success(alloc_words);
!     words_allocated += metaspace::get_raw_word_size_for_requested_word_size(alloc_words);
      num_allocated++;
  
      size_t used2 = 0, committed2 = 0, capacity2 = 0;
  
      smhelper.arena()->usage_numbers(&used2, &committed2, &capacity2);
--- 591,11 ---
      if (!test_in_place_enlargement) {
        smhelper_harrasser.allocate_from_arena_with_tests_expect_success(alloc_words * 2);
      }
  
      smhelper.allocate_from_arena_with_tests_expect_success(alloc_words);
!     words_allocated += metaspace::get_raw_word_size_for_requested_word_size(alloc_words, metaspace::MetaspaceMinAlignmentWords);
      num_allocated++;
  
      size_t used2 = 0, committed2 = 0, capacity2 = 0;
  
      smhelper.arena()->usage_numbers(&used2, &committed2, &capacity2);
< prev index next >