1 /*
 2  * Copyright (c) 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 #include "precompiled.hpp"
26 #include "gc/shared/markBitMap.inline.hpp"
27 #include "memory/universe.hpp"
28 #include "memory/virtualspace.hpp"
29 
30 void MarkBitMap::print_on_error(outputStream* st, const char* prefix) const {
31   _bm.print_on_error(st, prefix);
32 }
33 
34 size_t MarkBitMap::compute_size(size_t heap_size) {
35   return ReservedSpace::allocation_align_size_up(heap_size / mark_distance());
36 }
37 
38 size_t MarkBitMap::mark_distance() {
39   return MinObjAlignmentInBytes * BitsPerByte;
40 }
41 
42 void MarkBitMap::initialize(MemRegion heap, MemRegion storage) {
43   _covered = heap;
44 
45   _bm = BitMapView((BitMap::bm_word_t*) storage.start(), _covered.word_size() >> _shifter);
46 }
47 
48 void MarkBitMap::do_clear(MemRegion mr, bool large) {
49   MemRegion intersection = mr.intersection(_covered);
50   assert(!intersection.is_empty(),
51          "Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
52          p2i(mr.start()), p2i(mr.end()));
53   // convert address range into offset range
54   size_t beg = addr_to_offset(intersection.start());
55   size_t end = addr_to_offset(intersection.end());
56   if (large) {
57     _bm.clear_large_range(beg, end);
58   } else {
59     _bm.clear_range(beg, end);
60   }
61 }
62 
63 size_t MarkBitMap::count_marked(MemRegion mr) {
64   MemRegion intersection = mr.intersection(_covered);
65   assert(!intersection.is_empty(),
66          "Given range from " PTR_FORMAT " to " PTR_FORMAT " is completely outside the heap",
67          p2i(mr.start()), p2i(mr.end()));
68   // convert address range into offset range
69   size_t beg = addr_to_offset(intersection.start());
70   size_t end = addr_to_offset(intersection.end());
71   return _bm.count_one_bits(beg, end);
72 }
73 
74 #ifdef ASSERT
75 void MarkBitMap::check_mark(HeapWord* addr) {
76   assert(Universe::heap()->is_in(addr),
77          "Trying to access bitmap " PTR_FORMAT " for address " PTR_FORMAT " not in the heap.",
78          p2i(this), p2i(addr));
79 }
80 #endif