Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/parallel/parMarkBitMap.cpp
41149 views
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, page_sz);
53
const size_t used_page_sz = rs.page_size();
54
os::trace_page_sizes("Mark Bitmap", raw_bytes, raw_bytes, used_page_sz,
55
rs.base(), rs.size());
56
57
MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
58
59
_virtual_space = new PSVirtualSpace(rs, page_sz);
60
if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) {
61
_region_start = covered_region.start();
62
_region_size = covered_region.word_size();
63
BitMap::bm_word_t* map = (BitMap::bm_word_t*)_virtual_space->reserved_low_addr();
64
_beg_bits = BitMapView(map, bits / 2);
65
_end_bits = BitMapView(map + words / 2, bits / 2);
66
return true;
67
}
68
69
_region_start = 0;
70
_region_size = 0;
71
if (_virtual_space != NULL) {
72
delete _virtual_space;
73
_virtual_space = NULL;
74
// Release memory reserved in the space.
75
rs.release();
76
}
77
return false;
78
}
79
80
bool
81
ParMarkBitMap::mark_obj(HeapWord* addr, size_t size)
82
{
83
const idx_t beg_bit = addr_to_bit(addr);
84
if (_beg_bits.par_set_bit(beg_bit)) {
85
const idx_t end_bit = addr_to_bit(addr + size - 1);
86
bool end_bit_ok = _end_bits.par_set_bit(end_bit);
87
assert(end_bit_ok, "concurrency problem");
88
return true;
89
}
90
return false;
91
}
92
93
inline bool
94
ParMarkBitMap::is_live_words_in_range_in_cache(ParCompactionManager* cm, HeapWord* beg_addr) const {
95
return cm->last_query_begin() == beg_addr;
96
}
97
98
inline void
99
ParMarkBitMap::update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const {
100
cm->set_last_query_begin(beg_addr);
101
cm->set_last_query_object(end_obj);
102
cm->set_last_query_return(result);
103
}
104
105
size_t
106
ParMarkBitMap::live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const
107
{
108
assert(beg_addr <= cast_from_oop<HeapWord*>(end_obj), "bad range");
109
assert(is_marked(end_obj), "end_obj must be live");
110
111
idx_t live_bits = 0;
112
113
// The bitmap routines require the right boundary to be word-aligned.
114
const idx_t end_bit = addr_to_bit(cast_from_oop<HeapWord*>(end_obj));
115
const idx_t range_end = align_range_end(end_bit);
116
117
idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);
118
while (beg_bit < end_bit) {
119
idx_t tmp_end = find_obj_end(beg_bit, range_end);
120
assert(tmp_end < end_bit, "missing end bit");
121
live_bits += tmp_end - beg_bit + 1;
122
beg_bit = find_obj_beg(tmp_end + 1, range_end);
123
}
124
return bits_to_words(live_bits);
125
}
126
127
size_t
128
ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_oop) const
129
{
130
HeapWord* last_beg = cm->last_query_begin();
131
HeapWord* last_obj = cast_from_oop<HeapWord*>(cm->last_query_object());
132
HeapWord* end_obj = cast_from_oop<HeapWord*>(end_oop);
133
134
size_t last_ret = cm->last_query_return();
135
if (end_obj > last_obj) {
136
last_ret = last_ret + live_words_in_range_helper(last_obj, end_oop);
137
last_obj = end_obj;
138
} else if (end_obj < last_obj) {
139
// The cached value is for an object that is to the left (lower address) of the current
140
// end_obj. Calculate back from that cached value.
141
if (pointer_delta(end_obj, beg_addr) > pointer_delta(last_obj, end_obj)) {
142
last_ret = last_ret - live_words_in_range_helper(end_obj, cast_to_oop(last_obj));
143
} else {
144
last_ret = live_words_in_range_helper(beg_addr, end_oop);
145
}
146
last_obj = end_obj;
147
}
148
149
update_live_words_in_range_cache(cm, last_beg, cast_to_oop(last_obj), last_ret);
150
return last_ret;
151
}
152
153
size_t
154
ParMarkBitMap::live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const
155
{
156
// Try to reuse result from ParCompactionManager cache first.
157
if (is_live_words_in_range_in_cache(cm, beg_addr)) {
158
return live_words_in_range_use_cache(cm, beg_addr, end_obj);
159
}
160
size_t ret = live_words_in_range_helper(beg_addr, end_obj);
161
update_live_words_in_range_cache(cm, beg_addr, end_obj, ret);
162
return ret;
163
}
164
165
ParMarkBitMap::IterationStatus
166
ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
167
idx_t range_beg, idx_t range_end) const
168
{
169
DEBUG_ONLY(verify_bit(range_beg);)
170
DEBUG_ONLY(verify_bit(range_end);)
171
assert(range_beg <= range_end, "live range invalid");
172
173
// The bitmap routines require the right boundary to be word-aligned.
174
const idx_t search_end = align_range_end(range_end);
175
176
idx_t cur_beg = find_obj_beg(range_beg, search_end);
177
while (cur_beg < range_end) {
178
const idx_t cur_end = find_obj_end(cur_beg, search_end);
179
if (cur_end >= range_end) {
180
// The obj ends outside the range.
181
live_closure->set_source(bit_to_addr(cur_beg));
182
return incomplete;
183
}
184
185
const size_t size = obj_size(cur_beg, cur_end);
186
IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
187
if (status != incomplete) {
188
assert(status == would_overflow || status == full, "sanity");
189
return status;
190
}
191
192
// Successfully processed the object; look for the next object.
193
cur_beg = find_obj_beg(cur_end + 1, search_end);
194
}
195
196
live_closure->set_source(bit_to_addr(range_end));
197
return complete;
198
}
199
200
ParMarkBitMap::IterationStatus
201
ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
202
ParMarkBitMapClosure* dead_closure,
203
idx_t range_beg, idx_t range_end,
204
idx_t dead_range_end) const
205
{
206
DEBUG_ONLY(verify_bit(range_beg);)
207
DEBUG_ONLY(verify_bit(range_end);)
208
DEBUG_ONLY(verify_bit(dead_range_end);)
209
assert(range_beg <= range_end, "live range invalid");
210
assert(range_end <= dead_range_end, "dead range invalid");
211
212
// The bitmap routines require the right boundary to be word-aligned.
213
const idx_t live_search_end = align_range_end(range_end);
214
const idx_t dead_search_end = align_range_end(dead_range_end);
215
216
idx_t cur_beg = range_beg;
217
if (range_beg < range_end && is_unmarked(range_beg)) {
218
// The range starts with dead space. Look for the next object, then fill.
219
cur_beg = find_obj_beg(range_beg + 1, dead_search_end);
220
const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
221
const size_t size = obj_size(range_beg, dead_space_end);
222
dead_closure->do_addr(bit_to_addr(range_beg), size);
223
}
224
225
while (cur_beg < range_end) {
226
const idx_t cur_end = find_obj_end(cur_beg, live_search_end);
227
if (cur_end >= range_end) {
228
// The obj ends outside the range.
229
live_closure->set_source(bit_to_addr(cur_beg));
230
return incomplete;
231
}
232
233
const size_t size = obj_size(cur_beg, cur_end);
234
IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
235
if (status != incomplete) {
236
assert(status == would_overflow || status == full, "sanity");
237
return status;
238
}
239
240
// Look for the start of the next object.
241
const idx_t dead_space_beg = cur_end + 1;
242
cur_beg = find_obj_beg(dead_space_beg, dead_search_end);
243
if (cur_beg > dead_space_beg) {
244
// Found dead space; compute the size and invoke the dead closure.
245
const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
246
const size_t size = obj_size(dead_space_beg, dead_space_end);
247
dead_closure->do_addr(bit_to_addr(dead_space_beg), size);
248
}
249
}
250
251
live_closure->set_source(bit_to_addr(range_end));
252
return complete;
253
}
254
255
#ifdef ASSERT
256
void ParMarkBitMap::verify_clear() const
257
{
258
const idx_t* const beg = (const idx_t*)_virtual_space->committed_low_addr();
259
const idx_t* const end = (const idx_t*)_virtual_space->committed_high_addr();
260
for (const idx_t* p = beg; p < end; ++p) {
261
assert(*p == 0, "bitmap not clear");
262
}
263
}
264
#endif // #ifdef ASSERT
265
266