1 /*
2 * Copyright (c) 2005, 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/parallel/parMarkBitMap.inline.hpp"
27 #include "gc/parallel/psCompactionManager.inline.hpp"
28 #include "gc/parallel/psParallelCompact.inline.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/os.hpp"
32 #include "services/memTracker.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/bitMap.inline.hpp"
35
36 bool
37 ParMarkBitMap::initialize(MemRegion covered_region)
38 {
39 const idx_t bits = bits_required(covered_region);
40 // The bits will be divided evenly between two bitmaps; each of them should be
41 // an integral number of words.
42 assert(bits % (BitsPerWord * 2) == 0, "region size unaligned");
43
44 const size_t words = bits / BitsPerWord;
45 const size_t raw_bytes = words * sizeof(idx_t);
46 const size_t page_sz = os::page_size_for_region_aligned(raw_bytes, 10);
47 const size_t granularity = os::vm_allocation_granularity();
48 _reserved_byte_size = align_up(raw_bytes, MAX2(page_sz, granularity));
49
50 const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 :
51 MAX2(page_sz, granularity);
52 ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0);
53 os::trace_page_sizes("Mark Bitmap", raw_bytes, raw_bytes, page_sz,
54 rs.base(), rs.size());
55
56 MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
57
58 _virtual_space = new PSVirtualSpace(rs, page_sz);
59 if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) {
60 _region_start = covered_region.start();
61 _region_size = covered_region.word_size();
62 BitMap::bm_word_t* map = (BitMap::bm_word_t*)_virtual_space->reserved_low_addr();
101 return cm->last_query_begin() == beg_addr;
102 }
103
104 inline void
105 ParMarkBitMap::update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const {
106 cm->set_last_query_begin(beg_addr);
107 cm->set_last_query_object(end_obj);
108 cm->set_last_query_return(result);
109 }
110
111 size_t
112 ParMarkBitMap::live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const
113 {
114 assert(beg_addr <= (HeapWord*)end_obj, "bad range");
115 assert(is_marked(end_obj), "end_obj must be live");
116
117 idx_t live_bits = 0;
118
119 // The bitmap routines require the right boundary to be word-aligned.
120 const idx_t end_bit = addr_to_bit((HeapWord*)end_obj);
121 const idx_t range_end = BitMap::word_align_up(end_bit);
122
123 idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);
124 while (beg_bit < end_bit) {
125 idx_t tmp_end = find_obj_end(beg_bit, range_end);
126 assert(tmp_end < end_bit, "missing end bit");
127 live_bits += tmp_end - beg_bit + 1;
128 beg_bit = find_obj_beg(tmp_end + 1, range_end);
129 }
130 return bits_to_words(live_bits);
131 }
132
133 size_t
134 ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_oop) const
135 {
136 HeapWord* last_beg = cm->last_query_begin();
137 HeapWord* last_obj = (HeapWord*)cm->last_query_object();
138 HeapWord* end_obj = (HeapWord*)end_oop;
139
140 size_t last_ret = cm->last_query_return();
141 if (end_obj > last_obj) {
160 ParMarkBitMap::live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const
161 {
162 // Try to reuse result from ParCompactionManager cache first.
163 if (is_live_words_in_range_in_cache(cm, beg_addr)) {
164 return live_words_in_range_use_cache(cm, beg_addr, end_obj);
165 }
166 size_t ret = live_words_in_range_helper(beg_addr, end_obj);
167 update_live_words_in_range_cache(cm, beg_addr, end_obj, ret);
168 return ret;
169 }
170
171 ParMarkBitMap::IterationStatus
172 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
173 idx_t range_beg, idx_t range_end) const
174 {
175 DEBUG_ONLY(verify_bit(range_beg);)
176 DEBUG_ONLY(verify_bit(range_end);)
177 assert(range_beg <= range_end, "live range invalid");
178
179 // The bitmap routines require the right boundary to be word-aligned.
180 const idx_t search_end = BitMap::word_align_up(range_end);
181
182 idx_t cur_beg = find_obj_beg(range_beg, search_end);
183 while (cur_beg < range_end) {
184 const idx_t cur_end = find_obj_end(cur_beg, search_end);
185 if (cur_end >= range_end) {
186 // The obj ends outside the range.
187 live_closure->set_source(bit_to_addr(cur_beg));
188 return incomplete;
189 }
190
191 const size_t size = obj_size(cur_beg, cur_end);
192 IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
193 if (status != incomplete) {
194 assert(status == would_overflow || status == full, "sanity");
195 return status;
196 }
197
198 // Successfully processed the object; look for the next object.
199 cur_beg = find_obj_beg(cur_end + 1, search_end);
200 }
201
202 live_closure->set_source(bit_to_addr(range_end));
203 return complete;
204 }
205
206 ParMarkBitMap::IterationStatus
207 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
208 ParMarkBitMapClosure* dead_closure,
209 idx_t range_beg, idx_t range_end,
210 idx_t dead_range_end) const
211 {
212 DEBUG_ONLY(verify_bit(range_beg);)
213 DEBUG_ONLY(verify_bit(range_end);)
214 DEBUG_ONLY(verify_bit(dead_range_end);)
215 assert(range_beg <= range_end, "live range invalid");
216 assert(range_end <= dead_range_end, "dead range invalid");
217
218 // The bitmap routines require the right boundary to be word-aligned.
219 const idx_t live_search_end = BitMap::word_align_up(range_end);
220 const idx_t dead_search_end = BitMap::word_align_up(dead_range_end);
221
222 idx_t cur_beg = range_beg;
223 if (range_beg < range_end && is_unmarked(range_beg)) {
224 // The range starts with dead space. Look for the next object, then fill.
225 cur_beg = find_obj_beg(range_beg + 1, dead_search_end);
226 const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
227 const size_t size = obj_size(range_beg, dead_space_end);
228 dead_closure->do_addr(bit_to_addr(range_beg), size);
229 }
230
231 while (cur_beg < range_end) {
232 const idx_t cur_end = find_obj_end(cur_beg, live_search_end);
233 if (cur_end >= range_end) {
234 // The obj ends outside the range.
235 live_closure->set_source(bit_to_addr(cur_beg));
236 return incomplete;
237 }
238
239 const size_t size = obj_size(cur_beg, cur_end);
240 IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
|
1 /*
2 * Copyright (c) 2005, 2019, 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/parallel/parMarkBitMap.inline.hpp"
27 #include "gc/parallel/psCompactionManager.inline.hpp"
28 #include "gc/parallel/psParallelCompact.inline.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/os.hpp"
32 #include "services/memTracker.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/bitMap.inline.hpp"
35
36 bool
37 ParMarkBitMap::initialize(MemRegion covered_region)
38 {
39 const idx_t bits = bits_required(covered_region);
40 // The bits will be divided evenly between two bitmaps; each of them should be
41 // an integral number of words.
42 assert(is_aligned(bits, (BitsPerWord * 2)), "region size unaligned");
43
44 const size_t words = bits / BitsPerWord;
45 const size_t raw_bytes = words * sizeof(idx_t);
46 const size_t page_sz = os::page_size_for_region_aligned(raw_bytes, 10);
47 const size_t granularity = os::vm_allocation_granularity();
48 _reserved_byte_size = align_up(raw_bytes, MAX2(page_sz, granularity));
49
50 const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 :
51 MAX2(page_sz, granularity);
52 ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0);
53 os::trace_page_sizes("Mark Bitmap", raw_bytes, raw_bytes, page_sz,
54 rs.base(), rs.size());
55
56 MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
57
58 _virtual_space = new PSVirtualSpace(rs, page_sz);
59 if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) {
60 _region_start = covered_region.start();
61 _region_size = covered_region.word_size();
62 BitMap::bm_word_t* map = (BitMap::bm_word_t*)_virtual_space->reserved_low_addr();
101 return cm->last_query_begin() == beg_addr;
102 }
103
104 inline void
105 ParMarkBitMap::update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const {
106 cm->set_last_query_begin(beg_addr);
107 cm->set_last_query_object(end_obj);
108 cm->set_last_query_return(result);
109 }
110
111 size_t
112 ParMarkBitMap::live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const
113 {
114 assert(beg_addr <= (HeapWord*)end_obj, "bad range");
115 assert(is_marked(end_obj), "end_obj must be live");
116
117 idx_t live_bits = 0;
118
119 // The bitmap routines require the right boundary to be word-aligned.
120 const idx_t end_bit = addr_to_bit((HeapWord*)end_obj);
121 const idx_t range_end = align_range_end(end_bit);
122
123 idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);
124 while (beg_bit < end_bit) {
125 idx_t tmp_end = find_obj_end(beg_bit, range_end);
126 assert(tmp_end < end_bit, "missing end bit");
127 live_bits += tmp_end - beg_bit + 1;
128 beg_bit = find_obj_beg(tmp_end + 1, range_end);
129 }
130 return bits_to_words(live_bits);
131 }
132
133 size_t
134 ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_oop) const
135 {
136 HeapWord* last_beg = cm->last_query_begin();
137 HeapWord* last_obj = (HeapWord*)cm->last_query_object();
138 HeapWord* end_obj = (HeapWord*)end_oop;
139
140 size_t last_ret = cm->last_query_return();
141 if (end_obj > last_obj) {
160 ParMarkBitMap::live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const
161 {
162 // Try to reuse result from ParCompactionManager cache first.
163 if (is_live_words_in_range_in_cache(cm, beg_addr)) {
164 return live_words_in_range_use_cache(cm, beg_addr, end_obj);
165 }
166 size_t ret = live_words_in_range_helper(beg_addr, end_obj);
167 update_live_words_in_range_cache(cm, beg_addr, end_obj, ret);
168 return ret;
169 }
170
171 ParMarkBitMap::IterationStatus
172 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
173 idx_t range_beg, idx_t range_end) const
174 {
175 DEBUG_ONLY(verify_bit(range_beg);)
176 DEBUG_ONLY(verify_bit(range_end);)
177 assert(range_beg <= range_end, "live range invalid");
178
179 // The bitmap routines require the right boundary to be word-aligned.
180 const idx_t search_end = align_range_end(range_end);
181
182 idx_t cur_beg = find_obj_beg(range_beg, search_end);
183 while (cur_beg < range_end) {
184 const idx_t cur_end = find_obj_end(cur_beg, search_end);
185 if (cur_end >= range_end) {
186 // The obj ends outside the range.
187 live_closure->set_source(bit_to_addr(cur_beg));
188 return incomplete;
189 }
190
191 const size_t size = obj_size(cur_beg, cur_end);
192 IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
193 if (status != incomplete) {
194 assert(status == would_overflow || status == full, "sanity");
195 return status;
196 }
197
198 // Successfully processed the object; look for the next object.
199 cur_beg = find_obj_beg(cur_end + 1, search_end);
200 }
201
202 live_closure->set_source(bit_to_addr(range_end));
203 return complete;
204 }
205
206 ParMarkBitMap::IterationStatus
207 ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
208 ParMarkBitMapClosure* dead_closure,
209 idx_t range_beg, idx_t range_end,
210 idx_t dead_range_end) const
211 {
212 DEBUG_ONLY(verify_bit(range_beg);)
213 DEBUG_ONLY(verify_bit(range_end);)
214 DEBUG_ONLY(verify_bit(dead_range_end);)
215 assert(range_beg <= range_end, "live range invalid");
216 assert(range_end <= dead_range_end, "dead range invalid");
217
218 // The bitmap routines require the right boundary to be word-aligned.
219 const idx_t live_search_end = align_range_end(range_end);
220 const idx_t dead_search_end = align_range_end(dead_range_end);
221
222 idx_t cur_beg = range_beg;
223 if (range_beg < range_end && is_unmarked(range_beg)) {
224 // The range starts with dead space. Look for the next object, then fill.
225 cur_beg = find_obj_beg(range_beg + 1, dead_search_end);
226 const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
227 const size_t size = obj_size(range_beg, dead_space_end);
228 dead_closure->do_addr(bit_to_addr(range_beg), size);
229 }
230
231 while (cur_beg < range_end) {
232 const idx_t cur_end = find_obj_end(cur_beg, live_search_end);
233 if (cur_end >= range_end) {
234 // The obj ends outside the range.
235 live_closure->set_source(bit_to_addr(cur_beg));
236 return incomplete;
237 }
238
239 const size_t size = obj_size(cur_beg, cur_end);
240 IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
|