< prev index next >

test/hotspot/gtest/metaspace/test_metaspacearena_stress.cpp

Print this page
*** 24,12 ***
--- 24,14 ---
   */
  
  #include "precompiled.hpp"
  #include "memory/metaspace/chunkManager.hpp"
  #include "memory/metaspace/counters.hpp"
+ #include "memory/metaspace/metablock.hpp"
  #include "memory/metaspace/metaspaceArena.hpp"
  #include "memory/metaspace/metaspaceArenaGrowthPolicy.hpp"
+ #include "memory/metaspace/metaspaceContext.hpp"
  #include "memory/metaspace/metaspaceSettings.hpp"
  #include "memory/metaspace/metaspaceStatistics.hpp"
  #include "runtime/mutexLocker.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/globalDefinitions.hpp"

*** 41,11 ***
--- 43,13 ---
  using metaspace::AllocationAlignmentByteSize;
  using metaspace::ArenaGrowthPolicy;
  using metaspace::ChunkManager;
  using metaspace::IntCounter;
  using metaspace::MemRangeCounter;
+ using metaspace::MetaBlock;
  using metaspace::MetaspaceArena;
+ using metaspace::MetaspaceContext;
  using metaspace::SizeAtomicCounter;
  using metaspace::ArenaStats;
  using metaspace::InUseChunkStats;
  
  // Little randomness helper

*** 124,20 ***
  
  public:
  
    MetaspaceArena* arena() { return _arena; }
  
!   MetaspaceArenaTestBed(ChunkManager* cm, const ArenaGrowthPolicy* alloc_sequence,
!                         SizeAtomicCounter* used_words_counter, SizeRange allocation_range) :
!     _arena(nullptr),
!     _allocation_range(allocation_range),
!     _size_of_last_failed_allocation(0),
!     _allocations(nullptr),
-     _alloc_count(),
-     _dealloc_count()
    {
!     _arena = new MetaspaceArena(cm, alloc_sequence, used_words_counter, "gtest-MetaspaceArenaTestBed-sm");
    }
  
    ~MetaspaceArenaTestBed() {
  
      verify_arena_statistics();
--- 128,18 ---
  
  public:
  
    MetaspaceArena* arena() { return _arena; }
  
!   MetaspaceArenaTestBed(MetaspaceContext* context, const ArenaGrowthPolicy* growth_policy,
!                         size_t allocation_alignment_words, SizeRange allocation_range)
!     : _arena(nullptr)
!     , _allocation_range(allocation_range)
!     , _size_of_last_failed_allocation(0)
!     , _allocations(nullptr)
    {
!     _arena = new MetaspaceArena(context, growth_policy, Metaspace::min_allocation_alignment_words, "gtest-MetaspaceArenaTestBed-sm");
    }
  
    ~MetaspaceArenaTestBed() {
  
      verify_arena_statistics();

*** 163,17 ***
    size_t size_of_last_failed_allocation() const { return _size_of_last_failed_allocation; }
  
    // Allocate a random amount. Return false if the allocation failed.
    bool checked_random_allocate() {
      size_t word_size = 1 + _allocation_range.random_value();
!     MetaWord* p = _arena->allocate(word_size);
!     if (p != nullptr) {
!       EXPECT_TRUE(is_aligned(p, AllocationAlignmentByteSize));
  
        allocation_t* a = NEW_C_HEAP_OBJ(allocation_t, mtInternal);
        a->word_size = word_size;
!       a->p = p;
        a->mark();
        a->next = _allocations;
        _allocations = a;
        _alloc_count.add(word_size);
        if ((_alloc_count.count() % 20) == 0) {
--- 165,24 ---
    size_t size_of_last_failed_allocation() const { return _size_of_last_failed_allocation; }
  
    // Allocate a random amount. Return false if the allocation failed.
    bool checked_random_allocate() {
      size_t word_size = 1 + _allocation_range.random_value();
!     MetaBlock wastage;
!     MetaBlock bl = _arena->allocate(word_size, wastage);
!     // We only expect wastage if either alignment was not met or the chunk remainder
+     // was not large enough.
+     if (wastage.is_nonempty()) {
+       _arena->deallocate(wastage);
+       wastage.reset();
+     }
+     if (bl.is_nonempty()) {
+       EXPECT_TRUE(is_aligned(bl.base(), AllocationAlignmentByteSize));
  
        allocation_t* a = NEW_C_HEAP_OBJ(allocation_t, mtInternal);
        a->word_size = word_size;
!       a->p = bl.base();
        a->mark();
        a->next = _allocations;
        _allocations = a;
        _alloc_count.add(word_size);
        if ((_alloc_count.count() % 20) == 0) {

*** 193,11 ***
      while (a && a->p != nullptr && os::random() % 10 != 0) {
        a = a->next;
      }
      if (a != nullptr && a->p != nullptr) {
        a->verify();
!       _arena->deallocate(a->p, a->word_size);
        _dealloc_count.add(a->word_size);
        a->p = nullptr; a->word_size = 0;
        if ((_dealloc_count.count() % 20) == 0) {
          verify_arena_statistics();
          DEBUG_ONLY(_arena->verify();)
--- 202,11 ---
      while (a && a->p != nullptr && os::random() % 10 != 0) {
        a = a->next;
      }
      if (a != nullptr && a->p != nullptr) {
        a->verify();
!       _arena->deallocate(MetaBlock(a->p, a->word_size));
        _dealloc_count.add(a->word_size);
        a->p = nullptr; a->word_size = 0;
        if ((_dealloc_count.count() % 20) == 0) {
          verify_arena_statistics();
          DEBUG_ONLY(_arena->verify();)

*** 218,12 ***
  
    //////// Bed creation, destruction ///////
  
    void create_new_test_bed_at(int slotindex, const ArenaGrowthPolicy* growth_policy, SizeRange allocation_range) {
      DEBUG_ONLY(_testbeds.check_slot_is_null(slotindex));
!     MetaspaceArenaTestBed* bed = new MetaspaceArenaTestBed(&_context.cm(), growth_policy,
!                                                        &_used_words_counter, allocation_range);
      _testbeds.set_at(slotindex, bed);
      _num_beds.increment();
    }
  
    void create_random_test_bed_at(int slotindex) {
--- 227,12 ---
  
    //////// Bed creation, destruction ///////
  
    void create_new_test_bed_at(int slotindex, const ArenaGrowthPolicy* growth_policy, SizeRange allocation_range) {
      DEBUG_ONLY(_testbeds.check_slot_is_null(slotindex));
!     MetaspaceArenaTestBed* bed = new MetaspaceArenaTestBed(_context.context(), growth_policy,
!         Metaspace::min_allocation_alignment_words, allocation_range);
      _testbeds.set_at(slotindex, bed);
      _num_beds.increment();
    }
  
    void create_random_test_bed_at(int slotindex) {
< prev index next >