< prev index next >

src/hotspot/share/memory/metaspace/testHelpers.cpp

Print this page
@@ -52,27 +52,31 @@
    delete _lock;
  }
  
  MetaWord* MetaspaceTestArena::allocate(size_t word_size) {
    MutexLocker fcl(_lock, Mutex::_no_safepoint_check_flag);
-   return _arena->allocate(word_size);
+   MetaBlock result, wastage;
+   result = _arena->allocate(word_size, wastage);
+   if (wastage.is_nonempty()) {
+     _arena->deallocate(wastage);
+   }
+   return result.base();
  }
  
  void MetaspaceTestArena::deallocate(MetaWord* p, size_t word_size) {
    MutexLocker fcl(_lock, Mutex::_no_safepoint_check_flag);
-   return _arena->deallocate(p, word_size);
+   _arena->deallocate(MetaBlock(p, word_size));
  }
  
  ///// MetaspaceTestArea //////
  
  MetaspaceTestContext::MetaspaceTestContext(const char* name, size_t commit_limit, size_t reserve_limit) :
    _name(name),
    _reserve_limit(reserve_limit),
    _commit_limit(commit_limit),
    _context(nullptr),
    _commit_limiter(commit_limit == 0 ? max_uintx : commit_limit), // commit_limit == 0 -> no limit
-   _used_words_counter(),
    _rs()
  {
    assert(is_aligned(reserve_limit, Metaspace::reserve_alignment_words()), "reserve_limit (" SIZE_FORMAT ") "
                      "not aligned to metaspace reserve alignment (" SIZE_FORMAT ")",
                      reserve_limit, Metaspace::reserve_alignment_words());

@@ -101,11 +105,11 @@
    const ArenaGrowthPolicy* growth_policy = ArenaGrowthPolicy::policy_for_space_type(type, false);
    Mutex* lock = new Mutex(Monitor::nosafepoint, "MetaspaceTestArea_lock");
    MetaspaceArena* arena = nullptr;
    {
      MutexLocker ml(lock,  Mutex::_no_safepoint_check_flag);
-     arena = new MetaspaceArena(_context->cm(), growth_policy, &_used_words_counter, _name);
+     arena = new MetaspaceArena(_context, growth_policy, Metaspace::min_allocation_alignment_words, _name);
    }
    return new MetaspaceTestArena(lock, arena);
  }
  
  void MetaspaceTestContext::purge_area() {

@@ -122,7 +126,20 @@
  
  void MetaspaceTestContext::print_on(outputStream* st) const {
    _context->print_on(st);
  }
  
+ size_t MetaspaceTestContext::used_words() const {
+   return _context->used_words_counter()->get();
+ }
+ 
+ size_t MetaspaceTestContext::committed_words() const {
+   assert(_commit_limiter.committed_words() == _context->committed_words(), "Sanity");
+   return _context->committed_words();
+ }
+ 
+ size_t MetaspaceTestContext::reserved_words() const {
+   return _context->reserved_words();
+ }
+ 
  } // namespace metaspace
  
< prev index next >