< prev index next >

src/hotspot/share/utilities/bitMap.inline.hpp

Print this page

 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  *
 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 #ifndef SHARE_UTILITIES_BITMAP_INLINE_HPP
 26 #define SHARE_UTILITIES_BITMAP_INLINE_HPP
 27 
 28 #include "utilities/bitMap.hpp"
 29 

 30 #include "runtime/atomic.hpp"
 31 #include "utilities/align.hpp"
 32 #include "utilities/count_trailing_zeros.hpp"
 33 
 34 inline void BitMap::set_bit(idx_t bit) {
 35   verify_index(bit);
 36   *word_addr(bit) |= bit_mask(bit);
 37 }
 38 
 39 inline void BitMap::clear_bit(idx_t bit) {
 40   verify_index(bit);
 41   *word_addr(bit) &= ~bit_mask(bit);
 42 }
 43 
 44 inline const BitMap::bm_word_t BitMap::load_word_ordered(const volatile bm_word_t* const addr, atomic_memory_order memory_order) {
 45   if (memory_order == memory_order_relaxed || memory_order == memory_order_release) {
 46     return Atomic::load(addr);
 47   } else {
 48     assert(memory_order == memory_order_acq_rel ||
 49            memory_order == memory_order_acquire ||

226     }
227   }
228   return r_index;
229 }
230 
231 inline BitMap::idx_t
232 BitMap::get_next_one_offset(idx_t l_offset, idx_t r_offset) const {
233   return get_next_bit_impl<find_ones_flip, false>(l_offset, r_offset);
234 }
235 
236 inline BitMap::idx_t
237 BitMap::get_next_zero_offset(idx_t l_offset, idx_t r_offset) const {
238   return get_next_bit_impl<find_zeros_flip, false>(l_offset, r_offset);
239 }
240 
241 inline BitMap::idx_t
242 BitMap::get_next_one_offset_aligned_right(idx_t l_offset, idx_t r_offset) const {
243   return get_next_bit_impl<find_ones_flip, true>(l_offset, r_offset);
244 }
245 
246 inline bool BitMap::iterate(BitMapClosure* cl, idx_t beg, idx_t end) {

247   for (idx_t index = beg; true; ++index) {
248     index = get_next_one_offset(index, end);
249     if (index >= end) {
250       return true;
251     } else if (!cl->do_bit(index)) {
252       return false;
253     }
254   }
255 }
256 
257 inline bool BitMap::iterate(BitMapClosure* cl) {

258   return iterate(cl, 0, size());
259 }
260 
261 // Returns a bit mask for a range of bits [beg, end) within a single word.  Each
262 // bit in the mask is 0 if the bit is in the range, 1 if not in the range.  The
263 // returned mask can be used directly to clear the range, or inverted to set the
264 // range.  Note:  end must not be 0.
265 inline BitMap::bm_word_t
266 BitMap::inverted_bit_mask_for_range(idx_t beg, idx_t end) const {
267   assert(end != 0, "does not work when end == 0");
268   assert(beg == end || to_words_align_down(beg) == to_words_align_down(end - 1),
269          "must be a single-word range");
270   bm_word_t mask = bit_mask(beg) - 1;   // low (right) bits
271   if (bit_in_word(end) != 0) {
272     mask |= ~(bit_mask(end) - 1);       // high (left) bits
273   }
274   return mask;
275 }
276 
277 inline void BitMap::set_large_range_of_words(idx_t beg, idx_t end) {

 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  *
 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 #ifndef SHARE_UTILITIES_BITMAP_INLINE_HPP
 26 #define SHARE_UTILITIES_BITMAP_INLINE_HPP
 27 
 28 #include "utilities/bitMap.hpp"
 29 
 30 #include "memory/iterator.inline.hpp"
 31 #include "runtime/atomic.hpp"
 32 #include "utilities/align.hpp"
 33 #include "utilities/count_trailing_zeros.hpp"
 34 
 35 inline void BitMap::set_bit(idx_t bit) {
 36   verify_index(bit);
 37   *word_addr(bit) |= bit_mask(bit);
 38 }
 39 
 40 inline void BitMap::clear_bit(idx_t bit) {
 41   verify_index(bit);
 42   *word_addr(bit) &= ~bit_mask(bit);
 43 }
 44 
 45 inline const BitMap::bm_word_t BitMap::load_word_ordered(const volatile bm_word_t* const addr, atomic_memory_order memory_order) {
 46   if (memory_order == memory_order_relaxed || memory_order == memory_order_release) {
 47     return Atomic::load(addr);
 48   } else {
 49     assert(memory_order == memory_order_acq_rel ||
 50            memory_order == memory_order_acquire ||

227     }
228   }
229   return r_index;
230 }
231 
232 inline BitMap::idx_t
233 BitMap::get_next_one_offset(idx_t l_offset, idx_t r_offset) const {
234   return get_next_bit_impl<find_ones_flip, false>(l_offset, r_offset);
235 }
236 
237 inline BitMap::idx_t
238 BitMap::get_next_zero_offset(idx_t l_offset, idx_t r_offset) const {
239   return get_next_bit_impl<find_zeros_flip, false>(l_offset, r_offset);
240 }
241 
242 inline BitMap::idx_t
243 BitMap::get_next_one_offset_aligned_right(idx_t l_offset, idx_t r_offset) const {
244   return get_next_bit_impl<find_ones_flip, true>(l_offset, r_offset);
245 }
246 
247 template <class BitMapClosureType>
248 inline bool BitMap::iterate(BitMapClosureType* cl, idx_t beg, idx_t end) {
249   for (idx_t index = beg; true; ++index) {
250     index = get_next_one_offset(index, end);
251     if (index >= end) {
252       return true;
253     } else if (!Devirtualizer::do_bit(cl, index)) {
254       return false;
255     }
256   }
257 }
258 
259 template <class BitMapClosureType>
260 inline bool BitMap::iterate(BitMapClosureType* cl) {
261   return iterate(cl, 0, size());
262 }
263 
264 // Returns a bit mask for a range of bits [beg, end) within a single word.  Each
265 // bit in the mask is 0 if the bit is in the range, 1 if not in the range.  The
266 // returned mask can be used directly to clear the range, or inverted to set the
267 // range.  Note:  end must not be 0.
268 inline BitMap::bm_word_t
269 BitMap::inverted_bit_mask_for_range(idx_t beg, idx_t end) const {
270   assert(end != 0, "does not work when end == 0");
271   assert(beg == end || to_words_align_down(beg) == to_words_align_down(end - 1),
272          "must be a single-word range");
273   bm_word_t mask = bit_mask(beg) - 1;   // low (right) bits
274   if (bit_in_word(end) != 0) {
275     mask |= ~(bit_mask(end) - 1);       // high (left) bits
276   }
277   return mask;
278 }
279 
280 inline void BitMap::set_large_range_of_words(idx_t beg, idx_t end) {
< prev index next >