author | redestad |
Sun, 11 Dec 2016 12:20:45 +0100 | |
changeset 42469 | d1c0a9123f87 |
parent 40639 | 83c879c8db57 |
child 42591 | 821346dfd80d |
permissions | -rw-r--r-- |
1 | 1 |
/* |
37414
2672ba9af0dc
8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents:
37413
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
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 |
* |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_BITMAP_HPP |
26 |
#define SHARE_VM_UTILITIES_BITMAP_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
||
1374 | 30 |
// Forward decl; |
31 |
class BitMapClosure; |
|
1 | 32 |
|
1374 | 33 |
// Operations for bitmaps represented as arrays of unsigned integers. |
34 |
// Bit offsets are numbered from 0 to size-1. |
|
1 | 35 |
|
38177 | 36 |
// The "abstract" base BitMap class. |
37 |
// |
|
38 |
// The constructor and destructor are protected to prevent |
|
39 |
// creation of BitMap instances outside of the BitMap class. |
|
40 |
// |
|
41 |
// The BitMap class doesn't use virtual calls on purpose, |
|
42 |
// this ensures that we don't get a vtable unnecessarily. |
|
43 |
// |
|
44 |
// The allocation of the backing storage for the BitMap are handled by |
|
45 |
// the subclasses. BitMap doesn't allocate or delete backing storage. |
|
1 | 46 |
class BitMap VALUE_OBJ_CLASS_SPEC { |
47 |
friend class BitMap2D; |
|
48 |
||
49 |
public: |
|
50 |
typedef size_t idx_t; // Type used for bit and word indices. |
|
1374 | 51 |
typedef uintptr_t bm_word_t; // Element type of array that represents |
52 |
// the bitmap. |
|
1 | 53 |
|
54 |
// Hints for range sizes. |
|
55 |
typedef enum { |
|
56 |
unknown_range, small_range, large_range |
|
57 |
} RangeSizeHint; |
|
58 |
||
59 |
private: |
|
1374 | 60 |
bm_word_t* _map; // First word in bitmap |
61 |
idx_t _size; // Size of bitmap (in bits) |
|
1 | 62 |
|
63 |
protected: |
|
64 |
// Return the position of bit within the word that contains it (e.g., if |
|
65 |
// bitmap words are 32 bits, return a number 0 <= n <= 31). |
|
66 |
static idx_t bit_in_word(idx_t bit) { return bit & (BitsPerWord - 1); } |
|
67 |
||
68 |
// Return a mask that will select the specified bit, when applied to the word |
|
69 |
// containing the bit. |
|
1374 | 70 |
static bm_word_t bit_mask(idx_t bit) { return (bm_word_t)1 << bit_in_word(bit); } |
1 | 71 |
|
72 |
// Return the index of the word containing the specified bit. |
|
73 |
static idx_t word_index(idx_t bit) { return bit >> LogBitsPerWord; } |
|
74 |
||
75 |
// Return the bit number of the first bit in the specified word. |
|
76 |
static idx_t bit_index(idx_t word) { return word << LogBitsPerWord; } |
|
77 |
||
78 |
// Return the array of bitmap words, or a specific word from it. |
|
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
79 |
bm_word_t* map() { return _map; } |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
80 |
const bm_word_t* map() const { return _map; } |
1374 | 81 |
bm_word_t map(idx_t word) const { return _map[word]; } |
1 | 82 |
|
83 |
// Return a pointer to the word containing the specified bit. |
|
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
84 |
bm_word_t* word_addr(idx_t bit) { return map() + word_index(bit); } |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
85 |
const bm_word_t* word_addr(idx_t bit) const { return map() + word_index(bit); } |
1 | 86 |
|
87 |
// Set a word to a specified value or to all ones; clear a word. |
|
1374 | 88 |
void set_word (idx_t word, bm_word_t val) { _map[word] = val; } |
26937 | 89 |
void set_word (idx_t word) { set_word(word, ~(bm_word_t)0); } |
1 | 90 |
void clear_word(idx_t word) { _map[word] = 0; } |
91 |
||
92 |
// Utilities for ranges of bits. Ranges are half-open [beg, end). |
|
93 |
||
94 |
// Ranges within a single word. |
|
1374 | 95 |
bm_word_t inverted_bit_mask_for_range(idx_t beg, idx_t end) const; |
96 |
void set_range_within_word (idx_t beg, idx_t end); |
|
97 |
void clear_range_within_word (idx_t beg, idx_t end); |
|
98 |
void par_put_range_within_word (idx_t beg, idx_t end, bool value); |
|
1 | 99 |
|
100 |
// Ranges spanning entire words. |
|
1374 | 101 |
void set_range_of_words (idx_t beg, idx_t end); |
102 |
void clear_range_of_words (idx_t beg, idx_t end); |
|
103 |
void set_large_range_of_words (idx_t beg, idx_t end); |
|
104 |
void clear_large_range_of_words (idx_t beg, idx_t end); |
|
1 | 105 |
|
38177 | 106 |
static void clear_range_of_words(bm_word_t* map, idx_t beg, idx_t end); |
107 |
||
1 | 108 |
// The index of the first full word in a range. |
1374 | 109 |
idx_t word_index_round_up(idx_t bit) const; |
1 | 110 |
|
2998
b501bd305780
6849716: BitMap - performance regression introduced with G1
jcoomes
parents:
1374
diff
changeset
|
111 |
// Verification. |
37059
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
112 |
void verify_index(idx_t index) const NOT_DEBUG_RETURN; |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
113 |
void verify_range(idx_t beg_index, idx_t end_index) const NOT_DEBUG_RETURN; |
1 | 114 |
|
2998
b501bd305780
6849716: BitMap - performance regression introduced with G1
jcoomes
parents:
1374
diff
changeset
|
115 |
// Statistics. |
1374 | 116 |
static idx_t* _pop_count_table; |
117 |
static void init_pop_count_table(); |
|
118 |
static idx_t num_set_bits(bm_word_t w); |
|
119 |
static idx_t num_set_bits_from_table(unsigned char c); |
|
1 | 120 |
|
38177 | 121 |
// Allocation Helpers. |
122 |
||
123 |
// Allocates and clears the bitmap memory. |
|
124 |
template <class Allocator> |
|
125 |
static bm_word_t* allocate(const Allocator&, idx_t size_in_bits); |
|
1 | 126 |
|
38177 | 127 |
// Reallocates and clears the new bitmap memory. |
128 |
template <class Allocator> |
|
129 |
static bm_word_t* reallocate(const Allocator&, bm_word_t* map, idx_t old_size_in_bits, idx_t new_size_in_bits); |
|
130 |
||
131 |
// Free the bitmap memory. |
|
132 |
template <class Allocator> |
|
133 |
static void free(const Allocator&, bm_word_t* map, idx_t size_in_bits); |
|
134 |
||
135 |
// Protected functions, that are used by BitMap sub-classes that support them. |
|
1 | 136 |
|
38177 | 137 |
// Resize the backing bitmap memory. |
138 |
// |
|
139 |
// Old bits are transfered to the new memory |
|
140 |
// and the extended memory is cleared. |
|
141 |
template <class Allocator> |
|
142 |
void resize(const Allocator& allocator, idx_t new_size_in_bits); |
|
1 | 143 |
|
38177 | 144 |
// Set up and clear the bitmap memory. |
145 |
// |
|
146 |
// Precondition: The bitmap was default constructed and has |
|
147 |
// not yet had memory allocated via resize or (re)initialize. |
|
148 |
template <class Allocator> |
|
149 |
void initialize(const Allocator& allocator, idx_t size_in_bits); |
|
150 |
||
151 |
// Set up and clear the bitmap memory. |
|
152 |
// |
|
153 |
// Can be called on previously initialized bitmaps. |
|
154 |
template <class Allocator> |
|
155 |
void reinitialize(const Allocator& allocator, idx_t new_size_in_bits); |
|
1 | 156 |
|
1374 | 157 |
// Set the map and size. |
38177 | 158 |
void update(bm_word_t* map, idx_t size) { |
159 |
_map = map; |
|
160 |
_size = size; |
|
161 |
} |
|
1 | 162 |
|
38177 | 163 |
// Protected constructor and destructor. |
164 |
BitMap(bm_word_t* map, idx_t size_in_bits) : _map(map), _size(size_in_bits) {} |
|
165 |
~BitMap() {} |
|
1 | 166 |
|
38177 | 167 |
public: |
37413
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
168 |
// Pretouch the entire range of memory this BitMap covers. |
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
169 |
void pretouch(); |
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
170 |
|
1 | 171 |
// Accessing |
37414
2672ba9af0dc
8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents:
37413
diff
changeset
|
172 |
static idx_t calc_size_in_words(size_t size_in_bits) { |
37413
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
173 |
return word_index(size_in_bits + BitsPerWord - 1); |
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
174 |
} |
2f71679d06dd
8077144: Concurrent mark initialization takes too long
tschatzl
parents:
37059
diff
changeset
|
175 |
|
38177 | 176 |
static idx_t calc_size_in_bytes(size_t size_in_bits) { |
177 |
return calc_size_in_words(size_in_bits) * BytesPerWord; |
|
178 |
} |
|
179 |
||
180 |
idx_t size() const { return _size; } |
|
181 |
idx_t size_in_words() const { return calc_size_in_words(size()); } |
|
182 |
idx_t size_in_bytes() const { return calc_size_in_bytes(size()); } |
|
183 |
||
1 | 184 |
bool at(idx_t index) const { |
185 |
verify_index(index); |
|
186 |
return (*word_addr(index) & bit_mask(index)) != 0; |
|
187 |
} |
|
188 |
||
189 |
// Align bit index up or down to the next bitmap word boundary, or check |
|
190 |
// alignment. |
|
191 |
static idx_t word_align_up(idx_t bit) { |
|
192 |
return align_size_up(bit, BitsPerWord); |
|
193 |
} |
|
194 |
static idx_t word_align_down(idx_t bit) { |
|
195 |
return align_size_down(bit, BitsPerWord); |
|
196 |
} |
|
197 |
static bool is_word_aligned(idx_t bit) { |
|
198 |
return word_align_up(bit) == bit; |
|
199 |
} |
|
200 |
||
201 |
// Set or clear the specified bit. |
|
202 |
inline void set_bit(idx_t bit); |
|
9994 | 203 |
inline void clear_bit(idx_t bit); |
1 | 204 |
|
205 |
// Atomically set or clear the specified bit. |
|
9994 | 206 |
inline bool par_set_bit(idx_t bit); |
207 |
inline bool par_clear_bit(idx_t bit); |
|
1 | 208 |
|
209 |
// Put the given value at the given offset. The parallel version |
|
210 |
// will CAS the value into the bitmap and is quite a bit slower. |
|
211 |
// The parallel version also returns a value indicating if the |
|
212 |
// calling thread was the one that changed the value of the bit. |
|
213 |
void at_put(idx_t index, bool value); |
|
214 |
bool par_at_put(idx_t index, bool value); |
|
215 |
||
216 |
// Update a range of bits. Ranges are half-open [beg, end). |
|
217 |
void set_range (idx_t beg, idx_t end); |
|
218 |
void clear_range (idx_t beg, idx_t end); |
|
219 |
void set_large_range (idx_t beg, idx_t end); |
|
220 |
void clear_large_range (idx_t beg, idx_t end); |
|
221 |
void at_put_range(idx_t beg, idx_t end, bool value); |
|
222 |
void par_at_put_range(idx_t beg, idx_t end, bool value); |
|
223 |
void at_put_large_range(idx_t beg, idx_t end, bool value); |
|
224 |
void par_at_put_large_range(idx_t beg, idx_t end, bool value); |
|
225 |
||
226 |
// Update a range of bits, using a hint about the size. Currently only |
|
227 |
// inlines the predominant case of a 1-bit range. Works best when hint is a |
|
228 |
// compile-time constant. |
|
1374 | 229 |
void set_range(idx_t beg, idx_t end, RangeSizeHint hint); |
230 |
void clear_range(idx_t beg, idx_t end, RangeSizeHint hint); |
|
231 |
void par_set_range(idx_t beg, idx_t end, RangeSizeHint hint); |
|
232 |
void par_clear_range (idx_t beg, idx_t end, RangeSizeHint hint); |
|
233 |
||
1 | 234 |
// Clearing |
235 |
void clear_large(); |
|
1374 | 236 |
inline void clear(); |
1 | 237 |
|
1374 | 238 |
// Iteration support. Returns "true" if the iteration completed, false |
239 |
// if the iteration terminated early (because the closure "blk" returned |
|
240 |
// false). |
|
241 |
bool iterate(BitMapClosure* blk, idx_t leftIndex, idx_t rightIndex); |
|
242 |
bool iterate(BitMapClosure* blk) { |
|
1 | 243 |
// call the version that takes an interval |
1374 | 244 |
return iterate(blk, 0, size()); |
1 | 245 |
} |
246 |
||
1374 | 247 |
// Looking for 1's and 0's at indices equal to or greater than "l_index", |
248 |
// stopping if none has been found before "r_index", and returning |
|
249 |
// "r_index" (which must be at most "size") in that case. |
|
250 |
idx_t get_next_one_offset_inline (idx_t l_index, idx_t r_index) const; |
|
251 |
idx_t get_next_zero_offset_inline(idx_t l_index, idx_t r_index) const; |
|
252 |
||
253 |
// Like "get_next_one_offset_inline", except requires that "r_index" is |
|
254 |
// aligned to bitsizeof(bm_word_t). |
|
255 |
idx_t get_next_one_offset_inline_aligned_right(idx_t l_index, |
|
256 |
idx_t r_index) const; |
|
257 |
||
258 |
// Non-inline versionsof the above. |
|
1 | 259 |
idx_t get_next_one_offset (idx_t l_index, idx_t r_index) const; |
260 |
idx_t get_next_zero_offset(idx_t l_index, idx_t r_index) const; |
|
261 |
||
262 |
idx_t get_next_one_offset(idx_t offset) const { |
|
263 |
return get_next_one_offset(offset, size()); |
|
264 |
} |
|
265 |
idx_t get_next_zero_offset(idx_t offset) const { |
|
266 |
return get_next_zero_offset(offset, size()); |
|
267 |
} |
|
268 |
||
1374 | 269 |
// Returns the number of bits set in the bitmap. |
270 |
idx_t count_one_bits() const; |
|
1 | 271 |
|
272 |
// Set operations. |
|
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
273 |
void set_union(const BitMap& bits); |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
274 |
void set_difference(const BitMap& bits); |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
275 |
void set_intersection(const BitMap& bits); |
1 | 276 |
// Returns true iff "this" is a superset of "bits". |
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
277 |
bool contains(const BitMap& bits) const; |
1 | 278 |
// Returns true iff "this and "bits" have a non-empty intersection. |
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
279 |
bool intersects(const BitMap& bits) const; |
1 | 280 |
|
281 |
// Returns result of whether this map changed |
|
282 |
// during the operation |
|
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
283 |
bool set_union_with_result(const BitMap& bits); |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
284 |
bool set_difference_with_result(const BitMap& bits); |
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
285 |
bool set_intersection_with_result(const BitMap& bits); |
1 | 286 |
|
38102
839593075df1
8141496: BitMap set operations copy their other BitMap argument
stefank
parents:
37466
diff
changeset
|
287 |
void set_from(const BitMap& bits); |
1 | 288 |
|
40639
83c879c8db57
8155043: BitMap set operations assume clear bits beyond unaligned end
kbarrett
parents:
39219
diff
changeset
|
289 |
bool is_same(const BitMap& bits) const; |
1 | 290 |
|
291 |
// Test if all bits are set or cleared |
|
292 |
bool is_full() const; |
|
293 |
bool is_empty() const; |
|
294 |
||
16685
41c34debcde0
8011872: Include Bit Map addresses in the hs_err files
stefank
parents:
12272
diff
changeset
|
295 |
void print_on_error(outputStream* st, const char* prefix) const; |
1 | 296 |
|
297 |
#ifndef PRODUCT |
|
298 |
public: |
|
299 |
// Printing |
|
300 |
void print_on(outputStream* st) const; |
|
301 |
#endif |
|
302 |
}; |
|
303 |
||
38177 | 304 |
// A concrete implementation of the the "abstract" BitMap class. |
305 |
// |
|
306 |
// The BitMapView is used when the backing storage is managed externally. |
|
307 |
class BitMapView : public BitMap { |
|
308 |
public: |
|
309 |
BitMapView() : BitMap(NULL, 0) {} |
|
310 |
BitMapView(bm_word_t* map, idx_t size_in_bits) : BitMap(map, size_in_bits) {} |
|
311 |
}; |
|
312 |
||
313 |
// A BitMap with storage in a ResourceArea. |
|
314 |
class ResourceBitMap : public BitMap { |
|
315 |
friend class TestBitMap; |
|
316 |
||
317 |
public: |
|
318 |
ResourceBitMap() : BitMap(NULL, 0) {} |
|
319 |
// Clears the bitmap memory. |
|
320 |
ResourceBitMap(idx_t size_in_bits); |
|
321 |
||
322 |
// Resize the backing bitmap memory. |
|
323 |
// |
|
324 |
// Old bits are transfered to the new memory |
|
325 |
// and the extended memory is cleared. |
|
326 |
void resize(idx_t new_size_in_bits); |
|
327 |
||
328 |
// Set up and clear the bitmap memory. |
|
329 |
// |
|
330 |
// Precondition: The bitmap was default constructed and has |
|
331 |
// not yet had memory allocated via resize or initialize. |
|
332 |
void initialize(idx_t size_in_bits); |
|
333 |
||
334 |
// Set up and clear the bitmap memory. |
|
335 |
// |
|
336 |
// Can be called on previously initialized bitmaps. |
|
337 |
void reinitialize(idx_t size_in_bits); |
|
338 |
}; |
|
339 |
||
340 |
// A BitMap with storage in a specific Arena. |
|
341 |
class ArenaBitMap : public BitMap { |
|
342 |
public: |
|
343 |
// Clears the bitmap memory. |
|
344 |
ArenaBitMap(Arena* arena, idx_t size_in_bits); |
|
345 |
||
346 |
private: |
|
347 |
// Don't allow copy or assignment. |
|
348 |
ArenaBitMap(const ArenaBitMap&); |
|
349 |
ArenaBitMap& operator=(const ArenaBitMap&); |
|
350 |
}; |
|
351 |
||
352 |
// A BitMap with storage in the CHeap. |
|
353 |
class CHeapBitMap : public BitMap { |
|
354 |
friend class TestBitMap; |
|
355 |
||
356 |
private: |
|
357 |
// Don't allow copy or assignment, to prevent the |
|
358 |
// allocated memory from leaking out to other instances. |
|
359 |
CHeapBitMap(const CHeapBitMap&); |
|
360 |
CHeapBitMap& operator=(const CHeapBitMap&); |
|
361 |
||
362 |
public: |
|
363 |
CHeapBitMap() : BitMap(NULL, 0) {} |
|
364 |
// Clears the bitmap memory. |
|
365 |
CHeapBitMap(idx_t size_in_bits); |
|
366 |
~CHeapBitMap(); |
|
367 |
||
368 |
// Resize the backing bitmap memory. |
|
369 |
// |
|
370 |
// Old bits are transfered to the new memory |
|
371 |
// and the extended memory is cleared. |
|
372 |
void resize(idx_t new_size_in_bits); |
|
373 |
||
374 |
// Set up and clear the bitmap memory. |
|
375 |
// |
|
376 |
// Precondition: The bitmap was default constructed and has |
|
377 |
// not yet had memory allocated via resize or initialize. |
|
378 |
void initialize(idx_t size_in_bits); |
|
379 |
||
380 |
// Set up and clear the bitmap memory. |
|
381 |
// |
|
382 |
// Can be called on previously initialized bitmaps. |
|
383 |
void reinitialize(idx_t size_in_bits); |
|
384 |
}; |
|
385 |
||
1 | 386 |
// Convenience class wrapping BitMap which provides multiple bits per slot. |
387 |
class BitMap2D VALUE_OBJ_CLASS_SPEC { |
|
388 |
public: |
|
1374 | 389 |
typedef BitMap::idx_t idx_t; // Type used for bit and word indices. |
390 |
typedef BitMap::bm_word_t bm_word_t; // Element type of array that |
|
391 |
// represents the bitmap. |
|
1 | 392 |
private: |
38177 | 393 |
ResourceBitMap _map; |
394 |
idx_t _bits_per_slot; |
|
1 | 395 |
|
396 |
idx_t bit_index(idx_t slot_index, idx_t bit_within_slot_index) const { |
|
397 |
return slot_index * _bits_per_slot + bit_within_slot_index; |
|
398 |
} |
|
399 |
||
400 |
void verify_bit_within_slot_index(idx_t index) const { |
|
401 |
assert(index < _bits_per_slot, "bit_within_slot index out of bounds"); |
|
402 |
} |
|
403 |
||
404 |
public: |
|
405 |
// Construction. bits_per_slot must be greater than 0. |
|
38177 | 406 |
BitMap2D(idx_t bits_per_slot) : |
407 |
_map(), _bits_per_slot(bits_per_slot) {} |
|
1 | 408 |
|
409 |
// Allocates necessary data structure in resource area. bits_per_slot must be greater than 0. |
|
38177 | 410 |
BitMap2D(idx_t size_in_slots, idx_t bits_per_slot) : |
411 |
_map(size_in_slots * bits_per_slot), _bits_per_slot(bits_per_slot) {} |
|
1 | 412 |
|
413 |
idx_t size_in_bits() { |
|
414 |
return _map.size(); |
|
415 |
} |
|
416 |
||
417 |
// Returns number of full slots that have been allocated |
|
418 |
idx_t size_in_slots() { |
|
419 |
// Round down |
|
420 |
return _map.size() / _bits_per_slot; |
|
421 |
} |
|
422 |
||
37059
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
423 |
bool is_valid_index(idx_t slot_index, idx_t bit_within_slot_index); |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
424 |
bool at(idx_t slot_index, idx_t bit_within_slot_index) const; |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
425 |
void set_bit(idx_t slot_index, idx_t bit_within_slot_index); |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
426 |
void clear_bit(idx_t slot_index, idx_t bit_within_slot_index); |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
427 |
void at_put(idx_t slot_index, idx_t bit_within_slot_index, bool value); |
c482915a21aa
8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents:
37058
diff
changeset
|
428 |
void at_put_grow(idx_t slot_index, idx_t bit_within_slot_index, bool value); |
1 | 429 |
}; |
430 |
||
1374 | 431 |
// Closure for iterating over BitMaps |
1 | 432 |
|
1374 | 433 |
class BitMapClosure VALUE_OBJ_CLASS_SPEC { |
434 |
public: |
|
435 |
// Callback when bit in map is set. Should normally return "true"; |
|
436 |
// return of false indicates that the bitmap iteration should terminate. |
|
437 |
virtual bool do_bit(BitMap::idx_t offset) = 0; |
|
438 |
}; |
|
7397 | 439 |
|
440 |
#endif // SHARE_VM_UTILITIES_BITMAP_HPP |