1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   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  *
  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_VM_GC_SHARED_CMBITMAP_INLINE_HPP
  26 #define SHARE_VM_GC_SHARED_CMBITMAP_INLINE_HPP
  27 
  28 #include "gc/shared/cmBitMap.hpp"
  29 #include "utilities/bitMap.inline.hpp"
  30 
  31 inline bool CMBitMapRO::iterate(BitMapClosure* cl, MemRegion mr) {
  32   HeapWord* start_addr = MAX2(startWord(), mr.start());
  33   HeapWord* end_addr = MIN2(endWord(), mr.end());
  34 
  35   if (end_addr > start_addr) {
  36     // Right-open interval [start-offset, end-offset).
  37     BitMap::idx_t start_offset = heapWordToOffset(start_addr);
  38     BitMap::idx_t end_offset = heapWordToOffset(end_addr);
  39 
  40     start_offset = _bm.get_next_one_offset(start_offset, end_offset);
  41     while (start_offset < end_offset) {
  42       if (!cl->do_bit(start_offset)) {
  43         return false;
  44       }
  45       HeapWord* next_addr = MIN2(nextObject(offsetToHeapWord(start_offset)), end_addr);
  46       BitMap::idx_t next_offset = heapWordToOffset(next_addr);
  47       start_offset = _bm.get_next_one_offset(next_offset, end_offset);
  48     }
  49   }
  50   return true;
  51 }
  52 
  53 inline bool CMBitMapRO::iterate(BitMapClosure* cl) {
  54   MemRegion mr(startWord(), sizeInWords());
  55   return iterate(cl, mr);
  56 }
  57 
  58 #define check_mark(addr)                                                       \
  59   assert(_bmStartWord <= (addr) && (addr) < (_bmStartWord + _bmWordSize),      \
  60          "outside underlying space?");                                         \
  61   /* assert(G1CollectedHeap::heap()->is_in_exact(addr),                  \
  62          err_msg("Trying to access not available bitmap "PTR_FORMAT            \
  63                  " corresponding to "PTR_FORMAT" (%u)",                        \
  64                  p2i(this), p2i(addr), G1CollectedHeap::heap()->addr_to_region(addr))); */
  65 
  66 inline void CMBitMap::mark(HeapWord* addr) {
  67   check_mark(addr);
  68   _bm.set_bit(heapWordToOffset(addr));
  69 }
  70 
  71 inline void CMBitMap::clear(HeapWord* addr) {
  72   check_mark(addr);
  73   _bm.clear_bit(heapWordToOffset(addr));
  74 }
  75 
  76 inline bool CMBitMap::parMark(HeapWord* addr) {
  77   check_mark(addr);
  78   return _bm.par_set_bit(heapWordToOffset(addr));
  79 }
  80 
  81 inline bool CMBitMap::parClear(HeapWord* addr) {
  82   check_mark(addr);
  83   return _bm.par_clear_bit(heapWordToOffset(addr));
  84 }
  85 
  86 #undef check_mark
  87 
  88 #endif // SHARE_VM_GC_SHARED_CMBITMAP_INLINE_HPP