src/hotspot/share/memory/metaspace/commitMask.hpp
author stuefe
Wed, 16 Oct 2019 16:10:24 +0200
branchstuefe-new-metaspace-branch
changeset 58646 bcdba1c9f1fe
parent 58063 bdf136b8ae0e
child 58683 2d5dd194c65c
permissions -rw-r--r--
Remove experimental MetaspaceSeparateMicroCLDs feature, since its effect was underwhelming
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58063
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     1
/*
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2019, SAP SE. All rights reserved.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     3
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     5
 *
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
     9
 *
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    14
 * accompanied this code).
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    15
 *
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    19
 *
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    22
 * questions.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    23
 *
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    24
 */
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    25
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    26
#ifndef SHARE_MEMORY_METASPACE_COMMITMASK_HPP
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    27
#define SHARE_MEMORY_METASPACE_COMMITMASK_HPP
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    28
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    29
#include "utilities/debug.hpp"
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    30
#include "utilities/bitMap.hpp"
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    32
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    33
class outputStream;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    34
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    35
namespace metaspace {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    36
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    37
// A bitmap covering a range of metaspace; each bit in this mask corresponds to
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    38
//
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    39
class CommitMask : public CHeapBitMap {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    40
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    41
  const MetaWord* const _base;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    42
  const size_t _word_size;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    43
  const size_t _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    44
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    45
  // Given an offset, in words, into the area, return the number of the bit
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    46
  // covering it.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    47
  static idx_t bitno_for_word_offset(size_t offset, size_t words_per_bit) {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    48
    return offset / words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    49
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    50
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    51
  idx_t bitno_for_address(const MetaWord* p) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    52
    // Note: we allow one-beyond since this is a typical need.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    53
    assert(p >= _base && p <= _base + _word_size, "Invalid address");
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    54
    const size_t off = p - _base;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    55
    return bitno_for_word_offset(off, _words_per_bit);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    56
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    57
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    58
  static idx_t mask_size(size_t word_size, size_t words_per_bit) {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    59
    return bitno_for_word_offset(word_size, words_per_bit);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    60
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    61
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    62
  struct BitCounterClosure : public BitMapClosure {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    63
    idx_t cnt;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    64
    bool do_bit(BitMap::idx_t offset) { cnt ++; return true; }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    65
  };
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    66
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    67
  // Missing from BitMap.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    68
  // Count 1 bits in range [start, end).
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    69
  idx_t count_one_bits_in_range(idx_t start, idx_t end) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    70
    assert(start < end, "Zero range");
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    71
    // TODO: This can be done more efficiently.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    72
    BitCounterClosure bcc;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    73
    bcc.cnt = 0;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    74
    iterate(&bcc, start, end);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    75
    return bcc.cnt;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    76
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    77
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    78
#ifdef ASSERT
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    79
  // Given a pointer, check if it points into the range this bitmap covers.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    80
  bool is_pointer_valid(const MetaWord* p) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    81
    return p >= _base && p < _base + _word_size;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    82
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    83
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    84
  // Given a pointer, check if it points into the range this bitmap covers.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    85
  void check_pointer(const MetaWord* p) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    86
    assert(is_pointer_valid(p),
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    87
           "Pointer " PTR_FORMAT " not in range of this bitmap [" PTR_FORMAT ", " PTR_FORMAT ").",
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    88
           p2i(p), p2i(_base), p2i(_base + _word_size));
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    89
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    90
  // Given a pointer, check if it points into the range this bitmap covers,
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    91
  // and if it is aligned to commit granule border.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    92
  void check_pointer_aligned(const MetaWord* p) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    93
    check_pointer(p);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    94
    assert(is_aligned(p, _words_per_bit * BytesPerWord),
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    95
           "Pointer " PTR_FORMAT " should be aligned to commit granule size " SIZE_FORMAT ".",
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    96
           p2i(p), _words_per_bit * BytesPerWord);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    97
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    98
  // Given a range, check if it points into the range this bitmap covers,
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
    99
  // and if its borders are aligned to commit granule border.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   100
  void check_range(const MetaWord* start, size_t word_size) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   101
    check_pointer_aligned(start);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   102
    assert(is_aligned(word_size, _words_per_bit),
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   103
           "Range " SIZE_FORMAT " should be aligned to commit granule size " SIZE_FORMAT ".",
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   104
           word_size, _words_per_bit);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   105
    check_pointer(start + word_size - 1);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   106
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   107
#endif
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   108
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   109
  // Marks a single commit granule as committed (value == true)
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   110
  // or uncomitted (value == false) and returns
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   111
  // its prior state.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   112
  bool mark_granule(idx_t bitno, bool value) {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   113
    bool b = at(bitno);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   114
    at_put(bitno, value);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   115
    return b;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   116
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   117
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   118
public:
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   119
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   120
  CommitMask(const MetaWord* start, size_t word_size);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   121
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   122
  const MetaWord* base() const  { return _base; }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   123
  size_t word_size() const      { return _word_size; }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   124
  const MetaWord* end() const   { return _base + word_size(); }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   125
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   126
  // Given an address, returns true if the address is committed, false if not.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   127
  bool is_committed_address(const MetaWord* p) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   128
    DEBUG_ONLY(check_pointer(p));
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   129
    const idx_t bitno = bitno_for_address(p);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   130
    return at(bitno);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   131
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   132
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   133
  // Given an address range, return size, in number of words, of committed area within that range.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   134
  size_t get_committed_size_in_range(const MetaWord* start, size_t word_size) const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   135
    DEBUG_ONLY(check_range(start, word_size));
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   136
    assert(word_size > 0, "zero range");
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   137
    const idx_t b1 = bitno_for_address(start);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   138
    const idx_t b2 = bitno_for_address(start + word_size);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   139
    const idx_t num_bits = count_one_bits_in_range(b1, b2);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   140
    return num_bits * _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   141
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   142
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   143
  // Return total committed size, in number of words.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   144
  size_t get_committed_size() const {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   145
    return count_one_bits() * _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   146
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   147
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   148
  // Mark a whole address range [start, end) as committed.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   149
  // Return the number of words which had already been committed before this operation.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   150
  size_t mark_range_as_committed(const MetaWord* start, size_t word_size) {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   151
    DEBUG_ONLY(check_range(start, word_size));
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   152
    assert(word_size > 0, "zero range");
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   153
    const idx_t b1 = bitno_for_address(start);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   154
    const idx_t b2 = bitno_for_address(start + word_size);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   155
    if (b1 == b2) { // Simple case, 1 granule
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   156
      bool was_committed = mark_granule(b1, true);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   157
      return was_committed ? _words_per_bit : 0;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   158
    }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   159
    const idx_t one_bits_in_range_before = count_one_bits_in_range(b1, b2);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   160
    set_range(b1, b2);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   161
    return one_bits_in_range_before * _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   162
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   163
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   164
  // Mark a whole address range [start, end) as uncommitted.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   165
  // Return the number of words which had already been uncommitted before this operation.
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   166
  size_t mark_range_as_uncommitted(const MetaWord* start, size_t word_size) {
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   167
    DEBUG_ONLY(check_range(start, word_size));
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   168
    assert(word_size > 0, "zero range");
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   169
    const idx_t b1 = bitno_for_address(start);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   170
    const idx_t b2 = bitno_for_address(start + word_size);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   171
    if (b1 == b2) { // Simple case, 1 granule
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   172
      bool was_committed = mark_granule(b1, false);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   173
      return was_committed ? 0 : _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   174
    }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   175
    const idx_t zero_bits_in_range_before =
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   176
        (b2 - b1) - count_one_bits_in_range(b1, b2);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   177
    clear_range(b1, b2);
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   178
    return zero_bits_in_range_before * _words_per_bit;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   179
  }
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   180
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   181
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   182
  //// Debug stuff ////
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   183
  DEBUG_ONLY(void verify(bool slow, bool do_touch_test = true) const;)
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   184
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   185
  void print_on(outputStream* st) const;
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   186
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   187
};
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   188
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   189
} // namespace metaspace
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   190
bdf136b8ae0e Initial changes for new metaspace. Only tested for Linux x64.
stuefe
parents:
diff changeset
   191
#endif // SHARE_MEMORY_METASPACE_COMMITMASK_HPP