1 /*
   2  * Copyright (c) 2015, 2018, 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 // Concurrent marking bit map wrapper
  26 
  27 #include "precompiled.hpp"
  28 #include "gc/shared/markBitMap.inline.hpp"
  29 #include "utilities/bitMap.inline.hpp"
  30 
  31 MarkBitMapRO::MarkBitMapRO(int shifter) :
  32   _bm(),
  33   _shifter(shifter) {
  34   _bmStartWord = 0;
  35   _bmWordSize = 0;
  36 }
  37 
  38 #ifndef PRODUCT
  39 bool MarkBitMapRO::covers(MemRegion heap_rs) const {
  40   // assert(_bm.map() == _virtual_space.low(), "map inconsistency");
  41   assert(((size_t)_bm.size() * ((size_t)1 << _shifter)) == _bmWordSize,
  42          "size inconsistency");
  43   return _bmStartWord == (HeapWord*)(heap_rs.start()) &&
  44          _bmWordSize  == heap_rs.word_size();
  45 }
  46 #endif
  47 
  48 void MarkBitMapRO::print_on_error(outputStream* st, const char* prefix) const {
  49   _bm.print_on_error(st, prefix);
  50 }
  51 
  52 size_t MarkBitMap::compute_size(size_t heap_size) {
  53   return ReservedSpace::allocation_align_size_up(heap_size / mark_distance());
  54 }
  55 
  56 size_t MarkBitMap::mark_distance() {
  57   return MinObjAlignmentInBytes * BitsPerByte;
  58 }
  59 
  60 void MarkBitMap::initialize(MemRegion heap, MemRegion bitmap) {
  61   _bmStartWord = heap.start();
  62   _bmWordSize = heap.word_size();
  63 
  64   _bm = BitMapView((BitMap::bm_word_t*) bitmap.start(), _bmWordSize >> _shifter);
  65   _covered = heap;
  66 }
  67 
  68 void MarkBitMap::do_clear(MemRegion mr, bool large) {
  69   MemRegion intersection = mr.intersection(_covered);
  70   assert(!intersection.is_empty(),
  71          "Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
  72          p2i(mr.start()), p2i(mr.end()));
  73   // convert address range into offset range
  74   size_t beg = heapWordToOffset(intersection.start());
  75   size_t end = heapWordToOffset(intersection.end());
  76   if (large) {
  77     _bm.clear_large_range(beg, end);
  78   } else {
  79     _bm.clear_range(beg, end);
  80   }
  81 }
  82