hotspot/src/share/vm/utilities/bitMap.cpp
author goetz
Mon, 16 Feb 2015 14:07:36 +0100
changeset 29580 a67a581cfe11
parent 27880 afb974a04396
child 37057 03b3e1870228
permissions -rw-r--r--
8073315: Enable gcc -Wtype-limits and fix upcoming issues. Summary: Relevant fixes in blockOffsetTable.cpp, os_linux.cpp, parCardTableModRefBS.cpp. Reviewed-by: jwilhelm, kbarrett, simonis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27880
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    27
#include "memory/resourceArea.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    28
#include "runtime/atomic.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/bitMap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    32
BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
18092
202cf28d5b82 8016556: G1: Use ArrayAllocator for BitMaps
brutisso
parents: 16685
diff changeset
    33
  _map(map), _size(size_in_bits), _map_allocator(false)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    34
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    35
  assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    39
BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) :
18092
202cf28d5b82 8016556: G1: Use ArrayAllocator for BitMaps
brutisso
parents: 16685
diff changeset
    40
  _map(NULL), _size(0), _map_allocator(false)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    41
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    42
  assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    43
  resize(size_in_bits, in_resource_area);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    46
void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    47
  idx_t old_size_in_words = size_in_words();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    48
  bm_word_t* old_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    49
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _size = size_in_bits;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    51
  idx_t new_size_in_words = size_in_words();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    52
  if (in_resource_area) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    53
    _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    54
    Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    55
                         MIN2(old_size_in_words, new_size_in_words));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    56
  } else {
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    57
    _map = _map_allocator.reallocate(new_size_in_words);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    58
  }
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    59
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (new_size_in_words > old_size_in_words) {
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
    61
    clear_range_of_words(old_size_in_words, new_size_in_words);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
void BitMap::set_range_within_word(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // With a valid range (beg <= end), this test ensures that end != 0, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // required by inverted_bit_mask_for_range.  Also avoids an unnecessary write.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  if (beg != end) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    69
    bm_word_t mask = inverted_bit_mask_for_range(beg, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    *word_addr(beg) |= ~mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
void BitMap::clear_range_within_word(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // With a valid range (beg <= end), this test ensures that end != 0, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // required by inverted_bit_mask_for_range.  Also avoids an unnecessary write.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  if (beg != end) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    78
    bm_word_t mask = inverted_bit_mask_for_range(beg, end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    *word_addr(beg) &= mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void BitMap::par_put_range_within_word(idx_t beg, idx_t end, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(value == 0 || value == 1, "0 for clear, 1 for set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // With a valid range (beg <= end), this test ensures that end != 0, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // required by inverted_bit_mask_for_range.  Also avoids an unnecessary write.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  if (beg != end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    intptr_t* pw  = (intptr_t*)word_addr(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    intptr_t  w   = *pw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    intptr_t  mr  = (intptr_t)inverted_bit_mask_for_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    intptr_t  nw  = value ? (w | ~mr) : (w & mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      intptr_t res = Atomic::cmpxchg_ptr(nw, pw, w);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      if (res == w) break;
22769
516e9b159656 8033545: Missing volatile specifier in Bitmap::par_put_range_within_word
tschatzl
parents: 22234
diff changeset
    95
      w  = res;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      nw = value ? (w | ~mr) : (w & mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
void BitMap::set_range(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  if (beg_full_word < end_full_word) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    set_range_within_word(beg, bit_index(beg_full_word));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    set_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    set_range_within_word(bit_index(end_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // The range spans at most 2 partial words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    idx_t boundary = MIN2(bit_index(beg_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    set_range_within_word(beg, boundary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    set_range_within_word(boundary, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void BitMap::clear_range(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (beg_full_word < end_full_word) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    clear_range_within_word(beg, bit_index(beg_full_word));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    clear_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    clear_range_within_word(bit_index(end_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // The range spans at most 2 partial words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    idx_t boundary = MIN2(bit_index(beg_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    clear_range_within_word(beg, boundary);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    clear_range_within_word(boundary, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
void BitMap::set_large_range(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  assert(end_full_word - beg_full_word >= 32,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
         "the range must include at least 32 bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  set_range_within_word(beg, bit_index(beg_full_word));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  set_large_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  set_range_within_word(bit_index(end_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
void BitMap::clear_large_range(idx_t beg, idx_t end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(end_full_word - beg_full_word >= 32,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
         "the range must include at least 32 bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  clear_range_within_word(beg, bit_index(beg_full_word));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  clear_large_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  clear_range_within_word(bit_index(end_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
void BitMap::at_put(idx_t offset, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    set_bit(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    clear_bit(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// Return true to indicate that this thread changed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// the bit, false to indicate that someone else did.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// In either case, the requested bit is in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
// requested state some time during the period that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
// this thread is executing this call. More importantly,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
// if no other thread is executing an action to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// change the requested bit to a state other than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
// the one that this thread is trying to set it to,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// then the the bit is in the expected state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
// at exit from this method. However, rather than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
// make such a strong assertion here, based on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// assuming such constrained use (which though true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// today, could change in the future to service some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// funky parallel algorithm), we encourage callers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// to do such verification, as and when appropriate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
bool BitMap::par_at_put(idx_t bit, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  return value ? par_set_bit(bit) : par_clear_bit(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void BitMap::at_put_grow(idx_t offset, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if (offset >= size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    resize(2 * MAX2(size(), offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  at_put(offset, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
void BitMap::at_put_range(idx_t start_offset, idx_t end_offset, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  if (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    set_range(start_offset, end_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    clear_range(start_offset, end_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
void BitMap::par_at_put_range(idx_t beg, idx_t end, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (beg_full_word < end_full_word) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    par_put_range_within_word(beg, bit_index(beg_full_word), value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    if (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      set_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      clear_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    par_put_range_within_word(bit_index(end_full_word), end, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    // The range spans at most 2 partial words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    idx_t boundary = MIN2(bit_index(beg_full_word), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    par_put_range_within_word(beg, boundary, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    par_put_range_within_word(boundary, end, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
void BitMap::at_put_large_range(idx_t beg, idx_t end, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  if (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    set_large_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    clear_large_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
void BitMap::par_at_put_large_range(idx_t beg, idx_t end, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  verify_range(beg, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  idx_t beg_full_word = word_index_round_up(beg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  idx_t end_full_word = word_index(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert(end_full_word - beg_full_word >= 32,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
         "the range must include at least 32 bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // The range includes at least one full word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  par_put_range_within_word(beg, bit_index(beg_full_word), value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  if (value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    set_large_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    clear_large_range_of_words(beg_full_word, end_full_word);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  par_put_range_within_word(bit_index(end_full_word), end, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
bool BitMap::contains(const BitMap other) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   264
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   265
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  for (idx_t index = 0; index < size_in_words(); index++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   268
    bm_word_t word_union = dest_map[index] | other_map[index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    // If this has more bits set than dest_map[index], then other is not a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // subset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    if (word_union != dest_map[index]) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
bool BitMap::intersects(const BitMap other) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   278
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   279
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  for (idx_t index = 0; index < size_in_words(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    if ((dest_map[index] & other_map[index]) != 0) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Otherwise, no intersection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
void BitMap::set_union(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   290
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   291
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  for (idx_t index = 0; index < size_in_words(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    dest_map[index] = dest_map[index] | other_map[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
void BitMap::set_difference(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   301
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   302
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  for (idx_t index = 0; index < size_in_words(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    dest_map[index] = dest_map[index] & ~(other_map[index]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
void BitMap::set_intersection(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   312
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   313
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  for (idx_t index = 0; index < size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    dest_map[index]  = dest_map[index] & other_map[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   321
void BitMap::set_intersection_at_offset(BitMap other, idx_t offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   322
  assert(other.size() >= offset, "offset not in range");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   323
  assert(other.size() - offset >= size(), "other not large enough");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   324
  // XXX Ideally, we would remove this restriction.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   325
  guarantee((offset % (sizeof(bm_word_t) * BitsPerByte)) == 0,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   326
            "Only handle aligned cases so far.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   327
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   328
  bm_word_t* other_map = other.map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   329
  idx_t offset_word_ind = word_index(offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   330
  idx_t size = size_in_words();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   331
  for (idx_t index = 0; index < size; index++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   332
    dest_map[index] = dest_map[index] & other_map[offset_word_ind + index];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   333
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   334
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   335
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
bool BitMap::set_union_with_result(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  assert(size() == other.size(), "must have same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  bool changed = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   339
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   340
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  for (idx_t index = 0; index < size; index++) {
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   343
    idx_t temp = dest_map[index] | other_map[index];
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   344
    changed = changed || (temp != dest_map[index]);
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   345
    dest_map[index] = temp;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  return changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
bool BitMap::set_difference_with_result(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  assert(size() == other.size(), "must have same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  bool changed = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   354
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   355
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  for (idx_t index = 0; index < size; index++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   358
    bm_word_t temp = dest_map[index] & ~(other_map[index]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    changed = changed || (temp != dest_map[index]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    dest_map[index] = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  return changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
bool BitMap::set_intersection_with_result(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  assert(size() == other.size(), "must have same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  bool changed = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   369
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   370
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  for (idx_t index = 0; index < size; index++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   373
    bm_word_t orig = dest_map[index];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   374
    bm_word_t temp = orig & other_map[index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    changed = changed || (temp != orig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    dest_map[index]  = temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  return changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
void BitMap::set_from(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   384
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   385
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  for (idx_t index = 0; index < size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    dest_map[index] = other_map[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
bool BitMap::is_same(BitMap other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  assert(size() == other.size(), "must have same size");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   395
  bm_word_t* dest_map = map();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   396
  bm_word_t* other_map = other.map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  idx_t size = size_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  for (idx_t index = 0; index < size; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    if (dest_map[index] != other_map[index]) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
bool BitMap::is_full() const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   405
  bm_word_t* word = map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  idx_t rest = size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) {
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   408
    if (*word != ~(bm_word_t)0) return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    word++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  }
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   411
  return rest == 0 || (*word | ~right_n_bits((int)rest)) == ~(bm_word_t)0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
bool BitMap::is_empty() const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   416
  bm_word_t* word = map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  idx_t rest = size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) {
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   419
    if (*word != 0) return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    word++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   422
  return rest == 0 || (*word & right_n_bits((int)rest)) == 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
void BitMap::clear_large() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  clear_large_range_of_words(0, size_in_words());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// Note that if the closure itself modifies the bitmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
// then modifications in and to the left of the _bit_ being
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
// currently sampled will not be seen. Note also that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
// interval [leftOffset, rightOffset) is right open.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   433
bool BitMap::iterate(BitMapClosure* blk, idx_t leftOffset, idx_t rightOffset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  verify_range(leftOffset, rightOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  idx_t startIndex = word_index(leftOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  idx_t endIndex   = MIN2(word_index(rightOffset) + 1, size_in_words());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  for (idx_t index = startIndex, offset = leftOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
       offset < rightOffset && index < endIndex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
       offset = (++index) << LogBitsPerWord) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    idx_t rest = map(index) >> (offset & (BitsPerWord - 1));
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 25959
diff changeset
   442
    for (; offset < rightOffset && rest != 0; offset++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      if (rest & 1) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   444
        if (!blk->do_bit(offset)) return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        //  resample at each closure application
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        // (see, for instance, CMS bug 4525989)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        rest = map(index) >> (offset & (BitsPerWord -1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      rest = rest >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   452
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   453
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   454
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   455
BitMap::idx_t* BitMap::_pop_count_table = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   456
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   457
void BitMap::init_pop_count_table() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   458
  if (_pop_count_table == NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12272
diff changeset
   459
    BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   460
    for (uint i = 0; i < 256; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   461
      table[i] = num_set_bits(i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   462
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   463
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   464
    intptr_t res = Atomic::cmpxchg_ptr((intptr_t)  table,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   465
                                       (intptr_t*) &_pop_count_table,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   466
                                       (intptr_t)  NULL_WORD);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   467
    if (res != NULL_WORD) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   468
      guarantee( _pop_count_table == (void*) res, "invariant" );
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26937
diff changeset
   469
      FREE_C_HEAP_ARRAY(idx_t, table);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   470
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   471
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   474
BitMap::idx_t BitMap::num_set_bits(bm_word_t w) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   475
  idx_t bits = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   477
  while (w != 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   478
    while ((w & 1) == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   479
      w >>= 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   481
    bits++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   482
    w >>= 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   484
  return bits;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   487
BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   488
  assert(_pop_count_table != NULL, "precondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   489
  return _pop_count_table[c];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   490
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   492
BitMap::idx_t BitMap::count_one_bits() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   493
  init_pop_count_table(); // If necessary.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   494
  idx_t sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   495
  typedef unsigned char uchar;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   496
  for (idx_t i = 0; i < size_in_words(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   497
    bm_word_t w = map()[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   498
    for (size_t j = 0; j < sizeof(bm_word_t); j++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   499
      sum += num_set_bits_from_table(uchar(w & 255));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   500
      w >>= 8;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   503
  return sum;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
16685
41c34debcde0 8011872: Include Bit Map addresses in the hs_err files
stefank
parents: 13195
diff changeset
   506
void BitMap::print_on_error(outputStream* st, const char* prefix) const {
41c34debcde0 8011872: Include Bit Map addresses in the hs_err files
stefank
parents: 13195
diff changeset
   507
  st->print_cr("%s[" PTR_FORMAT ", " PTR_FORMAT ")",
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23545
diff changeset
   508
      prefix, p2i(map()), p2i((char*)map() + (size() >> LogBitsPerByte)));
16685
41c34debcde0 8011872: Include Bit Map addresses in the hs_err files
stefank
parents: 13195
diff changeset
   509
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   510
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
void BitMap::print_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23545
diff changeset
   514
  tty->print("Bitmap(" SIZE_FORMAT "):", size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  for (idx_t index = 0; index < size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    tty->print("%c", at(index) ? '1' : '0');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   521
class TestBitMap : public AllStatic {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   522
  const static BitMap::idx_t BITMAP_SIZE = 1024;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   523
  static void fillBitMap(BitMap& map) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   524
    map.set_bit(1);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   525
    map.set_bit(3);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   526
    map.set_bit(17);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   527
    map.set_bit(512);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   528
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   529
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   530
  static void testResize(bool in_resource_area) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   531
    {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   532
      BitMap map(0, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   533
      map.resize(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   534
      fillBitMap(map);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   535
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   536
      BitMap map2(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   537
      fillBitMap(map2);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   538
      assert(map.is_same(map2), "could be");
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   539
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   540
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   541
    {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   542
      BitMap map(128, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   543
      map.resize(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   544
      fillBitMap(map);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   546
      BitMap map2(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   547
      fillBitMap(map2);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   548
      assert(map.is_same(map2), "could be");
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   549
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   550
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   551
    {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   552
      BitMap map(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   553
      map.resize(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   554
      fillBitMap(map);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   555
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   556
      BitMap map2(BITMAP_SIZE, in_resource_area);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   557
      fillBitMap(map2);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   558
      assert(map.is_same(map2), "could be");
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   559
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   560
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   561
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   562
  static void testResizeResource() {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   563
    ResourceMark rm;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   564
    testResize(true);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   565
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   566
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   567
  static void testResizeNonResource() {
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25468
diff changeset
   568
    const size_t bitmap_bytes = BITMAP_SIZE / BitsPerByte;
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   569
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   570
    // Test the default behavior
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   571
    testResize(false);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   572
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   573
    {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   574
      // Make sure that AllocatorMallocLimit is larger than our allocation request
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   575
      // forcing it to call standard malloc()
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25468
diff changeset
   576
      SizeTFlagSetting fs(ArrayAllocatorMallocLimit, bitmap_bytes * 4);
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   577
      testResize(false);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   578
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   579
    {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   580
      // Make sure that AllocatorMallocLimit is smaller than our allocation request
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   581
      // forcing it to call mmap() (or equivalent)
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 25468
diff changeset
   582
      SizeTFlagSetting fs(ArrayAllocatorMallocLimit, bitmap_bytes / 4);
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   583
      testResize(false);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   584
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   585
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   586
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   587
 public:
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   588
  static void test() {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   589
    testResizeResource();
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   590
    testResizeNonResource();
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   591
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   592
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   593
};
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   594
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   595
void TestBitMap_test() {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   596
  TestBitMap::test();
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 22876
diff changeset
   597
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   601
BitMap2D::BitMap2D(bm_word_t* map, idx_t size_in_slots, idx_t bits_per_slot)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  : _bits_per_slot(bits_per_slot)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  , _map(map, size_in_slots * bits_per_slot)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
BitMap2D::BitMap2D(idx_t size_in_slots, idx_t bits_per_slot)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  : _bits_per_slot(bits_per_slot)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  , _map(size_in_slots * bits_per_slot)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
}