src/hotspot/share/memory/metaspace/blockListArray.inline.hpp
author stuefe
Mon, 25 Nov 2019 16:35:14 +0100
branchstuefe-new-metaspace-branch
changeset 59257 990b1fed3b47
parent 59238 6ce12ce00d3e
child 59271 1558266946de
permissions -rw-r--r--
Improve comments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59238
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     1
/*
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2019, SAP SE. All rights reserved.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     3
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     5
 *
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
     9
 *
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    14
 * accompanied this code).
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    15
 *
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    19
 *
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    22
 * questions.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    23
 *
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    24
 */
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    25
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    26
#ifndef SHARE_MEMORY_METASPACE_BLOCKLISTARRAY_INLINE_HPP
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    27
#define SHARE_MEMORY_METASPACE_BLOCKLISTARRAY_INLINE_HPP
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    28
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    29
#include "memory/allocation.hpp"
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    30
#include "memory/metaspace/blockListArray.hpp"
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    31
#include "utilities/debug.hpp"
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    32
#include "utilities/globalDefinitions.hpp"
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    33
#include "utilities/ostream.hpp"
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    34
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    35
namespace metaspace {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    36
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    37
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    38
// Starting at (including) pos, find the position of the next 1 bit.
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    39
// Return -1 if not found.
59257
990b1fed3b47 Improve comments
stuefe
parents: 59238
diff changeset
    40
int BlockListArrayMask::find_next_set_bit(int pos) const {
59238
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    41
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    42
  if (get_bit(pos)) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    43
    return pos;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    44
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    45
  mask_type m2 = _mask;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    46
  int pos2 = pos + 1;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    47
  m2 >>= pos2;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    48
  if (m2 > 0) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    49
    while ((m2 & (mask_type)1) == 0) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    50
      m2 >>= 1;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    51
      pos2 ++;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    52
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    53
    return pos2;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    54
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    55
  return -1;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    56
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    57
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    58
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    59
///////////////////////////////////////
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    60
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    61
template <size_t min_word_size, size_t spread, int num_bins>
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    62
void BlockListArray<min_word_size, spread, num_bins>::put(MetaWord* p, size_t word_size) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    63
  assert(word_size >= minimal_word_size() && word_size < maximal_word_size(), "Invalid word size");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    64
  block_t* b = (block_t*)p;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    65
  int bno = bin_for_size(word_size);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    66
  assert(bno >= 0 && bno < num_bins, "Sanity");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    67
  assert(b != _bins[bno], "double add?");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    68
  b->next = _bins[bno];
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    69
  b->size = word_size;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    70
  _bins[bno] = b;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    71
  _map.set_bit(bno);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    72
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    73
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    74
template <size_t min_word_size, size_t spread, int num_bins>
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    75
block_t* BlockListArray<min_word_size, spread, num_bins>::get(size_t word_size) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    76
  // Adjust size for spread (we need the bin number which guarantees word_size).
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    77
  word_size += (spread - 1);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    78
  if (word_size >= maximal_word_size()) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    79
    return NULL;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    80
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    81
  int bno = bin_for_size(word_size);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    82
  bno = _map.find_next_set_bit(bno);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    83
  if (bno != -1) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    84
    assert(bno >= 0 && bno < num_bins, "Sanity");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    85
    assert(_bins[bno] != NULL, "Sanity");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    86
    block_t* b = _bins[bno];
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    87
    _bins[bno] = b->next;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    88
    if (_bins[bno] == NULL) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    89
      _map.clr_bit(bno);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    90
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    91
    return b;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    92
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    93
  return NULL;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    94
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    95
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    96
#ifdef ASSERT
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    97
template <size_t min_word_size, size_t spread, int num_bins>
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    98
void BlockListArray<min_word_size, spread, num_bins>::verify() const {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
    99
  for (int i = 0; i < num_bins; i ++) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   100
    assert(_map.get_bit(i) == (_bins[i] != NULL), "Sanity");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   101
    const size_t min_size = minimal_word_size_in_bin(i);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   102
    const size_t max_size = maximal_word_size_in_bin(i);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   103
    for(block_t* b = _bins[i]; b != NULL; b = b->next) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   104
      assert(b->size >= min_size && b->size < max_size, "Sanity");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   105
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   106
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   107
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   108
#endif // ASSERT
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   109
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   110
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   111
template <size_t min_word_size, size_t spread, int num_bins>
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   112
void BlockListArray<min_word_size, spread, num_bins>::statistics(block_stats_t* stats) const {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   113
  for (int i = 0; i < num_bins; i ++) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   114
    for(block_t* b = _bins[i]; b != NULL; b = b->next) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   115
      stats->num_blocks ++;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   116
      stats->word_size += b->size;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   117
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   118
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   119
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   120
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   121
template <size_t min_word_size, size_t spread, int num_bins>
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   122
void BlockListArray<min_word_size, spread, num_bins>::print(outputStream* st) const {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   123
  bool first = true;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   124
  for (int i = 0; i < num_bins; i ++) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   125
    int n = 0;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   126
    for(block_t* b = _bins[i]; b != NULL; b = b->next) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   127
      n ++;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   128
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   129
    if (n > 0) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   130
      if (!first) {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   131
        st->print(", ");
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   132
      } else {
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   133
        first = false;
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   134
      }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   135
      st->print(SIZE_FORMAT "=%d", minimal_word_size_in_bin(i), n);
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   136
    }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   137
  }
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   138
}
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   139
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   140
} // namespace metaspace
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   141
6ce12ce00d3e Factor out block list array from LOM since we may use it elsewhere
stuefe
parents:
diff changeset
   142
#endif // SHARE_MEMORY_METASPACE_BLOCKLISTARRAY_INLINE_HPP