< prev index next >

src/hotspot/share/memory/metaspace/binList.hpp

Print this page
@@ -26,20 +26,20 @@
  
  #ifndef SHARE_MEMORY_METASPACE_BINLIST_HPP
  #define SHARE_MEMORY_METASPACE_BINLIST_HPP
  
  #include "memory/metaspace/counters.hpp"
+ #include "memory/metaspace/metablock.hpp"
  #include "memory/metaspace/metaspaceCommon.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/globalDefinitions.hpp"
  
  namespace metaspace {
  
  // BinList is a data structure to manage small to very small memory blocks
- // (only a few words). It is used to manage deallocated blocks - see
- // class FreeBlocks.
+ // (only a few words). It is used to manage deallocated small blocks.
  
  // Memory blocks are kept in a vector of linked lists of equi-sized blocks:
  //
  // wordsize
  //

@@ -141,11 +141,14 @@
      for (int i = 0; i < num_lists; i++) {
        _blocks[i] = nullptr;
      }
    }
  
-   void add_block(MetaWord* p, size_t word_size) {
+   void add_block(MetaBlock mb) {
+     assert(!mb.is_empty(), "Don't add empty blocks");
+     const size_t word_size = mb.word_size();
+     MetaWord* const p = mb.base();
      assert(word_size >= MinWordSize &&
             word_size <= MaxWordSize, "bad block size");
      DEBUG_ONLY(write_canary(p, word_size);)
      const int index = index_for_word_size(word_size);
      Block* old_head = _blocks[index];

@@ -153,30 +156,28 @@
      _blocks[index] = new_head;
      _counter.add(word_size);
    }
  
    // Given a word_size, searches and returns a block of at least that size.
-   // Block may be larger. Real block size is returned in *p_real_word_size.
-   MetaWord* remove_block(size_t word_size, size_t* p_real_word_size) {
+   // Block may be larger.
+   MetaBlock remove_block(size_t word_size) {
      assert(word_size >= MinWordSize &&
             word_size <= MaxWordSize, "bad block size " SIZE_FORMAT ".", word_size);
+     MetaBlock result;
      int index = index_for_word_size(word_size);
      index = index_for_next_non_empty_list(index);
      if (index != -1) {
        Block* b = _blocks[index];
        const size_t real_word_size = word_size_for_index(index);
        assert(b != nullptr, "Sanity");
        assert(check_canary(b, real_word_size),
               "bad block in list[%d] (" BLOCK_FORMAT ")", index, BLOCK_FORMAT_ARGS(b, real_word_size));
        _blocks[index] = b->_next;
        _counter.sub(real_word_size);
-       *p_real_word_size = real_word_size;
-       return (MetaWord*)b;
-     } else {
-       *p_real_word_size = 0;
-       return nullptr;
+       result = MetaBlock((MetaWord*)b, real_word_size);
      }
+     return result;
    }
  
    // Returns number of blocks in this structure
    unsigned count() const { return _counter.count(); }
  

@@ -189,14 +190,18 @@
    void verify() const {
      MemRangeCounter local_counter;
      for (int i = 0; i < num_lists; i++) {
        const size_t s = word_size_for_index(i);
        int pos = 0;
+       Block* b_last = nullptr; // catch simple circularities
        for (Block* b = _blocks[i]; b != nullptr; b = b->_next, pos++) {
          assert(check_canary(b, s), "");
+         assert(b != b_last, "Circle");
          local_counter.add(s);
+         b_last = b;
        }
+       if (UseNewCode)printf("\n");
      }
      local_counter.check(_counter);
    }
  #endif // ASSERT
  
< prev index next >