aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "utilities/bitMap.inline.hpp" aoqi@0: #include "utilities/copy.hpp" aoqi@0: #ifdef TARGET_OS_FAMILY_linux aoqi@0: # include "os_linux.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_OS_FAMILY_solaris aoqi@0: # include "os_solaris.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_OS_FAMILY_windows aoqi@0: # include "os_windows.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_OS_FAMILY_aix aoqi@0: # include "os_aix.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_OS_FAMILY_bsd aoqi@0: # include "os_bsd.inline.hpp" aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) : aoqi@0: _map(map), _size(size_in_bits), _map_allocator(false) aoqi@0: { aoqi@0: assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption."); aoqi@0: assert(size_in_bits >= 0, "just checking"); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) : aoqi@0: _map(NULL), _size(0), _map_allocator(false) aoqi@0: { aoqi@0: assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption."); aoqi@0: resize(size_in_bits, in_resource_area); aoqi@0: } aoqi@0: aoqi@0: void BitMap::resize(idx_t size_in_bits, bool in_resource_area) { aoqi@0: assert(size_in_bits >= 0, "just checking"); aoqi@0: idx_t old_size_in_words = size_in_words(); aoqi@0: bm_word_t* old_map = map(); aoqi@0: aoqi@0: _size = size_in_bits; aoqi@0: idx_t new_size_in_words = size_in_words(); aoqi@0: if (in_resource_area) { aoqi@0: _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words); aoqi@0: } else { aoqi@0: if (old_map != NULL) { aoqi@0: _map_allocator.free(); aoqi@0: } aoqi@0: _map = _map_allocator.allocate(new_size_in_words); aoqi@0: } aoqi@0: Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map, aoqi@0: MIN2(old_size_in_words, new_size_in_words)); aoqi@0: if (new_size_in_words > old_size_in_words) { aoqi@0: clear_range_of_words(old_size_in_words, size_in_words()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::set_range_within_word(idx_t beg, idx_t end) { aoqi@0: // With a valid range (beg <= end), this test ensures that end != 0, as aoqi@0: // required by inverted_bit_mask_for_range. Also avoids an unnecessary write. aoqi@0: if (beg != end) { aoqi@0: bm_word_t mask = inverted_bit_mask_for_range(beg, end); aoqi@0: *word_addr(beg) |= ~mask; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::clear_range_within_word(idx_t beg, idx_t end) { aoqi@0: // With a valid range (beg <= end), this test ensures that end != 0, as aoqi@0: // required by inverted_bit_mask_for_range. Also avoids an unnecessary write. aoqi@0: if (beg != end) { aoqi@0: bm_word_t mask = inverted_bit_mask_for_range(beg, end); aoqi@0: *word_addr(beg) &= mask; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::par_put_range_within_word(idx_t beg, idx_t end, bool value) { aoqi@0: assert(value == 0 || value == 1, "0 for clear, 1 for set"); aoqi@0: // With a valid range (beg <= end), this test ensures that end != 0, as aoqi@0: // required by inverted_bit_mask_for_range. Also avoids an unnecessary write. aoqi@0: if (beg != end) { aoqi@0: intptr_t* pw = (intptr_t*)word_addr(beg); aoqi@0: intptr_t w = *pw; aoqi@0: intptr_t mr = (intptr_t)inverted_bit_mask_for_range(beg, end); aoqi@0: intptr_t nw = value ? (w | ~mr) : (w & mr); aoqi@0: while (true) { aoqi@0: intptr_t res = Atomic::cmpxchg_ptr(nw, pw, w); aoqi@0: if (res == w) break; aoqi@0: w = res; aoqi@0: nw = value ? (w | ~mr) : (w & mr); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::set_range(idx_t beg, idx_t end) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: if (beg_full_word < end_full_word) { aoqi@0: // The range includes at least one full word. aoqi@0: set_range_within_word(beg, bit_index(beg_full_word)); aoqi@0: set_range_of_words(beg_full_word, end_full_word); aoqi@0: set_range_within_word(bit_index(end_full_word), end); aoqi@0: } else { aoqi@0: // The range spans at most 2 partial words. aoqi@0: idx_t boundary = MIN2(bit_index(beg_full_word), end); aoqi@0: set_range_within_word(beg, boundary); aoqi@0: set_range_within_word(boundary, end); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::clear_range(idx_t beg, idx_t end) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: if (beg_full_word < end_full_word) { aoqi@0: // The range includes at least one full word. aoqi@0: clear_range_within_word(beg, bit_index(beg_full_word)); aoqi@0: clear_range_of_words(beg_full_word, end_full_word); aoqi@0: clear_range_within_word(bit_index(end_full_word), end); aoqi@0: } else { aoqi@0: // The range spans at most 2 partial words. aoqi@0: idx_t boundary = MIN2(bit_index(beg_full_word), end); aoqi@0: clear_range_within_word(beg, boundary); aoqi@0: clear_range_within_word(boundary, end); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::set_large_range(idx_t beg, idx_t end) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: assert(end_full_word - beg_full_word >= 32, aoqi@0: "the range must include at least 32 bytes"); aoqi@0: aoqi@0: // The range includes at least one full word. aoqi@0: set_range_within_word(beg, bit_index(beg_full_word)); aoqi@0: set_large_range_of_words(beg_full_word, end_full_word); aoqi@0: set_range_within_word(bit_index(end_full_word), end); aoqi@0: } aoqi@0: aoqi@0: void BitMap::clear_large_range(idx_t beg, idx_t end) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: assert(end_full_word - beg_full_word >= 32, aoqi@0: "the range must include at least 32 bytes"); aoqi@0: aoqi@0: // The range includes at least one full word. aoqi@0: clear_range_within_word(beg, bit_index(beg_full_word)); aoqi@0: clear_large_range_of_words(beg_full_word, end_full_word); aoqi@0: clear_range_within_word(bit_index(end_full_word), end); aoqi@0: } aoqi@0: aoqi@0: void BitMap::at_put(idx_t offset, bool value) { aoqi@0: if (value) { aoqi@0: set_bit(offset); aoqi@0: } else { aoqi@0: clear_bit(offset); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Return true to indicate that this thread changed aoqi@0: // the bit, false to indicate that someone else did. aoqi@0: // In either case, the requested bit is in the aoqi@0: // requested state some time during the period that aoqi@0: // this thread is executing this call. More importantly, aoqi@0: // if no other thread is executing an action to aoqi@0: // change the requested bit to a state other than aoqi@0: // the one that this thread is trying to set it to, aoqi@0: // then the the bit is in the expected state aoqi@0: // at exit from this method. However, rather than aoqi@0: // make such a strong assertion here, based on aoqi@0: // assuming such constrained use (which though true aoqi@0: // today, could change in the future to service some aoqi@0: // funky parallel algorithm), we encourage callers aoqi@0: // to do such verification, as and when appropriate. aoqi@0: bool BitMap::par_at_put(idx_t bit, bool value) { aoqi@0: return value ? par_set_bit(bit) : par_clear_bit(bit); aoqi@0: } aoqi@0: aoqi@0: void BitMap::at_put_grow(idx_t offset, bool value) { aoqi@0: if (offset >= size()) { aoqi@0: resize(2 * MAX2(size(), offset)); aoqi@0: } aoqi@0: at_put(offset, value); aoqi@0: } aoqi@0: aoqi@0: void BitMap::at_put_range(idx_t start_offset, idx_t end_offset, bool value) { aoqi@0: if (value) { aoqi@0: set_range(start_offset, end_offset); aoqi@0: } else { aoqi@0: clear_range(start_offset, end_offset); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::par_at_put_range(idx_t beg, idx_t end, bool value) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: if (beg_full_word < end_full_word) { aoqi@0: // The range includes at least one full word. aoqi@0: par_put_range_within_word(beg, bit_index(beg_full_word), value); aoqi@0: if (value) { aoqi@0: set_range_of_words(beg_full_word, end_full_word); aoqi@0: } else { aoqi@0: clear_range_of_words(beg_full_word, end_full_word); aoqi@0: } aoqi@0: par_put_range_within_word(bit_index(end_full_word), end, value); aoqi@0: } else { aoqi@0: // The range spans at most 2 partial words. aoqi@0: idx_t boundary = MIN2(bit_index(beg_full_word), end); aoqi@0: par_put_range_within_word(beg, boundary, value); aoqi@0: par_put_range_within_word(boundary, end, value); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: void BitMap::at_put_large_range(idx_t beg, idx_t end, bool value) { aoqi@0: if (value) { aoqi@0: set_large_range(beg, end); aoqi@0: } else { aoqi@0: clear_large_range(beg, end); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void BitMap::par_at_put_large_range(idx_t beg, idx_t end, bool value) { aoqi@0: verify_range(beg, end); aoqi@0: aoqi@0: idx_t beg_full_word = word_index_round_up(beg); aoqi@0: idx_t end_full_word = word_index(end); aoqi@0: aoqi@0: assert(end_full_word - beg_full_word >= 32, aoqi@0: "the range must include at least 32 bytes"); aoqi@0: aoqi@0: // The range includes at least one full word. aoqi@0: par_put_range_within_word(beg, bit_index(beg_full_word), value); aoqi@0: if (value) { aoqi@0: set_large_range_of_words(beg_full_word, end_full_word); aoqi@0: } else { aoqi@0: clear_large_range_of_words(beg_full_word, end_full_word); aoqi@0: } aoqi@0: par_put_range_within_word(bit_index(end_full_word), end, value); aoqi@0: } aoqi@0: aoqi@0: bool BitMap::contains(const BitMap other) const { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size_in_words(); index++) { aoqi@0: bm_word_t word_union = dest_map[index] | other_map[index]; aoqi@0: // If this has more bits set than dest_map[index], then other is not a aoqi@0: // subset. aoqi@0: if (word_union != dest_map[index]) return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: bool BitMap::intersects(const BitMap other) const { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size_in_words(); index++) { aoqi@0: if ((dest_map[index] & other_map[index]) != 0) return true; aoqi@0: } aoqi@0: // Otherwise, no intersection. aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void BitMap::set_union(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size_in_words(); index++) { aoqi@0: dest_map[index] = dest_map[index] | other_map[index]; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void BitMap::set_difference(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size_in_words(); index++) { aoqi@0: dest_map[index] = dest_map[index] & ~(other_map[index]); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void BitMap::set_intersection(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: dest_map[index] = dest_map[index] & other_map[index]; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void BitMap::set_intersection_at_offset(BitMap other, idx_t offset) { aoqi@0: assert(other.size() >= offset, "offset not in range"); aoqi@0: assert(other.size() - offset >= size(), "other not large enough"); aoqi@0: // XXX Ideally, we would remove this restriction. aoqi@0: guarantee((offset % (sizeof(bm_word_t) * BitsPerByte)) == 0, aoqi@0: "Only handle aligned cases so far."); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t offset_word_ind = word_index(offset); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: dest_map[index] = dest_map[index] & other_map[offset_word_ind + index]; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool BitMap::set_union_with_result(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bool changed = false; aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: idx_t temp = map(index) | other_map[index]; aoqi@0: changed = changed || (temp != map(index)); aoqi@0: map()[index] = temp; aoqi@0: } aoqi@0: return changed; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool BitMap::set_difference_with_result(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bool changed = false; aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: bm_word_t temp = dest_map[index] & ~(other_map[index]); aoqi@0: changed = changed || (temp != dest_map[index]); aoqi@0: dest_map[index] = temp; aoqi@0: } aoqi@0: return changed; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool BitMap::set_intersection_with_result(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bool changed = false; aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: bm_word_t orig = dest_map[index]; aoqi@0: bm_word_t temp = orig & other_map[index]; aoqi@0: changed = changed || (temp != orig); aoqi@0: dest_map[index] = temp; aoqi@0: } aoqi@0: return changed; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void BitMap::set_from(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: dest_map[index] = other_map[index]; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool BitMap::is_same(BitMap other) { aoqi@0: assert(size() == other.size(), "must have same size"); aoqi@0: bm_word_t* dest_map = map(); aoqi@0: bm_word_t* other_map = other.map(); aoqi@0: idx_t size = size_in_words(); aoqi@0: for (idx_t index = 0; index < size; index++) { aoqi@0: if (dest_map[index] != other_map[index]) return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: bool BitMap::is_full() const { aoqi@0: bm_word_t* word = map(); aoqi@0: idx_t rest = size(); aoqi@0: for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) { aoqi@0: if (*word != (bm_word_t) AllBits) return false; aoqi@0: word++; aoqi@0: } aoqi@0: return rest == 0 || (*word | ~right_n_bits((int)rest)) == (bm_word_t) AllBits; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool BitMap::is_empty() const { aoqi@0: bm_word_t* word = map(); aoqi@0: idx_t rest = size(); aoqi@0: for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) { aoqi@0: if (*word != (bm_word_t) NoBits) return false; aoqi@0: word++; aoqi@0: } aoqi@0: return rest == 0 || (*word & right_n_bits((int)rest)) == (bm_word_t) NoBits; aoqi@0: } aoqi@0: aoqi@0: void BitMap::clear_large() { aoqi@0: clear_large_range_of_words(0, size_in_words()); aoqi@0: } aoqi@0: aoqi@0: // Note that if the closure itself modifies the bitmap aoqi@0: // then modifications in and to the left of the _bit_ being aoqi@0: // currently sampled will not be seen. Note also that the aoqi@0: // interval [leftOffset, rightOffset) is right open. aoqi@0: bool BitMap::iterate(BitMapClosure* blk, idx_t leftOffset, idx_t rightOffset) { aoqi@0: verify_range(leftOffset, rightOffset); aoqi@0: aoqi@0: idx_t startIndex = word_index(leftOffset); aoqi@0: idx_t endIndex = MIN2(word_index(rightOffset) + 1, size_in_words()); aoqi@0: for (idx_t index = startIndex, offset = leftOffset; aoqi@0: offset < rightOffset && index < endIndex; aoqi@0: offset = (++index) << LogBitsPerWord) { aoqi@0: idx_t rest = map(index) >> (offset & (BitsPerWord - 1)); aoqi@0: for (; offset < rightOffset && rest != (bm_word_t)NoBits; offset++) { aoqi@0: if (rest & 1) { aoqi@0: if (!blk->do_bit(offset)) return false; aoqi@0: // resample at each closure application aoqi@0: // (see, for instance, CMS bug 4525989) aoqi@0: rest = map(index) >> (offset & (BitsPerWord -1)); aoqi@0: } aoqi@0: rest = rest >> 1; aoqi@0: } aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: BitMap::idx_t* BitMap::_pop_count_table = NULL; aoqi@0: aoqi@0: void BitMap::init_pop_count_table() { aoqi@0: if (_pop_count_table == NULL) { aoqi@0: BitMap::idx_t *table = NEW_C_HEAP_ARRAY(idx_t, 256, mtInternal); aoqi@0: for (uint i = 0; i < 256; i++) { aoqi@0: table[i] = num_set_bits(i); aoqi@0: } aoqi@0: aoqi@0: intptr_t res = Atomic::cmpxchg_ptr((intptr_t) table, aoqi@0: (intptr_t*) &_pop_count_table, aoqi@0: (intptr_t) NULL_WORD); aoqi@0: if (res != NULL_WORD) { aoqi@0: guarantee( _pop_count_table == (void*) res, "invariant" ); aoqi@0: FREE_C_HEAP_ARRAY(bm_word_t, table, mtInternal); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: BitMap::idx_t BitMap::num_set_bits(bm_word_t w) { aoqi@0: idx_t bits = 0; aoqi@0: aoqi@0: while (w != 0) { aoqi@0: while ((w & 1) == 0) { aoqi@0: w >>= 1; aoqi@0: } aoqi@0: bits++; aoqi@0: w >>= 1; aoqi@0: } aoqi@0: return bits; aoqi@0: } aoqi@0: aoqi@0: BitMap::idx_t BitMap::num_set_bits_from_table(unsigned char c) { aoqi@0: assert(_pop_count_table != NULL, "precondition"); aoqi@0: return _pop_count_table[c]; aoqi@0: } aoqi@0: aoqi@0: BitMap::idx_t BitMap::count_one_bits() const { aoqi@0: init_pop_count_table(); // If necessary. aoqi@0: idx_t sum = 0; aoqi@0: typedef unsigned char uchar; aoqi@0: for (idx_t i = 0; i < size_in_words(); i++) { aoqi@0: bm_word_t w = map()[i]; aoqi@0: for (size_t j = 0; j < sizeof(bm_word_t); j++) { aoqi@0: sum += num_set_bits_from_table(uchar(w & 255)); aoqi@0: w >>= 8; aoqi@0: } aoqi@0: } aoqi@0: return sum; aoqi@0: } aoqi@0: aoqi@0: void BitMap::print_on_error(outputStream* st, const char* prefix) const { aoqi@0: st->print_cr("%s[" PTR_FORMAT ", " PTR_FORMAT ")", aoqi@0: prefix, p2i(map()), p2i((char*)map() + (size() >> LogBitsPerByte))); aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void BitMap::print_on(outputStream* st) const { aoqi@0: tty->print("Bitmap(" SIZE_FORMAT "):", size()); aoqi@0: for (idx_t index = 0; index < size(); index++) { aoqi@0: tty->print("%c", at(index) ? '1' : '0'); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: BitMap2D::BitMap2D(bm_word_t* map, idx_t size_in_slots, idx_t bits_per_slot) aoqi@0: : _bits_per_slot(bits_per_slot) aoqi@0: , _map(map, size_in_slots * bits_per_slot) aoqi@0: { aoqi@0: } aoqi@0: aoqi@0: aoqi@0: BitMap2D::BitMap2D(idx_t size_in_slots, idx_t bits_per_slot) aoqi@0: : _bits_per_slot(bits_per_slot) aoqi@0: , _map(size_in_slots * bits_per_slot) aoqi@0: { aoqi@0: }