13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "runtime/atomic.inline.hpp"
29 #include "utilities/bitMap.inline.hpp"
30 #include "utilities/copy.hpp"
31
32 BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
33 _map(map), _size(size_in_bits), _map_allocator(false)
34 {
35 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
36 }
37
38
39 BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) :
40 _map(NULL), _size(0), _map_allocator(false)
41 {
42 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
43 resize(size_in_bits, in_resource_area);
44 }
45
46 void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
47 idx_t old_size_in_words = size_in_words();
48 bm_word_t* old_map = map();
49
50 _size = size_in_bits;
51 idx_t new_size_in_words = size_in_words();
52 if (in_resource_area) {
53 _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
54 Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
55 MIN2(old_size_in_words, new_size_in_words));
56 } else {
57 _map = _map_allocator.reallocate(new_size_in_words);
58 }
59
60 if (new_size_in_words > old_size_in_words) {
61 clear_range_of_words(old_size_in_words, new_size_in_words);
62 }
63 }
64
65 void BitMap::set_range_within_word(idx_t beg, idx_t end) {
66 // With a valid range (beg <= end), this test ensures that end != 0, as
67 // required by inverted_bit_mask_for_range. Also avoids an unnecessary write.
68 if (beg != end) {
69 bm_word_t mask = inverted_bit_mask_for_range(beg, end);
70 *word_addr(beg) |= ~mask;
71 }
72 }
73
74 void BitMap::clear_range_within_word(idx_t beg, idx_t end) {
75 // With a valid range (beg <= end), this test ensures that end != 0, as
76 // required by inverted_bit_mask_for_range. Also avoids an unnecessary write.
77 if (beg != end) {
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.inline.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "runtime/atomic.inline.hpp"
29 #include "utilities/bitMap.inline.hpp"
30 #include "utilities/copy.hpp"
31
32 BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
33 _map(map), _size(size_in_bits)
34 {
35 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
36 }
37
38
39 BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) :
40 _map(NULL), _size(0)
41 {
42 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
43 resize(size_in_bits, in_resource_area);
44 }
45
46 void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
47 idx_t old_size_in_words = size_in_words();
48 bm_word_t* old_map = map();
49
50 _size = size_in_bits;
51 idx_t new_size_in_words = size_in_words();
52 if (in_resource_area) {
53 _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
54 Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
55 MIN2(old_size_in_words, new_size_in_words));
56 } else {
57 _map = ArrayAllocator<bm_word_t, mtInternal>::reallocate(old_map, old_size_in_words, new_size_in_words);
58 }
59
60 if (new_size_in_words > old_size_in_words) {
61 clear_range_of_words(old_size_in_words, new_size_in_words);
62 }
63 }
64
65 void BitMap::set_range_within_word(idx_t beg, idx_t end) {
66 // With a valid range (beg <= end), this test ensures that end != 0, as
67 // required by inverted_bit_mask_for_range. Also avoids an unnecessary write.
68 if (beg != end) {
69 bm_word_t mask = inverted_bit_mask_for_range(beg, end);
70 *word_addr(beg) |= ~mask;
71 }
72 }
73
74 void BitMap::clear_range_within_word(idx_t beg, idx_t end) {
75 // With a valid range (beg <= end), this test ensures that end != 0, as
76 // required by inverted_bit_mask_for_range. Also avoids an unnecessary write.
77 if (beg != end) {
|