1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
177 clear_range_within_word(beg, bit_index(beg_full_word)); |
177 clear_range_within_word(beg, bit_index(beg_full_word)); |
178 clear_large_range_of_words(beg_full_word, end_full_word); |
178 clear_large_range_of_words(beg_full_word, end_full_word); |
179 clear_range_within_word(bit_index(end_full_word), end); |
179 clear_range_within_word(bit_index(end_full_word), end); |
180 } |
180 } |
181 |
181 |
182 void BitMap::mostly_disjoint_range_union(BitMap* from_bitmap, |
|
183 idx_t from_start_index, |
|
184 idx_t to_start_index, |
|
185 size_t word_num) { |
|
186 // Ensure that the parameters are correct. |
|
187 // These shouldn't be that expensive to check, hence I left them as |
|
188 // guarantees. |
|
189 guarantee(from_bitmap->bit_in_word(from_start_index) == 0, |
|
190 "it should be aligned on a word boundary"); |
|
191 guarantee(bit_in_word(to_start_index) == 0, |
|
192 "it should be aligned on a word boundary"); |
|
193 guarantee(word_num >= 2, "word_num should be at least 2"); |
|
194 |
|
195 intptr_t* from = (intptr_t*) from_bitmap->word_addr(from_start_index); |
|
196 intptr_t* to = (intptr_t*) word_addr(to_start_index); |
|
197 |
|
198 if (*from != 0) { |
|
199 // if it's 0, then there's no point in doing the CAS |
|
200 while (true) { |
|
201 intptr_t old_value = *to; |
|
202 intptr_t new_value = old_value | *from; |
|
203 intptr_t res = Atomic::cmpxchg_ptr(new_value, to, old_value); |
|
204 if (res == old_value) break; |
|
205 } |
|
206 } |
|
207 ++from; |
|
208 ++to; |
|
209 |
|
210 for (size_t i = 0; i < word_num - 2; ++i) { |
|
211 if (*from != 0) { |
|
212 // if it's 0, then there's no point in doing the CAS |
|
213 assert(*to == 0, "nobody else should be writing here"); |
|
214 intptr_t new_value = *from; |
|
215 *to = new_value; |
|
216 } |
|
217 |
|
218 ++from; |
|
219 ++to; |
|
220 } |
|
221 |
|
222 if (*from != 0) { |
|
223 // if it's 0, then there's no point in doing the CAS |
|
224 while (true) { |
|
225 intptr_t old_value = *to; |
|
226 intptr_t new_value = old_value | *from; |
|
227 intptr_t res = Atomic::cmpxchg_ptr(new_value, to, old_value); |
|
228 if (res == old_value) break; |
|
229 } |
|
230 } |
|
231 |
|
232 // the -1 is because we didn't advance them after the final CAS |
|
233 assert(from == |
|
234 (intptr_t*) from_bitmap->word_addr(from_start_index) + word_num - 1, |
|
235 "invariant"); |
|
236 assert(to == (intptr_t*) word_addr(to_start_index) + word_num - 1, |
|
237 "invariant"); |
|
238 } |
|
239 |
|
240 void BitMap::at_put(idx_t offset, bool value) { |
182 void BitMap::at_put(idx_t offset, bool value) { |
241 if (value) { |
183 if (value) { |
242 set_bit(offset); |
184 set_bit(offset); |
243 } else { |
185 } else { |
244 clear_bit(offset); |
186 clear_bit(offset); |