src/hotspot/share/memory/metaspace/leftOverBins.inline.hpp
branchstuefe-new-metaspace-branch
changeset 59238 6ce12ce00d3e
parent 59155 b537e6386306
equal deleted inserted replaced
59155:b537e6386306 59238:6ce12ce00d3e
    25 
    25 
    26 #ifndef SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
    26 #ifndef SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
    27 #define SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
    27 #define SHARE_MEMORY_METASPACE_LEFTOVERBINS_INLINE_HPP
    28 
    28 
    29 #include "memory/allocation.hpp"
    29 #include "memory/allocation.hpp"
       
    30 #include "memory/metaspace/blockListArray.inline.hpp"
    30 #include "memory/metaspace/leftOverBins.hpp"
    31 #include "memory/metaspace/leftOverBins.hpp"
    31 #include "utilities/debug.hpp"
    32 #include "utilities/debug.hpp"
    32 #include "utilities/globalDefinitions.hpp"
    33 #include "utilities/globalDefinitions.hpp"
    33 #include "utilities/ostream.hpp"
    34 #include "utilities/ostream.hpp"
    34 
    35 
    35 namespace metaspace {
    36 namespace metaspace {
    36 
       
    37 
       
    38 // Starting at (including) pos, find the position of the next 1 bit.
       
    39 // Return -1 if not found.
       
    40 int BinMap::find_next_set_bit(int pos) const {
       
    41   if (get_bit(pos)) {
       
    42     return pos;
       
    43   }
       
    44   mask_type m2 = _mask;
       
    45   int pos2 = pos + 1;
       
    46   m2 >>= pos2;
       
    47   if (m2 > 0) {
       
    48     while ((m2 & (mask_type)1) == 0) {
       
    49       m2 >>= 1;
       
    50       pos2 ++;
       
    51     }
       
    52     return pos2;
       
    53   }
       
    54   return -1;
       
    55 }
       
    56 
       
    57 ///////////////////////////////////////
       
    58 
       
    59 template <size_t min_word_size, size_t spread, int num_bins>
       
    60 void Bins<min_word_size, spread, num_bins>::put(MetaWord* p, size_t word_size) {
       
    61   assert(word_size >= minimal_word_size() && word_size < maximal_word_size(), "Invalid word size");
       
    62   block_t* b = (block_t*)p;
       
    63   int bno = bin_for_size(word_size);
       
    64   assert(bno >= 0 && bno < num_bins, "Sanity");
       
    65   assert(b != _bins[bno], "double add?");
       
    66   b->next = _bins[bno];
       
    67   b->size = word_size;
       
    68   _bins[bno] = b;
       
    69   _mask.set_bit(bno);
       
    70 }
       
    71 
       
    72 template <size_t min_word_size, size_t spread, int num_bins>
       
    73 block_t* Bins<min_word_size, spread, num_bins>::get(size_t word_size) {
       
    74   // Adjust size for spread (we need the bin number which guarantees word_size).
       
    75   word_size += (spread - 1);
       
    76   if (word_size >= maximal_word_size()) {
       
    77     return NULL;
       
    78   }
       
    79   int bno = bin_for_size(word_size);
       
    80   bno = _mask.find_next_set_bit(bno);
       
    81   if (bno != -1) {
       
    82     assert(bno >= 0 && bno < num_bins, "Sanity");
       
    83     assert(_bins[bno] != NULL, "Sanity");
       
    84     block_t* b = _bins[bno];
       
    85     _bins[bno] = b->next;
       
    86     if (_bins[bno] == NULL) {
       
    87       _mask.clr_bit(bno);
       
    88     }
       
    89     return b;
       
    90   }
       
    91   return NULL;
       
    92 }
       
    93 
       
    94 #ifdef ASSERT
       
    95 template <size_t min_word_size, size_t spread, int num_bins>
       
    96 void Bins<min_word_size, spread, num_bins>::verify() const {
       
    97   for (int i = 0; i < num_bins; i ++) {
       
    98     assert(_mask.get_bit(i) == (_bins[i] != NULL), "Sanity");
       
    99     const size_t min_size = minimal_word_size_in_bin(i);
       
   100     const size_t max_size = maximal_word_size_in_bin(i);
       
   101     for(block_t* b = _bins[i]; b != NULL; b = b->next) {
       
   102       assert(b->size >= min_size && b->size < max_size, "Sanity");
       
   103     }
       
   104   }
       
   105 }
       
   106 #endif // ASSERT
       
   107 
       
   108 
       
   109 template <size_t min_word_size, size_t spread, int num_bins>
       
   110 void Bins<min_word_size, spread, num_bins>::statistics(block_stats_t* stats) const {
       
   111   for (int i = 0; i < num_bins; i ++) {
       
   112     for(block_t* b = _bins[i]; b != NULL; b = b->next) {
       
   113       stats->num_blocks ++;
       
   114       stats->word_size += b->size;
       
   115     }
       
   116   }
       
   117 }
       
   118 
       
   119 template <size_t min_word_size, size_t spread, int num_bins>
       
   120 void Bins<min_word_size, spread, num_bins>::print(outputStream* st) const {
       
   121   bool first = true;
       
   122   for (int i = 0; i < num_bins; i ++) {
       
   123     int n = 0;
       
   124     for(block_t* b = _bins[i]; b != NULL; b = b->next) {
       
   125       n ++;
       
   126     }
       
   127     if (n > 0) {
       
   128       if (!first) {
       
   129         st->print(", ");
       
   130       } else {
       
   131         first = false;
       
   132       }
       
   133       st->print(SIZE_FORMAT "=%d", minimal_word_size_in_bin(i), n);
       
   134     }
       
   135   }
       
   136 }
       
   137 
       
   138 
    37 
   139 
    38 
   140 ///////////////////////////////////////
    39 ///////////////////////////////////////
   141 
    40 
   142 // Take the topmost block from the large block reserve list
    41 // Take the topmost block from the large block reserve list