src/hotspot/share/memory/metaspace/occupancyMap.hpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 53244 9807daeb47c4
permissions -rw-r--r--
8231323: ProblemList jdk/jfr/jcmd/TestJcmdConfigure.java Reviewed-by: ysuenaga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50193
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     3
 * Copyright (c) 2018 SAP SE. All rights reserved.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     5
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     9
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    14
 * accompanied this code).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    15
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    19
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    22
 * questions.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    23
 *
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    24
 */
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    25
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    26
#ifndef SHARE_MEMORY_METASPACE_OCCUPANCYMAP_HPP
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    27
#define SHARE_MEMORY_METASPACE_OCCUPANCYMAP_HPP
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    28
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    29
#include "memory/allocation.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    30
#include "utilities/debug.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    32
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    33
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    34
namespace metaspace {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    35
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    36
class Metachunk;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    37
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    38
// Helper for Occupancy Bitmap. A type trait to give an all-bits-are-one-unsigned constant.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    39
template <typename T> struct all_ones  { static const T value; };
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    40
template <> struct all_ones <uint64_t> { static const uint64_t value = 0xFFFFFFFFFFFFFFFFULL; };
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    41
template <> struct all_ones <uint32_t> { static const uint32_t value = 0xFFFFFFFF; };
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    42
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    43
// The OccupancyMap is a bitmap which, for a given VirtualSpaceNode,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    44
// keeps information about
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    45
// - where a chunk starts
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    46
// - whether a chunk is in-use or free
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    47
// A bit in this bitmap represents one range of memory in the smallest
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    48
// chunk size (SpecializedChunk or ClassSpecializedChunk).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    49
class OccupancyMap : public CHeapObj<mtInternal> {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    50
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    51
  // The address range this map covers.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    52
  const MetaWord* const _reference_address;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    53
  const size_t _word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    54
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    55
  // The word size of a specialized chunk, aka the number of words one
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    56
  // bit in this map represents.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    57
  const size_t _smallest_chunk_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    58
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    59
  // map data
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    60
  // Data are organized in two bit layers:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    61
  // The first layer is the chunk-start-map. Here, a bit is set to mark
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    62
  // the corresponding region as the head of a chunk.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    63
  // The second layer is the in-use-map. Here, a set bit indicates that
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    64
  // the corresponding belongs to a chunk which is in use.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    65
  uint8_t* _map[2];
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    66
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    67
  enum { layer_chunk_start_map = 0, layer_in_use_map = 1 };
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    68
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    69
  // length, in bytes, of bitmap data
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    70
  size_t _map_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    71
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    72
  // Returns true if bit at position pos at bit-layer layer is set.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    73
  bool get_bit_at_position(unsigned pos, unsigned layer) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    74
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    75
    const unsigned byteoffset = pos / 8;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    76
    assert(byteoffset < _map_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    77
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    78
    const unsigned mask = 1 << (pos % 8);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    79
    return (_map[layer][byteoffset] & mask) > 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    80
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    81
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    82
  // Changes bit at position pos at bit-layer layer to value v.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    83
  void set_bit_at_position(unsigned pos, unsigned layer, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    84
    assert(layer == 0 || layer == 1, "Invalid layer %d", layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    85
    const unsigned byteoffset = pos / 8;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    86
    assert(byteoffset < _map_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    87
           "invalid byte offset (%u), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    88
    const unsigned mask = 1 << (pos % 8);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    89
    if (v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    90
      _map[layer][byteoffset] |= mask;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    91
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    92
      _map[layer][byteoffset] &= ~mask;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    93
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    94
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    95
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    96
  // Optimized case of is_any_bit_set_in_region for 32/64bit aligned access:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    97
  // pos is 32/64 aligned and num_bits is 32/64.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    98
  // This is the typical case when coalescing to medium chunks, whose size is
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    99
  // 32 or 64 times the specialized chunk size (depending on class or non class
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   100
  // case), so they occupy 64 bits which should be 64bit aligned, because
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   101
  // chunks are chunk-size aligned.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   102
  template <typename T>
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   103
  bool is_any_bit_set_in_region_3264(unsigned pos, unsigned num_bits, unsigned layer) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   104
    assert(_map_size > 0, "not initialized");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   105
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   106
    assert(pos % (sizeof(T) * 8) == 0, "Bit position must be aligned (%u).", pos);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   107
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u).", num_bits);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   108
    const size_t byteoffset = pos / 8;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   109
    assert(byteoffset <= (_map_size - sizeof(T)),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   110
           "Invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   111
    const T w = *(T*)(_map[layer] + byteoffset);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   112
    return w > 0 ? true : false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   113
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   114
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   115
  // Returns true if any bit in region [pos1, pos1 + num_bits) is set in bit-layer layer.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   116
  bool is_any_bit_set_in_region(unsigned pos, unsigned num_bits, unsigned layer) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   117
    if (pos % 32 == 0 && num_bits == 32) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   118
      return is_any_bit_set_in_region_3264<uint32_t>(pos, num_bits, layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   119
    } else if (pos % 64 == 0 && num_bits == 64) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   120
      return is_any_bit_set_in_region_3264<uint64_t>(pos, num_bits, layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   121
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   122
      for (unsigned n = 0; n < num_bits; n ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   123
        if (get_bit_at_position(pos + n, layer)) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   124
          return true;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   125
        }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   126
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   127
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   128
    return false;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   129
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   130
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   131
  // Returns true if any bit in region [p, p+word_size) is set in bit-layer layer.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   132
  bool is_any_bit_set_in_region(MetaWord* p, size_t word_size, unsigned layer) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   133
    assert(word_size % _smallest_chunk_word_size == 0,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   134
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   135
    const unsigned pos = get_bitpos_for_address(p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   136
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   137
    return is_any_bit_set_in_region(pos, num_bits, layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   138
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   139
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   140
  // Optimized case of set_bits_of_region for 32/64bit aligned access:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   141
  // pos is 32/64 aligned and num_bits is 32/64.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   142
  // This is the typical case when coalescing to medium chunks, whose size
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   143
  // is 32 or 64 times the specialized chunk size (depending on class or non
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   144
  // class case), so they occupy 64 bits which should be 64bit aligned,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   145
  // because chunks are chunk-size aligned.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   146
  template <typename T>
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   147
  void set_bits_of_region_T(unsigned pos, unsigned num_bits, unsigned layer, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   148
    assert(pos % (sizeof(T) * 8) == 0, "Bit position must be aligned to %u (%u).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   149
           (unsigned)(sizeof(T) * 8), pos);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   150
    assert(num_bits == (sizeof(T) * 8), "Number of bits incorrect (%u), expected %u.",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   151
           num_bits, (unsigned)(sizeof(T) * 8));
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   152
    const size_t byteoffset = pos / 8;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   153
    assert(byteoffset <= (_map_size - sizeof(T)),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   154
           "invalid byte offset (" SIZE_FORMAT "), map size is " SIZE_FORMAT ".", byteoffset, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   155
    T* const pw = (T*)(_map[layer] + byteoffset);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   156
    *pw = v ? all_ones<T>::value : (T) 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   157
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   158
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   159
  // Set all bits in a region starting at pos to a value.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   160
  void set_bits_of_region(unsigned pos, unsigned num_bits, unsigned layer, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   161
    assert(_map_size > 0, "not initialized");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   162
    assert(layer == 0 || layer == 1, "Invalid layer %d.", layer);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   163
    if (pos % 32 == 0 && num_bits == 32) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   164
      set_bits_of_region_T<uint32_t>(pos, num_bits, layer, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   165
    } else if (pos % 64 == 0 && num_bits == 64) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   166
      set_bits_of_region_T<uint64_t>(pos, num_bits, layer, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   167
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   168
      for (unsigned n = 0; n < num_bits; n ++) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   169
        set_bit_at_position(pos + n, layer, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   170
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   171
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   172
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   173
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   174
  // Helper: sets all bits in a region [p, p+word_size).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   175
  void set_bits_of_region(MetaWord* p, size_t word_size, unsigned layer, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   176
    assert(word_size % _smallest_chunk_word_size == 0,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   177
        "Region size " SIZE_FORMAT " not a multiple of smallest chunk size.", word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   178
    const unsigned pos = get_bitpos_for_address(p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   179
    const unsigned num_bits = (unsigned) (word_size / _smallest_chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   180
    set_bits_of_region(pos, num_bits, layer, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   181
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   182
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   183
  // Helper: given an address, return the bit position representing that address.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   184
  unsigned get_bitpos_for_address(const MetaWord* p) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   185
    assert(_reference_address != NULL, "not initialized");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   186
    assert(p >= _reference_address && p < _reference_address + _word_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   187
           "Address %p out of range for occupancy map [%p..%p).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   188
            p, _reference_address, _reference_address + _word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   189
    assert(is_aligned(p, _smallest_chunk_word_size * sizeof(MetaWord)),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   190
           "Address not aligned (%p).", p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   191
    const ptrdiff_t d = (p - _reference_address) / _smallest_chunk_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   192
    assert(d >= 0 && (size_t)d < _map_size * 8, "Sanity.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   193
    return (unsigned) d;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   194
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   195
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   196
 public:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   197
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   198
  OccupancyMap(const MetaWord* reference_address, size_t word_size, size_t smallest_chunk_word_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   199
  ~OccupancyMap();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   200
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   201
  // Returns true if at address x a chunk is starting.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   202
  bool chunk_starts_at_address(MetaWord* p) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   203
    const unsigned pos = get_bitpos_for_address(p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   204
    return get_bit_at_position(pos, layer_chunk_start_map);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   205
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   206
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   207
  void set_chunk_starts_at_address(MetaWord* p, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   208
    const unsigned pos = get_bitpos_for_address(p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   209
    set_bit_at_position(pos, layer_chunk_start_map, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   210
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   211
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   212
  // Removes all chunk-start-bits inside a region, typically as a
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   213
  // result of a chunk merge.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   214
  void wipe_chunk_start_bits_in_region(MetaWord* p, size_t word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   215
    set_bits_of_region(p, word_size, layer_chunk_start_map, false);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   216
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   217
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   218
  // Returns true if there are life (in use) chunks in the region limited
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   219
  // by [p, p+word_size).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   220
  bool is_region_in_use(MetaWord* p, size_t word_size) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   221
    return is_any_bit_set_in_region(p, word_size, layer_in_use_map);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   222
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   223
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   224
  // Marks the region starting at p with the size word_size as in use
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   225
  // or free, depending on v.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   226
  void set_region_in_use(MetaWord* p, size_t word_size, bool v) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   227
    set_bits_of_region(p, word_size, layer_in_use_map, v);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   228
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   229
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   230
  // Verify occupancy map for the address range [from, to).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   231
  // We need to tell it the address range, because the memory the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   232
  // occupancy map is covering may not be fully comitted yet.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   233
  DEBUG_ONLY(void verify(MetaWord* from, MetaWord* to);)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   234
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   235
  // Verify that a given chunk is correctly accounted for in the bitmap.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   236
  DEBUG_ONLY(void verify_for_chunk(Metachunk* chunk);)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   237
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   238
};
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   239
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   240
} // namespace metaspace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   241
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50193
diff changeset
   242
#endif // SHARE_MEMORY_METASPACE_OCCUPANCYMAP_HPP