src/hotspot/share/memory/metaspace/occupancyMap.cpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 50193 49c3e91c424f
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
/*
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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
#include "precompiled.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    27
#include "utilities/debug.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    29
#include "memory/metaspace/metachunk.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    30
#include "memory/metaspace/occupancyMap.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    31
#include "runtime/os.hpp"
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    32
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    33
namespace metaspace {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    34
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    35
OccupancyMap::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
    36
            _reference_address(reference_address), _word_size(word_size),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    37
            _smallest_chunk_word_size(smallest_chunk_word_size)
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    38
{
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    39
  assert(reference_address != NULL, "invalid reference address");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    40
  assert(is_aligned(reference_address, smallest_chunk_word_size),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    41
      "Reference address not aligned to smallest chunk size.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    42
  assert(is_aligned(word_size, smallest_chunk_word_size),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    43
      "Word_size shall be a multiple of the smallest chunk size.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    44
  // Calculate bitmap size: one bit per smallest_chunk_word_size'd area.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    45
  size_t num_bits = word_size / smallest_chunk_word_size;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    46
  _map_size = (num_bits + 7) / 8;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    47
  assert(_map_size * 8 >= num_bits, "sanity");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    48
  _map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    49
  _map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    50
  assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    51
  memset(_map[1], 0, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    52
  memset(_map[0], 0, _map_size);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    53
  // Sanity test: the first respectively last possible chunk start address in
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    54
  // the covered range shall map to the first and last bit in the bitmap.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    55
  assert(get_bitpos_for_address(reference_address) == 0,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    56
      "First chunk address in range must map to fist bit in bitmap.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    57
  assert(get_bitpos_for_address(reference_address + word_size - smallest_chunk_word_size) == num_bits - 1,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    58
      "Last chunk address in range must map to last bit in bitmap.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    59
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    60
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    61
OccupancyMap::~OccupancyMap() {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    62
  os::free(_map[0]);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    63
  os::free(_map[1]);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    64
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    65
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    66
#ifdef ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    67
// Verify occupancy map for the address range [from, to).
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    68
// We need to tell it the address range, because the memory the
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    69
// occupancy map is covering may not be fully comitted yet.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    70
void OccupancyMap::verify(MetaWord* from, MetaWord* to) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    71
  Metachunk* chunk = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    72
  int nth_bit_for_chunk = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    73
  MetaWord* chunk_end = NULL;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    74
  for (MetaWord* p = from; p < to; p += _smallest_chunk_word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    75
    const unsigned pos = get_bitpos_for_address(p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    76
    // Check the chunk-starts-info:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    77
    if (get_bit_at_position(pos, layer_chunk_start_map)) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    78
      // Chunk start marked in bitmap.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    79
      chunk = (Metachunk*) p;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    80
      if (chunk_end != NULL) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    81
        assert(chunk_end == p, "Unexpected chunk start found at %p (expected "
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    82
            "the next chunk to start at %p).", p, chunk_end);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    83
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    84
      assert(chunk->is_valid_sentinel(), "Invalid chunk at address %p.", p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    85
      if (chunk->get_chunk_type() != HumongousIndex) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    86
        guarantee(is_aligned(p, chunk->word_size()), "Chunk %p not aligned.", p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    87
      }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    88
      chunk_end = p + chunk->word_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    89
      nth_bit_for_chunk = 0;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    90
      assert(chunk_end <= to, "Chunk end overlaps test address range.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    91
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    92
      // No chunk start marked in bitmap.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    93
      assert(chunk != NULL, "Chunk should start at start of address range.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    94
      assert(p < chunk_end, "Did not find expected chunk start at %p.", p);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    95
      nth_bit_for_chunk ++;
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    96
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    97
    // Check the in-use-info:
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    98
    const bool in_use_bit = get_bit_at_position(pos, layer_in_use_map);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
    99
    if (in_use_bit) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   100
      assert(!chunk->is_tagged_free(), "Chunk %p: marked in-use in map but is free (bit %u).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   101
          chunk, nth_bit_for_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   102
    } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   103
      assert(chunk->is_tagged_free(), "Chunk %p: marked free in map but is in use (bit %u).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   104
          chunk, nth_bit_for_chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   105
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   106
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   107
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   108
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   109
// Verify that a given chunk is correctly accounted for in the bitmap.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   110
void OccupancyMap::verify_for_chunk(Metachunk* chunk) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   111
  assert(chunk_starts_at_address((MetaWord*) chunk),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   112
      "No chunk start marked in map for chunk %p.", chunk);
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   113
  // For chunks larger than the minimal chunk size, no other chunk
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   114
  // must start in its area.
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   115
  if (chunk->word_size() > _smallest_chunk_word_size) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   116
    assert(!is_any_bit_set_in_region(((MetaWord*) chunk) + _smallest_chunk_word_size,
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   117
        chunk->word_size() - _smallest_chunk_word_size, layer_chunk_start_map),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   118
        "No chunk must start within another chunk.");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   119
  }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   120
  if (!chunk->is_tagged_free()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   121
    assert(is_region_in_use((MetaWord*)chunk, chunk->word_size()),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   122
        "Chunk %p is in use but marked as free in map (%d %d).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   123
        chunk, chunk->get_chunk_type(), chunk->get_origin());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   124
  } else {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   125
    assert(!is_region_in_use((MetaWord*)chunk, chunk->word_size()),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   126
        "Chunk %p is free but marked as in-use in map (%d %d).",
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   127
        chunk, chunk->get_chunk_type(), chunk->get_origin());
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   128
  }
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
#endif // ASSERT
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   132
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   133
} // namespace metaspace
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   134
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents:
diff changeset
   135