author | tschatzl |
Thu, 28 Jan 2016 13:30:12 +0100 | |
changeset 35877 | a2a62511d0f8 |
parent 35862 | 411842d0c882 |
child 37462 | 58bb9394a98b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
35862
411842d0c882
8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents:
30764
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
823
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
823
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
823
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/parallel/parMarkBitMap.hpp" |
35877
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
27 |
#include "gc/parallel/psCompactionManager.inline.hpp" |
35862
411842d0c882
8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents:
30764
diff
changeset
|
28 |
#include "gc/parallel/psParallelCompact.inline.hpp" |
7397 | 29 |
#include "oops/oop.inline.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
25073
diff
changeset
|
30 |
#include "runtime/atomic.inline.hpp" |
7397 | 31 |
#include "runtime/os.hpp" |
30764 | 32 |
#include "services/memTracker.hpp" |
7397 | 33 |
#include "utilities/bitMap.inline.hpp" |
1 | 34 |
|
35 |
bool |
|
36 |
ParMarkBitMap::initialize(MemRegion covered_region) |
|
37 |
{ |
|
38 |
const idx_t bits = bits_required(covered_region); |
|
39 |
// The bits will be divided evenly between two bitmaps; each of them should be |
|
40 |
// an integral number of words. |
|
41 |
assert(bits % (BitsPerWord * 2) == 0, "region size unaligned"); |
|
42 |
||
43 |
const size_t words = bits / BitsPerWord; |
|
44 |
const size_t raw_bytes = words * sizeof(idx_t); |
|
28631 | 45 |
const size_t page_sz = os::page_size_for_region_aligned(raw_bytes, 10); |
1 | 46 |
const size_t granularity = os::vm_allocation_granularity(); |
17627
325871034f2c
7186737: Unable to allocate bit maps or card tables for parallel gc for the requested heap
tamao
parents:
17390
diff
changeset
|
47 |
_reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity)); |
1 | 48 |
|
49 |
const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 : |
|
50 |
MAX2(page_sz, granularity); |
|
17627
325871034f2c
7186737: Unable to allocate bit maps or card tables for parallel gc for the requested heap
tamao
parents:
17390
diff
changeset
|
51 |
ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0); |
1 | 52 |
os::trace_page_sizes("par bitmap", raw_bytes, raw_bytes, page_sz, |
53 |
rs.base(), rs.size()); |
|
13195 | 54 |
|
55 |
MemTracker::record_virtual_memory_type((address)rs.base(), mtGC); |
|
56 |
||
1 | 57 |
_virtual_space = new PSVirtualSpace(rs, page_sz); |
17627
325871034f2c
7186737: Unable to allocate bit maps or card tables for parallel gc for the requested heap
tamao
parents:
17390
diff
changeset
|
58 |
if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) { |
1 | 59 |
_region_start = covered_region.start(); |
60 |
_region_size = covered_region.word_size(); |
|
25073
e4654a279064
8043722: Swapped usage of idx_t and bm_word_t types in parMarkBitMap.cpp
tschatzl
parents:
22827
diff
changeset
|
61 |
BitMap::bm_word_t* map = (BitMap::bm_word_t*)_virtual_space->reserved_low_addr(); |
1 | 62 |
_beg_bits.set_map(map); |
63 |
_beg_bits.set_size(bits / 2); |
|
64 |
_end_bits.set_map(map + words / 2); |
|
65 |
_end_bits.set_size(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; |
|
823
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
670
diff
changeset
|
74 |
// Release memory reserved in the space. |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
670
diff
changeset
|
75 |
rs.release(); |
1 | 76 |
} |
77 |
return false; |
|
78 |
} |
|
79 |
||
80 |
#ifdef ASSERT |
|
81 |
extern size_t mark_bitmap_count; |
|
82 |
extern size_t mark_bitmap_size; |
|
83 |
#endif // #ifdef ASSERT |
|
84 |
||
85 |
bool |
|
86 |
ParMarkBitMap::mark_obj(HeapWord* addr, size_t size) |
|
87 |
{ |
|
88 |
const idx_t beg_bit = addr_to_bit(addr); |
|
89 |
if (_beg_bits.par_set_bit(beg_bit)) { |
|
90 |
const idx_t end_bit = addr_to_bit(addr + size - 1); |
|
91 |
bool end_bit_ok = _end_bits.par_set_bit(end_bit); |
|
92 |
assert(end_bit_ok, "concurrency problem"); |
|
93 |
DEBUG_ONLY(Atomic::inc_ptr(&mark_bitmap_count)); |
|
94 |
DEBUG_ONLY(Atomic::add_ptr(size, &mark_bitmap_size)); |
|
95 |
return true; |
|
96 |
} |
|
97 |
return false; |
|
98 |
} |
|
99 |
||
35877
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
100 |
inline bool |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
101 |
ParMarkBitMap::is_live_words_in_range_in_cache(ParCompactionManager* cm, HeapWord* beg_addr) const { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
102 |
return cm->last_query_begin() == beg_addr; |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
103 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
104 |
|
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
105 |
inline void |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
106 |
ParMarkBitMap::update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
107 |
cm->set_last_query_begin(beg_addr); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
108 |
cm->set_last_query_object(end_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
109 |
cm->set_last_query_return(result); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
110 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
111 |
|
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
112 |
size_t |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
113 |
ParMarkBitMap::live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const |
1 | 114 |
{ |
115 |
assert(beg_addr <= (HeapWord*)end_obj, "bad range"); |
|
116 |
assert(is_marked(end_obj), "end_obj must be live"); |
|
117 |
||
118 |
idx_t live_bits = 0; |
|
119 |
||
120 |
// The bitmap routines require the right boundary to be word-aligned. |
|
121 |
const idx_t end_bit = addr_to_bit((HeapWord*)end_obj); |
|
122 |
const idx_t range_end = BitMap::word_align_up(end_bit); |
|
123 |
||
124 |
idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end); |
|
125 |
while (beg_bit < end_bit) { |
|
126 |
idx_t tmp_end = find_obj_end(beg_bit, range_end); |
|
127 |
assert(tmp_end < end_bit, "missing end bit"); |
|
128 |
live_bits += tmp_end - beg_bit + 1; |
|
129 |
beg_bit = find_obj_beg(tmp_end + 1, range_end); |
|
130 |
} |
|
131 |
return bits_to_words(live_bits); |
|
132 |
} |
|
133 |
||
35877
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
134 |
size_t |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
135 |
ParMarkBitMap::live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
136 |
{ |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
137 |
HeapWord* last_beg = cm->last_query_begin(); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
138 |
oop last_obj = cm->last_query_object(); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
139 |
size_t last_ret = cm->last_query_return(); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
140 |
if (end_obj > last_obj) { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
141 |
last_ret = last_ret + live_words_in_range_helper((HeapWord*)last_obj, end_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
142 |
last_obj = end_obj; |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
143 |
} else if (end_obj < last_obj) { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
144 |
// The cached value is for an object that is to the left (lower address) of the current |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
145 |
// end_obj. Calculate back from that cached value. |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
146 |
if (pointer_delta((HeapWord*)end_obj, (HeapWord*)beg_addr) > pointer_delta((HeapWord*)last_obj, (HeapWord*)end_obj)) { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
147 |
last_ret = last_ret - live_words_in_range_helper((HeapWord*)end_obj, last_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
148 |
} else { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
149 |
last_ret = live_words_in_range_helper(beg_addr, end_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
150 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
151 |
last_obj = end_obj; |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
152 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
153 |
|
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
154 |
update_live_words_in_range_cache(cm, last_beg, last_obj, last_ret); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
155 |
return last_ret; |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
156 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
157 |
|
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
158 |
size_t |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
159 |
ParMarkBitMap::live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
160 |
{ |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
161 |
// Try to reuse result from ParCompactionManager cache first. |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
162 |
if (is_live_words_in_range_in_cache(cm, beg_addr)) { |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
163 |
return live_words_in_range_use_cache(cm, beg_addr, end_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
164 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
165 |
size_t ret = live_words_in_range_helper(beg_addr, end_obj); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
166 |
update_live_words_in_range_cache(cm, beg_addr, end_obj, ret); |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
167 |
return ret; |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
168 |
} |
a2a62511d0f8
8146987: Improve Parallel GC Full GC by caching results of live_words_in_range()
tschatzl
parents:
35862
diff
changeset
|
169 |
|
1 | 170 |
ParMarkBitMap::IterationStatus |
171 |
ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
|
172 |
idx_t range_beg, idx_t range_end) const |
|
173 |
{ |
|
174 |
DEBUG_ONLY(verify_bit(range_beg);) |
|
175 |
DEBUG_ONLY(verify_bit(range_end);) |
|
176 |
assert(range_beg <= range_end, "live range invalid"); |
|
177 |
||
178 |
// The bitmap routines require the right boundary to be word-aligned. |
|
179 |
const idx_t search_end = BitMap::word_align_up(range_end); |
|
180 |
||
181 |
idx_t cur_beg = find_obj_beg(range_beg, search_end); |
|
182 |
while (cur_beg < range_end) { |
|
183 |
const idx_t cur_end = find_obj_end(cur_beg, search_end); |
|
184 |
if (cur_end >= range_end) { |
|
185 |
// The obj ends outside the range. |
|
186 |
live_closure->set_source(bit_to_addr(cur_beg)); |
|
187 |
return incomplete; |
|
188 |
} |
|
189 |
||
190 |
const size_t size = obj_size(cur_beg, cur_end); |
|
191 |
IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size); |
|
192 |
if (status != incomplete) { |
|
193 |
assert(status == would_overflow || status == full, "sanity"); |
|
194 |
return status; |
|
195 |
} |
|
196 |
||
197 |
// Successfully processed the object; look for the next object. |
|
198 |
cur_beg = find_obj_beg(cur_end + 1, search_end); |
|
199 |
} |
|
200 |
||
201 |
live_closure->set_source(bit_to_addr(range_end)); |
|
202 |
return complete; |
|
203 |
} |
|
204 |
||
205 |
ParMarkBitMap::IterationStatus |
|
206 |
ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure, |
|
207 |
ParMarkBitMapClosure* dead_closure, |
|
208 |
idx_t range_beg, idx_t range_end, |
|
209 |
idx_t dead_range_end) const |
|
210 |
{ |
|
211 |
DEBUG_ONLY(verify_bit(range_beg);) |
|
212 |
DEBUG_ONLY(verify_bit(range_end);) |
|
213 |
DEBUG_ONLY(verify_bit(dead_range_end);) |
|
214 |
assert(range_beg <= range_end, "live range invalid"); |
|
215 |
assert(range_end <= dead_range_end, "dead range invalid"); |
|
216 |
||
217 |
// The bitmap routines require the right boundary to be word-aligned. |
|
218 |
const idx_t live_search_end = BitMap::word_align_up(range_end); |
|
219 |
const idx_t dead_search_end = BitMap::word_align_up(dead_range_end); |
|
220 |
||
221 |
idx_t cur_beg = range_beg; |
|
222 |
if (range_beg < range_end && is_unmarked(range_beg)) { |
|
223 |
// The range starts with dead space. Look for the next object, then fill. |
|
224 |
cur_beg = find_obj_beg(range_beg + 1, dead_search_end); |
|
225 |
const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1); |
|
226 |
const size_t size = obj_size(range_beg, dead_space_end); |
|
227 |
dead_closure->do_addr(bit_to_addr(range_beg), size); |
|
228 |
} |
|
229 |
||
230 |
while (cur_beg < range_end) { |
|
231 |
const idx_t cur_end = find_obj_end(cur_beg, live_search_end); |
|
232 |
if (cur_end >= range_end) { |
|
233 |
// The obj ends outside the range. |
|
234 |
live_closure->set_source(bit_to_addr(cur_beg)); |
|
235 |
return incomplete; |
|
236 |
} |
|
237 |
||
238 |
const size_t size = obj_size(cur_beg, cur_end); |
|
239 |
IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size); |
|
240 |
if (status != incomplete) { |
|
241 |
assert(status == would_overflow || status == full, "sanity"); |
|
242 |
return status; |
|
243 |
} |
|
244 |
||
245 |
// Look for the start of the next object. |
|
246 |
const idx_t dead_space_beg = cur_end + 1; |
|
247 |
cur_beg = find_obj_beg(dead_space_beg, dead_search_end); |
|
248 |
if (cur_beg > dead_space_beg) { |
|
249 |
// Found dead space; compute the size and invoke the dead closure. |
|
250 |
const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1); |
|
251 |
const size_t size = obj_size(dead_space_beg, dead_space_end); |
|
252 |
dead_closure->do_addr(bit_to_addr(dead_space_beg), size); |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
live_closure->set_source(bit_to_addr(range_end)); |
|
257 |
return complete; |
|
258 |
} |
|
259 |
||
260 |
#ifdef ASSERT |
|
261 |
void ParMarkBitMap::verify_clear() const |
|
262 |
{ |
|
263 |
const idx_t* const beg = (const idx_t*)_virtual_space->committed_low_addr(); |
|
264 |
const idx_t* const end = (const idx_t*)_virtual_space->committed_high_addr(); |
|
265 |
for (const idx_t* p = beg; p < end; ++p) { |
|
266 |
assert(*p == 0, "bitmap not clear"); |
|
267 |
} |
|
268 |
} |
|
269 |
#endif // #ifdef ASSERT |