Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 1719:b63010841f78
6975964: G1: print out a more descriptive message for evacuation failure when +PrintGCDetails is set
Summary: we're renaming "evacuation failure" to "to-space overflow". I'm also piggy-backing a small additional change which removes the "Mark closure took..." output.
Reviewed-by: ysr, johnc
author | tonyp |
---|---|
date | Tue, 17 Aug 2010 14:40:00 -0400 |
parents | c18cbe5936b8 |
children | 8b10f48633dc |
rev | line source |
---|---|
342 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1547
diff
changeset
|
2 * Copyright (c) 2001, 2009, Oracle and/or its affiliates. All rights reserved. |
342 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1547
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1547
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1547
diff
changeset
|
21 * questions. |
342 | 22 * |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_concurrentMark.cpp.incl" | |
27 | |
28 // | |
29 // CMS Bit Map Wrapper | |
30 | |
31 CMBitMapRO::CMBitMapRO(ReservedSpace rs, int shifter): | |
32 _bm((uintptr_t*)NULL,0), | |
33 _shifter(shifter) { | |
34 _bmStartWord = (HeapWord*)(rs.base()); | |
35 _bmWordSize = rs.size()/HeapWordSize; // rs.size() is in bytes | |
36 ReservedSpace brs(ReservedSpace::allocation_align_size_up( | |
37 (_bmWordSize >> (_shifter + LogBitsPerByte)) + 1)); | |
38 | |
39 guarantee(brs.is_reserved(), "couldn't allocate CMS bit map"); | |
40 // For now we'll just commit all of the bit map up fromt. | |
41 // Later on we'll try to be more parsimonious with swap. | |
42 guarantee(_virtual_space.initialize(brs, brs.size()), | |
43 "couldn't reseve backing store for CMS bit map"); | |
44 assert(_virtual_space.committed_size() == brs.size(), | |
45 "didn't reserve backing store for all of CMS bit map?"); | |
46 _bm.set_map((uintptr_t*)_virtual_space.low()); | |
47 assert(_virtual_space.committed_size() << (_shifter + LogBitsPerByte) >= | |
48 _bmWordSize, "inconsistency in bit map sizing"); | |
49 _bm.set_size(_bmWordSize >> _shifter); | |
50 } | |
51 | |
52 HeapWord* CMBitMapRO::getNextMarkedWordAddress(HeapWord* addr, | |
53 HeapWord* limit) const { | |
54 // First we must round addr *up* to a possible object boundary. | |
55 addr = (HeapWord*)align_size_up((intptr_t)addr, | |
56 HeapWordSize << _shifter); | |
57 size_t addrOffset = heapWordToOffset(addr); | |
58 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | |
59 size_t limitOffset = heapWordToOffset(limit); | |
60 size_t nextOffset = _bm.get_next_one_offset(addrOffset, limitOffset); | |
61 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | |
62 assert(nextAddr >= addr, "get_next_one postcondition"); | |
63 assert(nextAddr == limit || isMarked(nextAddr), | |
64 "get_next_one postcondition"); | |
65 return nextAddr; | |
66 } | |
67 | |
68 HeapWord* CMBitMapRO::getNextUnmarkedWordAddress(HeapWord* addr, | |
69 HeapWord* limit) const { | |
70 size_t addrOffset = heapWordToOffset(addr); | |
71 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | |
72 size_t limitOffset = heapWordToOffset(limit); | |
73 size_t nextOffset = _bm.get_next_zero_offset(addrOffset, limitOffset); | |
74 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | |
75 assert(nextAddr >= addr, "get_next_one postcondition"); | |
76 assert(nextAddr == limit || !isMarked(nextAddr), | |
77 "get_next_one postcondition"); | |
78 return nextAddr; | |
79 } | |
80 | |
81 int CMBitMapRO::heapWordDiffToOffsetDiff(size_t diff) const { | |
82 assert((diff & ((1 << _shifter) - 1)) == 0, "argument check"); | |
83 return (int) (diff >> _shifter); | |
84 } | |
85 | |
86 bool CMBitMapRO::iterate(BitMapClosure* cl, MemRegion mr) { | |
87 HeapWord* left = MAX2(_bmStartWord, mr.start()); | |
88 HeapWord* right = MIN2(_bmStartWord + _bmWordSize, mr.end()); | |
89 if (right > left) { | |
90 // Right-open interval [leftOffset, rightOffset). | |
91 return _bm.iterate(cl, heapWordToOffset(left), heapWordToOffset(right)); | |
92 } else { | |
93 return true; | |
94 } | |
95 } | |
96 | |
97 void CMBitMapRO::mostly_disjoint_range_union(BitMap* from_bitmap, | |
98 size_t from_start_index, | |
99 HeapWord* to_start_word, | |
100 size_t word_num) { | |
101 _bm.mostly_disjoint_range_union(from_bitmap, | |
102 from_start_index, | |
103 heapWordToOffset(to_start_word), | |
104 word_num); | |
105 } | |
106 | |
107 #ifndef PRODUCT | |
108 bool CMBitMapRO::covers(ReservedSpace rs) const { | |
109 // assert(_bm.map() == _virtual_space.low(), "map inconsistency"); | |
645
c3a720eefe82
6816308: Changes to allow builds with latest Windows SDK 6.1 on 64bit Windows 2003
kvn
parents:
619
diff
changeset
|
110 assert(((size_t)_bm.size() * (size_t)(1 << _shifter)) == _bmWordSize, |
342 | 111 "size inconsistency"); |
112 return _bmStartWord == (HeapWord*)(rs.base()) && | |
113 _bmWordSize == rs.size()>>LogHeapWordSize; | |
114 } | |
115 #endif | |
116 | |
117 void CMBitMap::clearAll() { | |
118 _bm.clear(); | |
119 return; | |
120 } | |
121 | |
122 void CMBitMap::markRange(MemRegion mr) { | |
123 mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
124 assert(!mr.is_empty(), "unexpected empty region"); | |
125 assert((offsetToHeapWord(heapWordToOffset(mr.end())) == | |
126 ((HeapWord *) mr.end())), | |
127 "markRange memory region end is not card aligned"); | |
128 // convert address range into offset range | |
129 _bm.at_put_range(heapWordToOffset(mr.start()), | |
130 heapWordToOffset(mr.end()), true); | |
131 } | |
132 | |
133 void CMBitMap::clearRange(MemRegion mr) { | |
134 mr.intersection(MemRegion(_bmStartWord, _bmWordSize)); | |
135 assert(!mr.is_empty(), "unexpected empty region"); | |
136 // convert address range into offset range | |
137 _bm.at_put_range(heapWordToOffset(mr.start()), | |
138 heapWordToOffset(mr.end()), false); | |
139 } | |
140 | |
141 MemRegion CMBitMap::getAndClearMarkedRegion(HeapWord* addr, | |
142 HeapWord* end_addr) { | |
143 HeapWord* start = getNextMarkedWordAddress(addr); | |
144 start = MIN2(start, end_addr); | |
145 HeapWord* end = getNextUnmarkedWordAddress(start); | |
146 end = MIN2(end, end_addr); | |
147 assert(start <= end, "Consistency check"); | |
148 MemRegion mr(start, end); | |
149 if (!mr.is_empty()) { | |
150 clearRange(mr); | |
151 } | |
152 return mr; | |
153 } | |
154 | |
155 CMMarkStack::CMMarkStack(ConcurrentMark* cm) : | |
156 _base(NULL), _cm(cm) | |
157 #ifdef ASSERT | |
158 , _drain_in_progress(false) | |
159 , _drain_in_progress_yields(false) | |
160 #endif | |
161 {} | |
162 | |
163 void CMMarkStack::allocate(size_t size) { | |
164 _base = NEW_C_HEAP_ARRAY(oop, size); | |
165 if (_base == NULL) | |
166 vm_exit_during_initialization("Failed to allocate " | |
167 "CM region mark stack"); | |
168 _index = 0; | |
169 // QQQQ cast ... | |
170 _capacity = (jint) size; | |
171 _oops_do_bound = -1; | |
172 NOT_PRODUCT(_max_depth = 0); | |
173 } | |
174 | |
175 CMMarkStack::~CMMarkStack() { | |
176 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | |
177 } | |
178 | |
179 void CMMarkStack::par_push(oop ptr) { | |
180 while (true) { | |
181 if (isFull()) { | |
182 _overflow = true; | |
183 return; | |
184 } | |
185 // Otherwise... | |
186 jint index = _index; | |
187 jint next_index = index+1; | |
188 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
189 if (res == index) { | |
190 _base[index] = ptr; | |
191 // Note that we don't maintain this atomically. We could, but it | |
192 // doesn't seem necessary. | |
193 NOT_PRODUCT(_max_depth = MAX2(_max_depth, next_index)); | |
194 return; | |
195 } | |
196 // Otherwise, we need to try again. | |
197 } | |
198 } | |
199 | |
200 void CMMarkStack::par_adjoin_arr(oop* ptr_arr, int n) { | |
201 while (true) { | |
202 if (isFull()) { | |
203 _overflow = true; | |
204 return; | |
205 } | |
206 // Otherwise... | |
207 jint index = _index; | |
208 jint next_index = index + n; | |
209 if (next_index > _capacity) { | |
210 _overflow = true; | |
211 return; | |
212 } | |
213 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
214 if (res == index) { | |
215 for (int i = 0; i < n; i++) { | |
216 int ind = index + i; | |
217 assert(ind < _capacity, "By overflow test above."); | |
218 _base[ind] = ptr_arr[i]; | |
219 } | |
220 NOT_PRODUCT(_max_depth = MAX2(_max_depth, next_index)); | |
221 return; | |
222 } | |
223 // Otherwise, we need to try again. | |
224 } | |
225 } | |
226 | |
227 | |
228 void CMMarkStack::par_push_arr(oop* ptr_arr, int n) { | |
229 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
230 jint start = _index; | |
231 jint next_index = start + n; | |
232 if (next_index > _capacity) { | |
233 _overflow = true; | |
234 return; | |
235 } | |
236 // Otherwise. | |
237 _index = next_index; | |
238 for (int i = 0; i < n; i++) { | |
239 int ind = start + i; | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
240 assert(ind < _capacity, "By overflow test above."); |
342 | 241 _base[ind] = ptr_arr[i]; |
242 } | |
243 } | |
244 | |
245 | |
246 bool CMMarkStack::par_pop_arr(oop* ptr_arr, int max, int* n) { | |
247 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
248 jint index = _index; | |
249 if (index == 0) { | |
250 *n = 0; | |
251 return false; | |
252 } else { | |
253 int k = MIN2(max, index); | |
254 jint new_ind = index - k; | |
255 for (int j = 0; j < k; j++) { | |
256 ptr_arr[j] = _base[new_ind + j]; | |
257 } | |
258 _index = new_ind; | |
259 *n = k; | |
260 return true; | |
261 } | |
262 } | |
263 | |
264 | |
265 CMRegionStack::CMRegionStack() : _base(NULL) {} | |
266 | |
267 void CMRegionStack::allocate(size_t size) { | |
268 _base = NEW_C_HEAP_ARRAY(MemRegion, size); | |
269 if (_base == NULL) | |
270 vm_exit_during_initialization("Failed to allocate " | |
271 "CM region mark stack"); | |
272 _index = 0; | |
273 // QQQQ cast ... | |
274 _capacity = (jint) size; | |
275 } | |
276 | |
277 CMRegionStack::~CMRegionStack() { | |
278 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | |
279 } | |
280 | |
281 void CMRegionStack::push(MemRegion mr) { | |
282 assert(mr.word_size() > 0, "Precondition"); | |
283 while (true) { | |
284 if (isFull()) { | |
285 _overflow = true; | |
286 return; | |
287 } | |
288 // Otherwise... | |
289 jint index = _index; | |
290 jint next_index = index+1; | |
291 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
292 if (res == index) { | |
293 _base[index] = mr; | |
294 return; | |
295 } | |
296 // Otherwise, we need to try again. | |
297 } | |
298 } | |
299 | |
1358
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
300 // Currently we do not call this at all. Normally we would call it |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
301 // during the concurrent marking / remark phases but we now call |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
302 // the lock-based version instead. But we might want to resurrect this |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
303 // code in the future. So, we'll leave it here commented out. |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
304 #if 0 |
342 | 305 MemRegion CMRegionStack::pop() { |
306 while (true) { | |
307 // Otherwise... | |
308 jint index = _index; | |
309 | |
310 if (index == 0) { | |
311 return MemRegion(); | |
312 } | |
313 jint next_index = index-1; | |
314 jint res = Atomic::cmpxchg(next_index, &_index, index); | |
315 if (res == index) { | |
316 MemRegion mr = _base[next_index]; | |
317 if (mr.start() != NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
318 assert(mr.end() != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
319 assert(mr.word_size() > 0, "invariant"); |
342 | 320 return mr; |
321 } else { | |
322 // that entry was invalidated... let's skip it | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
323 assert(mr.end() == NULL, "invariant"); |
342 | 324 } |
325 } | |
326 // Otherwise, we need to try again. | |
327 } | |
328 } | |
1358
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
329 #endif // 0 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
330 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
331 void CMRegionStack::push_with_lock(MemRegion mr) { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
332 assert(mr.word_size() > 0, "Precondition"); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
333 MutexLockerEx x(CMRegionStack_lock, Mutex::_no_safepoint_check_flag); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
334 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
335 if (isFull()) { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
336 _overflow = true; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
337 return; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
338 } |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
339 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
340 _base[_index] = mr; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
341 _index += 1; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
342 } |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
343 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
344 MemRegion CMRegionStack::pop_with_lock() { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
345 MutexLockerEx x(CMRegionStack_lock, Mutex::_no_safepoint_check_flag); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
346 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
347 while (true) { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
348 if (_index == 0) { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
349 return MemRegion(); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
350 } |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
351 _index -= 1; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
352 |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
353 MemRegion mr = _base[_index]; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
354 if (mr.start() != NULL) { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
355 assert(mr.end() != NULL, "invariant"); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
356 assert(mr.word_size() > 0, "invariant"); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
357 return mr; |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
358 } else { |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
359 // that entry was invalidated... let's skip it |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
360 assert(mr.end() == NULL, "invariant"); |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
361 } |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
362 } |
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
363 } |
342 | 364 |
365 bool CMRegionStack::invalidate_entries_into_cset() { | |
366 bool result = false; | |
367 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
368 for (int i = 0; i < _oops_do_bound; ++i) { | |
369 MemRegion mr = _base[i]; | |
370 if (mr.start() != NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
371 assert(mr.end() != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
372 assert(mr.word_size() > 0, "invariant"); |
342 | 373 HeapRegion* hr = g1h->heap_region_containing(mr.start()); |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
374 assert(hr != NULL, "invariant"); |
342 | 375 if (hr->in_collection_set()) { |
376 // The region points into the collection set | |
377 _base[i] = MemRegion(); | |
378 result = true; | |
379 } | |
380 } else { | |
381 // that entry was invalidated... let's skip it | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
382 assert(mr.end() == NULL, "invariant"); |
342 | 383 } |
384 } | |
385 return result; | |
386 } | |
387 | |
388 template<class OopClosureClass> | |
389 bool CMMarkStack::drain(OopClosureClass* cl, CMBitMap* bm, bool yield_after) { | |
390 assert(!_drain_in_progress || !_drain_in_progress_yields || yield_after | |
391 || SafepointSynchronize::is_at_safepoint(), | |
392 "Drain recursion must be yield-safe."); | |
393 bool res = true; | |
394 debug_only(_drain_in_progress = true); | |
395 debug_only(_drain_in_progress_yields = yield_after); | |
396 while (!isEmpty()) { | |
397 oop newOop = pop(); | |
398 assert(G1CollectedHeap::heap()->is_in_reserved(newOop), "Bad pop"); | |
399 assert(newOop->is_oop(), "Expected an oop"); | |
400 assert(bm == NULL || bm->isMarked((HeapWord*)newOop), | |
401 "only grey objects on this stack"); | |
402 // iterate over the oops in this oop, marking and pushing | |
403 // the ones in CMS generation. | |
404 newOop->oop_iterate(cl); | |
405 if (yield_after && _cm->do_yield_check()) { | |
406 res = false; break; | |
407 } | |
408 } | |
409 debug_only(_drain_in_progress = false); | |
410 return res; | |
411 } | |
412 | |
413 void CMMarkStack::oops_do(OopClosure* f) { | |
414 if (_index == 0) return; | |
415 assert(_oops_do_bound != -1 && _oops_do_bound <= _index, | |
416 "Bound must be set."); | |
417 for (int i = 0; i < _oops_do_bound; i++) { | |
418 f->do_oop(&_base[i]); | |
419 } | |
420 _oops_do_bound = -1; | |
421 } | |
422 | |
423 bool ConcurrentMark::not_yet_marked(oop obj) const { | |
424 return (_g1h->is_obj_ill(obj) | |
425 || (_g1h->is_in_permanent(obj) | |
426 && !nextMarkBitMap()->isMarked((HeapWord*)obj))); | |
427 } | |
428 | |
429 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away | |
430 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
431 #endif // _MSC_VER | |
432 | |
433 ConcurrentMark::ConcurrentMark(ReservedSpace rs, | |
434 int max_regions) : | |
435 _markBitMap1(rs, MinObjAlignment - 1), | |
436 _markBitMap2(rs, MinObjAlignment - 1), | |
437 | |
438 _parallel_marking_threads(0), | |
439 _sleep_factor(0.0), | |
440 _marking_task_overhead(1.0), | |
441 _cleanup_sleep_factor(0.0), | |
442 _cleanup_task_overhead(1.0), | |
443 _region_bm(max_regions, false /* in_resource_area*/), | |
444 _card_bm((rs.size() + CardTableModRefBS::card_size - 1) >> | |
445 CardTableModRefBS::card_shift, | |
446 false /* in_resource_area*/), | |
447 _prevMarkBitMap(&_markBitMap1), | |
448 _nextMarkBitMap(&_markBitMap2), | |
449 _at_least_one_mark_complete(false), | |
450 | |
451 _markStack(this), | |
452 _regionStack(), | |
453 // _finger set in set_non_marking_state | |
454 | |
455 _max_task_num(MAX2(ParallelGCThreads, (size_t)1)), | |
456 // _active_tasks set in set_non_marking_state | |
457 // _tasks set inside the constructor | |
458 _task_queues(new CMTaskQueueSet((int) _max_task_num)), | |
459 _terminator(ParallelTaskTerminator((int) _max_task_num, _task_queues)), | |
460 | |
461 _has_overflown(false), | |
462 _concurrent(false), | |
619
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
463 _has_aborted(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
464 _restart_for_overflow(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
465 _concurrent_marking_in_progress(false), |
7ea5ca260b28
6814467: G1: small fixes related to concurrent marking verboseness
tonyp
parents:
470
diff
changeset
|
466 _should_gray_objects(false), |
342 | 467 |
468 // _verbose_level set below | |
469 | |
470 _init_times(), | |
471 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(), | |
472 _cleanup_times(), | |
473 _total_counting_time(0.0), | |
474 _total_rs_scrub_time(0.0), | |
475 | |
936 | 476 _parallel_workers(NULL) |
342 | 477 { |
478 CMVerboseLevel verbose_level = | |
479 (CMVerboseLevel) G1MarkingVerboseLevel; | |
480 if (verbose_level < no_verbose) | |
481 verbose_level = no_verbose; | |
482 if (verbose_level > high_verbose) | |
483 verbose_level = high_verbose; | |
484 _verbose_level = verbose_level; | |
485 | |
486 if (verbose_low()) | |
487 gclog_or_tty->print_cr("[global] init, heap start = "PTR_FORMAT", " | |
488 "heap end = "PTR_FORMAT, _heap_start, _heap_end); | |
489 | |
1284 | 490 _markStack.allocate(MarkStackSize); |
751 | 491 _regionStack.allocate(G1MarkRegionStackSize); |
342 | 492 |
493 // Create & start a ConcurrentMark thread. | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
494 _cmThread = new ConcurrentMarkThread(this); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
495 assert(cmThread() != NULL, "CM Thread should have been created"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
496 assert(cmThread()->cm() != NULL, "CM Thread should refer to this cm"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
497 |
342 | 498 _g1h = G1CollectedHeap::heap(); |
499 assert(CGC_lock != NULL, "Where's the CGC_lock?"); | |
500 assert(_markBitMap1.covers(rs), "_markBitMap1 inconsistency"); | |
501 assert(_markBitMap2.covers(rs), "_markBitMap2 inconsistency"); | |
502 | |
503 SATBMarkQueueSet& satb_qs = JavaThread::satb_mark_queue_set(); | |
1282 | 504 satb_qs.set_buffer_size(G1SATBBufferSize); |
342 | 505 |
506 int size = (int) MAX2(ParallelGCThreads, (size_t)1); | |
507 _par_cleanup_thread_state = NEW_C_HEAP_ARRAY(ParCleanupThreadState*, size); | |
508 for (int i = 0 ; i < size; i++) { | |
509 _par_cleanup_thread_state[i] = new ParCleanupThreadState; | |
510 } | |
511 | |
512 _tasks = NEW_C_HEAP_ARRAY(CMTask*, _max_task_num); | |
513 _accum_task_vtime = NEW_C_HEAP_ARRAY(double, _max_task_num); | |
514 | |
515 // so that the assertion in MarkingTaskQueue::task_queue doesn't fail | |
516 _active_tasks = _max_task_num; | |
517 for (int i = 0; i < (int) _max_task_num; ++i) { | |
518 CMTaskQueue* task_queue = new CMTaskQueue(); | |
519 task_queue->initialize(); | |
520 _task_queues->register_queue(i, task_queue); | |
521 | |
522 _tasks[i] = new CMTask(i, this, task_queue, _task_queues); | |
523 _accum_task_vtime[i] = 0.0; | |
524 } | |
525 | |
1284 | 526 if (ConcGCThreads > ParallelGCThreads) { |
527 vm_exit_during_initialization("Can't have more ConcGCThreads " | |
342 | 528 "than ParallelGCThreads."); |
529 } | |
530 if (ParallelGCThreads == 0) { | |
531 // if we are not running with any parallel GC threads we will not | |
532 // spawn any marking threads either | |
533 _parallel_marking_threads = 0; | |
534 _sleep_factor = 0.0; | |
535 _marking_task_overhead = 1.0; | |
536 } else { | |
1284 | 537 if (ConcGCThreads > 0) { |
538 // notice that ConcGCThreads overwrites G1MarkingOverheadPercent | |
342 | 539 // if both are set |
540 | |
1284 | 541 _parallel_marking_threads = ConcGCThreads; |
342 | 542 _sleep_factor = 0.0; |
543 _marking_task_overhead = 1.0; | |
751 | 544 } else if (G1MarkingOverheadPercent > 0) { |
342 | 545 // we will calculate the number of parallel marking threads |
546 // based on a target overhead with respect to the soft real-time | |
547 // goal | |
548 | |
751 | 549 double marking_overhead = (double) G1MarkingOverheadPercent / 100.0; |
342 | 550 double overall_cm_overhead = |
751 | 551 (double) MaxGCPauseMillis * marking_overhead / |
552 (double) GCPauseIntervalMillis; | |
342 | 553 double cpu_ratio = 1.0 / (double) os::processor_count(); |
554 double marking_thread_num = ceil(overall_cm_overhead / cpu_ratio); | |
555 double marking_task_overhead = | |
556 overall_cm_overhead / marking_thread_num * | |
557 (double) os::processor_count(); | |
558 double sleep_factor = | |
559 (1.0 - marking_task_overhead) / marking_task_overhead; | |
560 | |
561 _parallel_marking_threads = (size_t) marking_thread_num; | |
562 _sleep_factor = sleep_factor; | |
563 _marking_task_overhead = marking_task_overhead; | |
564 } else { | |
565 _parallel_marking_threads = MAX2((ParallelGCThreads + 2) / 4, (size_t)1); | |
566 _sleep_factor = 0.0; | |
567 _marking_task_overhead = 1.0; | |
568 } | |
569 | |
570 if (parallel_marking_threads() > 1) | |
571 _cleanup_task_overhead = 1.0; | |
572 else | |
573 _cleanup_task_overhead = marking_task_overhead(); | |
574 _cleanup_sleep_factor = | |
575 (1.0 - cleanup_task_overhead()) / cleanup_task_overhead(); | |
576 | |
577 #if 0 | |
578 gclog_or_tty->print_cr("Marking Threads %d", parallel_marking_threads()); | |
579 gclog_or_tty->print_cr("CM Marking Task Overhead %1.4lf", marking_task_overhead()); | |
580 gclog_or_tty->print_cr("CM Sleep Factor %1.4lf", sleep_factor()); | |
581 gclog_or_tty->print_cr("CL Marking Task Overhead %1.4lf", cleanup_task_overhead()); | |
582 gclog_or_tty->print_cr("CL Sleep Factor %1.4lf", cleanup_sleep_factor()); | |
583 #endif | |
584 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
585 guarantee(parallel_marking_threads() > 0, "peace of mind"); |
1019 | 586 _parallel_workers = new WorkGang("G1 Parallel Marking Threads", |
342 | 587 (int) parallel_marking_threads(), false, true); |
588 if (_parallel_workers == NULL) | |
589 vm_exit_during_initialization("Failed necessary allocation."); | |
590 } | |
591 | |
592 // so that the call below can read a sensible value | |
593 _heap_start = (HeapWord*) rs.base(); | |
594 set_non_marking_state(); | |
595 } | |
596 | |
597 void ConcurrentMark::update_g1_committed(bool force) { | |
598 // If concurrent marking is not in progress, then we do not need to | |
599 // update _heap_end. This has a subtle and important | |
600 // side-effect. Imagine that two evacuation pauses happen between | |
601 // marking completion and remark. The first one can grow the | |
602 // heap (hence now the finger is below the heap end). Then, the | |
603 // second one could unnecessarily push regions on the region | |
604 // stack. This causes the invariant that the region stack is empty | |
605 // at the beginning of remark to be false. By ensuring that we do | |
606 // not observe heap expansions after marking is complete, then we do | |
607 // not have this problem. | |
608 if (!concurrent_marking_in_progress() && !force) | |
609 return; | |
610 | |
611 MemRegion committed = _g1h->g1_committed(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
612 assert(committed.start() == _heap_start, "start shouldn't change"); |
342 | 613 HeapWord* new_end = committed.end(); |
614 if (new_end > _heap_end) { | |
615 // The heap has been expanded. | |
616 | |
617 _heap_end = new_end; | |
618 } | |
619 // Notice that the heap can also shrink. However, this only happens | |
620 // during a Full GC (at least currently) and the entire marking | |
621 // phase will bail out and the task will not be restarted. So, let's | |
622 // do nothing. | |
623 } | |
624 | |
625 void ConcurrentMark::reset() { | |
626 // Starting values for these two. This should be called in a STW | |
627 // phase. CM will be notified of any future g1_committed expansions | |
628 // will be at the end of evacuation pauses, when tasks are | |
629 // inactive. | |
630 MemRegion committed = _g1h->g1_committed(); | |
631 _heap_start = committed.start(); | |
632 _heap_end = committed.end(); | |
633 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
634 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
635 assert(_heap_start != NULL, "heap bounds should look ok"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
636 assert(_heap_end != NULL, "heap bounds should look ok"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
637 assert(_heap_start < _heap_end, "heap bounds should look ok"); |
342 | 638 |
639 // reset all the marking data structures and any necessary flags | |
640 clear_marking_state(); | |
641 | |
642 if (verbose_low()) | |
643 gclog_or_tty->print_cr("[global] resetting"); | |
644 | |
645 // We do reset all of them, since different phases will use | |
646 // different number of active threads. So, it's easiest to have all | |
647 // of them ready. | |
648 for (int i = 0; i < (int) _max_task_num; ++i) | |
649 _tasks[i]->reset(_nextMarkBitMap); | |
650 | |
651 // we need this to make sure that the flag is on during the evac | |
652 // pause with initial mark piggy-backed | |
653 set_concurrent_marking_in_progress(); | |
654 } | |
655 | |
656 void ConcurrentMark::set_phase(size_t active_tasks, bool concurrent) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
657 assert(active_tasks <= _max_task_num, "we should not have more"); |
342 | 658 |
659 _active_tasks = active_tasks; | |
660 // Need to update the three data structures below according to the | |
661 // number of active threads for this phase. | |
662 _terminator = ParallelTaskTerminator((int) active_tasks, _task_queues); | |
663 _first_overflow_barrier_sync.set_n_workers((int) active_tasks); | |
664 _second_overflow_barrier_sync.set_n_workers((int) active_tasks); | |
665 | |
666 _concurrent = concurrent; | |
667 // We propagate this to all tasks, not just the active ones. | |
668 for (int i = 0; i < (int) _max_task_num; ++i) | |
669 _tasks[i]->set_concurrent(concurrent); | |
670 | |
671 if (concurrent) { | |
672 set_concurrent_marking_in_progress(); | |
673 } else { | |
674 // We currently assume that the concurrent flag has been set to | |
675 // false before we start remark. At this point we should also be | |
676 // in a STW phase. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
677 assert(!concurrent_marking_in_progress(), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
678 assert(_finger == _heap_end, "only way to get here"); |
342 | 679 update_g1_committed(true); |
680 } | |
681 } | |
682 | |
683 void ConcurrentMark::set_non_marking_state() { | |
684 // We set the global marking state to some default values when we're | |
685 // not doing marking. | |
686 clear_marking_state(); | |
687 _active_tasks = 0; | |
688 clear_concurrent_marking_in_progress(); | |
689 } | |
690 | |
691 ConcurrentMark::~ConcurrentMark() { | |
692 int size = (int) MAX2(ParallelGCThreads, (size_t)1); | |
693 for (int i = 0; i < size; i++) delete _par_cleanup_thread_state[i]; | |
694 FREE_C_HEAP_ARRAY(ParCleanupThreadState*, | |
695 _par_cleanup_thread_state); | |
696 | |
697 for (int i = 0; i < (int) _max_task_num; ++i) { | |
698 delete _task_queues->queue(i); | |
699 delete _tasks[i]; | |
700 } | |
701 delete _task_queues; | |
702 FREE_C_HEAP_ARRAY(CMTask*, _max_task_num); | |
703 } | |
704 | |
705 // This closure is used to mark refs into the g1 generation | |
706 // from external roots in the CMS bit map. | |
707 // Called at the first checkpoint. | |
708 // | |
709 | |
710 void ConcurrentMark::clearNextBitmap() { | |
1359
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
711 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
712 G1CollectorPolicy* g1p = g1h->g1_policy(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
713 |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
714 // Make sure that the concurrent mark thread looks to still be in |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
715 // the current cycle. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
716 guarantee(cmThread()->during_cycle(), "invariant"); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
717 |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
718 // We are finishing up the current cycle by clearing the next |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
719 // marking bitmap and getting it ready for the next cycle. During |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
720 // this time no other cycle can start. So, let's make sure that this |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
721 // is the case. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
722 guarantee(!g1h->mark_in_progress(), "invariant"); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
723 |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
724 // clear the mark bitmap (no grey objects to start with). |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
725 // We need to do this in chunks and offer to yield in between |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
726 // each chunk. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
727 HeapWord* start = _nextMarkBitMap->startWord(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
728 HeapWord* end = _nextMarkBitMap->endWord(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
729 HeapWord* cur = start; |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
730 size_t chunkSize = M; |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
731 while (cur < end) { |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
732 HeapWord* next = cur + chunkSize; |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
733 if (next > end) |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
734 next = end; |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
735 MemRegion mr(cur,next); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
736 _nextMarkBitMap->clearRange(mr); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
737 cur = next; |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
738 do_yield_check(); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
739 |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
740 // Repeat the asserts from above. We'll do them as asserts here to |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
741 // minimize their overhead on the product. However, we'll have |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
742 // them as guarantees at the beginning / end of the bitmap |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
743 // clearing to get some checking in the product. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
744 assert(cmThread()->during_cycle(), "invariant"); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
745 assert(!g1h->mark_in_progress(), "invariant"); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
746 } |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
747 |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
748 // Repeat the asserts from above. |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
749 guarantee(cmThread()->during_cycle(), "invariant"); |
23b1b27ac76c
6909756: G1: guarantee(G1CollectedHeap::heap()->mark_in_progress(),"Precondition.")
tonyp
parents:
1358
diff
changeset
|
750 guarantee(!g1h->mark_in_progress(), "invariant"); |
342 | 751 } |
752 | |
753 class NoteStartOfMarkHRClosure: public HeapRegionClosure { | |
754 public: | |
755 bool doHeapRegion(HeapRegion* r) { | |
756 if (!r->continuesHumongous()) { | |
757 r->note_start_of_marking(true); | |
758 } | |
759 return false; | |
760 } | |
761 }; | |
762 | |
763 void ConcurrentMark::checkpointRootsInitialPre() { | |
764 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
765 G1CollectorPolicy* g1p = g1h->g1_policy(); | |
766 | |
767 _has_aborted = false; | |
768 | |
1547
fb1a39993f69
6951319: enable solaris builds using Sun Studio 12 update 1
jcoomes
parents:
1388
diff
changeset
|
769 #ifndef PRODUCT |
1044 | 770 if (G1PrintReachableAtInitialMark) { |
1388 | 771 print_reachable("at-cycle-start", |
772 true /* use_prev_marking */, true /* all */); | |
1044 | 773 } |
1547
fb1a39993f69
6951319: enable solaris builds using Sun Studio 12 update 1
jcoomes
parents:
1388
diff
changeset
|
774 #endif |
342 | 775 |
776 // Initialise marking structures. This has to be done in a STW phase. | |
777 reset(); | |
778 } | |
779 | |
780 class CMMarkRootsClosure: public OopsInGenClosure { | |
781 private: | |
782 ConcurrentMark* _cm; | |
783 G1CollectedHeap* _g1h; | |
784 bool _do_barrier; | |
785 | |
786 public: | |
787 CMMarkRootsClosure(ConcurrentMark* cm, | |
788 G1CollectedHeap* g1h, | |
789 bool do_barrier) : _cm(cm), _g1h(g1h), | |
790 _do_barrier(do_barrier) { } | |
791 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
792 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
793 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
794 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
795 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
796 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
797 if (!oopDesc::is_null(heap_oop)) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
798 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
799 assert(obj->is_oop() || obj->mark() == NULL, |
342 | 800 "expected an oop, possibly with mark word displaced"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
801 HeapWord* addr = (HeapWord*)obj; |
342 | 802 if (_g1h->is_in_g1_reserved(addr)) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
803 _cm->grayRoot(obj); |
342 | 804 } |
805 } | |
806 if (_do_barrier) { | |
807 assert(!_g1h->is_in_g1_reserved(p), | |
808 "Should be called on external roots"); | |
809 do_barrier(p); | |
810 } | |
811 } | |
812 }; | |
813 | |
814 void ConcurrentMark::checkpointRootsInitialPost() { | |
815 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
816 | |
817 // For each region note start of marking. | |
818 NoteStartOfMarkHRClosure startcl; | |
819 g1h->heap_region_iterate(&startcl); | |
820 | |
821 // Start weak-reference discovery. | |
822 ReferenceProcessor* rp = g1h->ref_processor(); | |
823 rp->verify_no_references_recorded(); | |
824 rp->enable_discovery(); // enable ("weak") refs discovery | |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
825 rp->setup_policy(false); // snapshot the soft ref policy to be used in this cycle |
342 | 826 |
827 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
1317
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
828 // This is the start of the marking cycle, we're expected all |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
829 // threads to have SATB queues with active set to false. |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
830 satb_mq_set.set_active_all_threads(true, /* new active value */ |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
831 false /* expected_active */); |
342 | 832 |
833 // update_g1_committed() will be called at the end of an evac pause | |
834 // when marking is on. So, it's also called at the end of the | |
835 // initial-mark pause to update the heap end, if the heap expands | |
836 // during it. No need to call it here. | |
837 } | |
838 | |
839 // Checkpoint the roots into this generation from outside | |
840 // this generation. [Note this initial checkpoint need only | |
841 // be approximate -- we'll do a catch up phase subsequently.] | |
842 void ConcurrentMark::checkpointRootsInitial() { | |
843 assert(SafepointSynchronize::is_at_safepoint(), "world should be stopped"); | |
844 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
845 | |
846 double start = os::elapsedTime(); | |
847 | |
848 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); | |
849 g1p->record_concurrent_mark_init_start(); | |
850 checkpointRootsInitialPre(); | |
851 | |
852 // YSR: when concurrent precleaning is in place, we'll | |
853 // need to clear the cached card table here | |
854 | |
855 ResourceMark rm; | |
856 HandleMark hm; | |
857 | |
858 g1h->ensure_parsability(false); | |
859 g1h->perm_gen()->save_marks(); | |
860 | |
861 CMMarkRootsClosure notOlder(this, g1h, false); | |
862 CMMarkRootsClosure older(this, g1h, true); | |
863 | |
864 g1h->set_marking_started(); | |
865 g1h->rem_set()->prepare_for_younger_refs_iterate(false); | |
866 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
867 g1h->process_strong_roots(true, // activate StrongRootsScope |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
868 false, // fake perm gen collection |
342 | 869 SharedHeap::SO_AllClasses, |
870 ¬Older, // Regular roots | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
871 NULL, // do not visit active blobs |
342 | 872 &older // Perm Gen Roots |
873 ); | |
874 checkpointRootsInitialPost(); | |
875 | |
876 // Statistics. | |
877 double end = os::elapsedTime(); | |
878 _init_times.add((end - start) * 1000.0); | |
879 | |
880 g1p->record_concurrent_mark_init_end(); | |
881 } | |
882 | |
883 /* | |
884 Notice that in the next two methods, we actually leave the STS | |
885 during the barrier sync and join it immediately afterwards. If we | |
886 do not do this, this then the following deadlock can occur: one | |
887 thread could be in the barrier sync code, waiting for the other | |
888 thread to also sync up, whereas another one could be trying to | |
889 yield, while also waiting for the other threads to sync up too. | |
890 | |
891 Because the thread that does the sync barrier has left the STS, it | |
892 is possible to be suspended for a Full GC or an evacuation pause | |
893 could occur. This is actually safe, since the entering the sync | |
894 barrier is one of the last things do_marking_step() does, and it | |
895 doesn't manipulate any data structures afterwards. | |
896 */ | |
897 | |
898 void ConcurrentMark::enter_first_sync_barrier(int task_num) { | |
899 if (verbose_low()) | |
900 gclog_or_tty->print_cr("[%d] entering first barrier", task_num); | |
901 | |
902 ConcurrentGCThread::stsLeave(); | |
903 _first_overflow_barrier_sync.enter(); | |
904 ConcurrentGCThread::stsJoin(); | |
905 // at this point everyone should have synced up and not be doing any | |
906 // more work | |
907 | |
908 if (verbose_low()) | |
909 gclog_or_tty->print_cr("[%d] leaving first barrier", task_num); | |
910 | |
911 // let task 0 do this | |
912 if (task_num == 0) { | |
913 // task 0 is responsible for clearing the global data structures | |
914 clear_marking_state(); | |
915 | |
916 if (PrintGC) { | |
917 gclog_or_tty->date_stamp(PrintGCDateStamps); | |
918 gclog_or_tty->stamp(PrintGCTimeStamps); | |
919 gclog_or_tty->print_cr("[GC concurrent-mark-reset-for-overflow]"); | |
920 } | |
921 } | |
922 | |
923 // after this, each task should reset its own data structures then | |
924 // then go into the second barrier | |
925 } | |
926 | |
927 void ConcurrentMark::enter_second_sync_barrier(int task_num) { | |
928 if (verbose_low()) | |
929 gclog_or_tty->print_cr("[%d] entering second barrier", task_num); | |
930 | |
931 ConcurrentGCThread::stsLeave(); | |
932 _second_overflow_barrier_sync.enter(); | |
933 ConcurrentGCThread::stsJoin(); | |
934 // at this point everything should be re-initialised and ready to go | |
935 | |
936 if (verbose_low()) | |
937 gclog_or_tty->print_cr("[%d] leaving second barrier", task_num); | |
938 } | |
939 | |
940 void ConcurrentMark::grayRoot(oop p) { | |
941 HeapWord* addr = (HeapWord*) p; | |
942 // We can't really check against _heap_start and _heap_end, since it | |
943 // is possible during an evacuation pause with piggy-backed | |
944 // initial-mark that the committed space is expanded during the | |
945 // pause without CM observing this change. So the assertions below | |
946 // is a bit conservative; but better than nothing. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
947 assert(_g1h->g1_committed().contains(addr), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
948 "address should be within the heap bounds"); |
342 | 949 |
950 if (!_nextMarkBitMap->isMarked(addr)) | |
951 _nextMarkBitMap->parMark(addr); | |
952 } | |
953 | |
954 void ConcurrentMark::grayRegionIfNecessary(MemRegion mr) { | |
955 // The objects on the region have already been marked "in bulk" by | |
956 // the caller. We only need to decide whether to push the region on | |
957 // the region stack or not. | |
958 | |
959 if (!concurrent_marking_in_progress() || !_should_gray_objects) | |
960 // We're done with marking and waiting for remark. We do not need to | |
961 // push anything else on the region stack. | |
962 return; | |
963 | |
964 HeapWord* finger = _finger; | |
965 | |
966 if (verbose_low()) | |
967 gclog_or_tty->print_cr("[global] attempting to push " | |
968 "region ["PTR_FORMAT", "PTR_FORMAT"), finger is at " | |
969 PTR_FORMAT, mr.start(), mr.end(), finger); | |
970 | |
971 if (mr.start() < finger) { | |
972 // The finger is always heap region aligned and it is not possible | |
973 // for mr to span heap regions. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
974 assert(mr.end() <= finger, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
975 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
976 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
977 assert(mr.start() <= mr.end(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
978 "region boundaries should fall within the committed space"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
979 assert(_heap_start <= mr.start(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
980 "region boundaries should fall within the committed space"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
981 assert(mr.end() <= _heap_end, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
982 "region boundaries should fall within the committed space"); |
342 | 983 if (verbose_low()) |
984 gclog_or_tty->print_cr("[global] region ["PTR_FORMAT", "PTR_FORMAT") " | |
985 "below the finger, pushing it", | |
986 mr.start(), mr.end()); | |
987 | |
988 if (!region_stack_push(mr)) { | |
989 if (verbose_low()) | |
990 gclog_or_tty->print_cr("[global] region stack has overflown."); | |
991 } | |
992 } | |
993 } | |
994 | |
995 void ConcurrentMark::markAndGrayObjectIfNecessary(oop p) { | |
996 // The object is not marked by the caller. We need to at least mark | |
997 // it and maybe push in on the stack. | |
998 | |
999 HeapWord* addr = (HeapWord*)p; | |
1000 if (!_nextMarkBitMap->isMarked(addr)) { | |
1001 // We definitely need to mark it, irrespective whether we bail out | |
1002 // because we're done with marking. | |
1003 if (_nextMarkBitMap->parMark(addr)) { | |
1004 if (!concurrent_marking_in_progress() || !_should_gray_objects) | |
1005 // If we're done with concurrent marking and we're waiting for | |
1006 // remark, then we're not pushing anything on the stack. | |
1007 return; | |
1008 | |
1009 // No OrderAccess:store_load() is needed. It is implicit in the | |
1010 // CAS done in parMark(addr) above | |
1011 HeapWord* finger = _finger; | |
1012 | |
1013 if (addr < finger) { | |
1014 if (!mark_stack_push(oop(addr))) { | |
1015 if (verbose_low()) | |
1016 gclog_or_tty->print_cr("[global] global stack overflow " | |
1017 "during parMark"); | |
1018 } | |
1019 } | |
1020 } | |
1021 } | |
1022 } | |
1023 | |
1024 class CMConcurrentMarkingTask: public AbstractGangTask { | |
1025 private: | |
1026 ConcurrentMark* _cm; | |
1027 ConcurrentMarkThread* _cmt; | |
1028 | |
1029 public: | |
1030 void work(int worker_i) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1031 assert(Thread::current()->is_ConcurrentGC_thread(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1032 "this should only be done by a conc GC thread"); |
342 | 1033 |
1034 double start_vtime = os::elapsedVTime(); | |
1035 | |
1036 ConcurrentGCThread::stsJoin(); | |
1037 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1038 assert((size_t) worker_i < _cm->active_tasks(), "invariant"); |
342 | 1039 CMTask* the_task = _cm->task(worker_i); |
1040 the_task->record_start_time(); | |
1041 if (!_cm->has_aborted()) { | |
1042 do { | |
1043 double start_vtime_sec = os::elapsedVTime(); | |
1044 double start_time_sec = os::elapsedTime(); | |
1045 the_task->do_marking_step(10.0); | |
1046 double end_time_sec = os::elapsedTime(); | |
1047 double end_vtime_sec = os::elapsedVTime(); | |
1048 double elapsed_vtime_sec = end_vtime_sec - start_vtime_sec; | |
1049 double elapsed_time_sec = end_time_sec - start_time_sec; | |
1050 _cm->clear_has_overflown(); | |
1051 | |
1052 bool ret = _cm->do_yield_check(worker_i); | |
1053 | |
1054 jlong sleep_time_ms; | |
1055 if (!_cm->has_aborted() && the_task->has_aborted()) { | |
1056 sleep_time_ms = | |
1057 (jlong) (elapsed_vtime_sec * _cm->sleep_factor() * 1000.0); | |
1058 ConcurrentGCThread::stsLeave(); | |
1059 os::sleep(Thread::current(), sleep_time_ms, false); | |
1060 ConcurrentGCThread::stsJoin(); | |
1061 } | |
1062 double end_time2_sec = os::elapsedTime(); | |
1063 double elapsed_time2_sec = end_time2_sec - start_time_sec; | |
1064 | |
1065 #if 0 | |
1066 gclog_or_tty->print_cr("CM: elapsed %1.4lf ms, sleep %1.4lf ms, " | |
1067 "overhead %1.4lf", | |
1068 elapsed_vtime_sec * 1000.0, (double) sleep_time_ms, | |
1069 the_task->conc_overhead(os::elapsedTime()) * 8.0); | |
1070 gclog_or_tty->print_cr("elapsed time %1.4lf ms, time 2: %1.4lf ms", | |
1071 elapsed_time_sec * 1000.0, elapsed_time2_sec * 1000.0); | |
1072 #endif | |
1073 } while (!_cm->has_aborted() && the_task->has_aborted()); | |
1074 } | |
1075 the_task->record_end_time(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1076 guarantee(!the_task->has_aborted() || _cm->has_aborted(), "invariant"); |
342 | 1077 |
1078 ConcurrentGCThread::stsLeave(); | |
1079 | |
1080 double end_vtime = os::elapsedVTime(); | |
1081 _cm->update_accum_task_vtime(worker_i, end_vtime - start_vtime); | |
1082 } | |
1083 | |
1084 CMConcurrentMarkingTask(ConcurrentMark* cm, | |
1085 ConcurrentMarkThread* cmt) : | |
1086 AbstractGangTask("Concurrent Mark"), _cm(cm), _cmt(cmt) { } | |
1087 | |
1088 ~CMConcurrentMarkingTask() { } | |
1089 }; | |
1090 | |
1091 void ConcurrentMark::markFromRoots() { | |
1092 // we might be tempted to assert that: | |
1093 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), | |
1094 // "inconsistent argument?"); | |
1095 // However that wouldn't be right, because it's possible that | |
1096 // a safepoint is indeed in progress as a younger generation | |
1097 // stop-the-world GC happens even as we mark in this generation. | |
1098 | |
1099 _restart_for_overflow = false; | |
1100 | |
1101 set_phase(MAX2((size_t) 1, parallel_marking_threads()), true); | |
1102 | |
1103 CMConcurrentMarkingTask markingTask(this, cmThread()); | |
1104 if (parallel_marking_threads() > 0) | |
1105 _parallel_workers->run_task(&markingTask); | |
1106 else | |
1107 markingTask.work(0); | |
1108 print_stats(); | |
1109 } | |
1110 | |
1111 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) { | |
1112 // world is stopped at this checkpoint | |
1113 assert(SafepointSynchronize::is_at_safepoint(), | |
1114 "world should be stopped"); | |
1115 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1116 | |
1117 // If a full collection has happened, we shouldn't do this. | |
1118 if (has_aborted()) { | |
1119 g1h->set_marking_complete(); // So bitmap clearing isn't confused | |
1120 return; | |
1121 } | |
1122 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1123 if (VerifyDuringGC) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1124 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1125 gclog_or_tty->print(" VerifyDuringGC:(before)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1126 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1127 Universe::verify(true, false, true); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1128 } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1129 |
342 | 1130 G1CollectorPolicy* g1p = g1h->g1_policy(); |
1131 g1p->record_concurrent_mark_remark_start(); | |
1132 | |
1133 double start = os::elapsedTime(); | |
1134 | |
1135 checkpointRootsFinalWork(); | |
1136 | |
1137 double mark_work_end = os::elapsedTime(); | |
1138 | |
1139 weakRefsWork(clear_all_soft_refs); | |
1140 | |
1141 if (has_overflown()) { | |
1142 // Oops. We overflowed. Restart concurrent marking. | |
1143 _restart_for_overflow = true; | |
1144 // Clear the flag. We do not need it any more. | |
1145 clear_has_overflown(); | |
1146 if (G1TraceMarkStackOverflow) | |
1147 gclog_or_tty->print_cr("\nRemark led to restart for overflow."); | |
1148 } else { | |
1149 // We're done with marking. | |
1317
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
1150 // This is the end of the marking cycle, we're expected all |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
1151 // threads to have SATB queues with active set to true. |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
1152 JavaThread::satb_mark_queue_set().set_active_all_threads( |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
1153 false, /* new active value */ |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
1154 true /* expected_active */); |
811 | 1155 |
1156 if (VerifyDuringGC) { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1157 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1158 gclog_or_tty->print(" VerifyDuringGC:(after)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1159 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1160 Universe::heap()->verify(/* allow_dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1161 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1162 /* use_prev_marking */ false); |
811 | 1163 } |
342 | 1164 } |
1165 | |
1166 #if VERIFY_OBJS_PROCESSED | |
1167 _scan_obj_cl.objs_processed = 0; | |
1168 ThreadLocalObjQueue::objs_enqueued = 0; | |
1169 #endif | |
1170 | |
1171 // Statistics | |
1172 double now = os::elapsedTime(); | |
1173 _remark_mark_times.add((mark_work_end - start) * 1000.0); | |
1174 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0); | |
1175 _remark_times.add((now - start) * 1000.0); | |
1176 | |
1177 g1p->record_concurrent_mark_remark_end(); | |
1178 } | |
1179 | |
1180 | |
1181 #define CARD_BM_TEST_MODE 0 | |
1182 | |
1183 class CalcLiveObjectsClosure: public HeapRegionClosure { | |
1184 | |
1185 CMBitMapRO* _bm; | |
1186 ConcurrentMark* _cm; | |
1187 bool _changed; | |
1188 bool _yield; | |
1189 size_t _words_done; | |
1190 size_t _tot_live; | |
1191 size_t _tot_used; | |
1192 size_t _regions_done; | |
1193 double _start_vtime_sec; | |
1194 | |
1195 BitMap* _region_bm; | |
1196 BitMap* _card_bm; | |
1197 intptr_t _bottom_card_num; | |
1198 bool _final; | |
1199 | |
1200 void mark_card_num_range(intptr_t start_card_num, intptr_t last_card_num) { | |
1201 for (intptr_t i = start_card_num; i <= last_card_num; i++) { | |
1202 #if CARD_BM_TEST_MODE | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1203 guarantee(_card_bm->at(i - _bottom_card_num), "Should already be set."); |
342 | 1204 #else |
1205 _card_bm->par_at_put(i - _bottom_card_num, 1); | |
1206 #endif | |
1207 } | |
1208 } | |
1209 | |
1210 public: | |
1211 CalcLiveObjectsClosure(bool final, | |
1212 CMBitMapRO *bm, ConcurrentMark *cm, | |
936 | 1213 BitMap* region_bm, BitMap* card_bm) : |
342 | 1214 _bm(bm), _cm(cm), _changed(false), _yield(true), |
1215 _words_done(0), _tot_live(0), _tot_used(0), | |
936 | 1216 _region_bm(region_bm), _card_bm(card_bm),_final(final), |
342 | 1217 _regions_done(0), _start_vtime_sec(0.0) |
1218 { | |
1219 _bottom_card_num = | |
1220 intptr_t(uintptr_t(G1CollectedHeap::heap()->reserved_region().start()) >> | |
1221 CardTableModRefBS::card_shift); | |
1222 } | |
1223 | |
829 | 1224 // It takes a region that's not empty (i.e., it has at least one |
1225 // live object in it and sets its corresponding bit on the region | |
1226 // bitmap to 1. If the region is "starts humongous" it will also set | |
1227 // to 1 the bits on the region bitmap that correspond to its | |
1228 // associated "continues humongous" regions. | |
1229 void set_bit_for_region(HeapRegion* hr) { | |
1230 assert(!hr->continuesHumongous(), "should have filtered those out"); | |
1231 | |
1232 size_t index = hr->hrs_index(); | |
1233 if (!hr->startsHumongous()) { | |
1234 // Normal (non-humongous) case: just set the bit. | |
1235 _region_bm->par_at_put((BitMap::idx_t) index, true); | |
1236 } else { | |
1237 // Starts humongous case: calculate how many regions are part of | |
1238 // this humongous region and then set the bit range. It might | |
1239 // have been a bit more efficient to look at the object that | |
1240 // spans these humongous regions to calculate their number from | |
1241 // the object's size. However, it's a good idea to calculate | |
1242 // this based on the metadata itself, and not the region | |
1243 // contents, so that this code is not aware of what goes into | |
1244 // the humongous regions (in case this changes in the future). | |
1245 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1246 size_t end_index = index + 1; | |
831 | 1247 while (end_index < g1h->n_regions()) { |
1248 HeapRegion* chr = g1h->region_at(end_index); | |
829 | 1249 if (!chr->continuesHumongous()) { |
1250 break; | |
1251 } | |
1252 end_index += 1; | |
1253 } | |
1254 _region_bm->par_at_put_range((BitMap::idx_t) index, | |
1255 (BitMap::idx_t) end_index, true); | |
1256 } | |
1257 } | |
1258 | |
342 | 1259 bool doHeapRegion(HeapRegion* hr) { |
1260 if (!_final && _regions_done == 0) | |
1261 _start_vtime_sec = os::elapsedVTime(); | |
1262 | |
639 | 1263 if (hr->continuesHumongous()) { |
829 | 1264 // We will ignore these here and process them when their |
1265 // associated "starts humongous" region is processed (see | |
1266 // set_bit_for_heap_region()). Note that we cannot rely on their | |
1267 // associated "starts humongous" region to have their bit set to | |
1268 // 1 since, due to the region chunking in the parallel region | |
1269 // iteration, a "continues humongous" region might be visited | |
1270 // before its associated "starts humongous". | |
639 | 1271 return false; |
1272 } | |
342 | 1273 |
1274 HeapWord* nextTop = hr->next_top_at_mark_start(); | |
1275 HeapWord* start = hr->top_at_conc_mark_count(); | |
1276 assert(hr->bottom() <= start && start <= hr->end() && | |
1277 hr->bottom() <= nextTop && nextTop <= hr->end() && | |
1278 start <= nextTop, | |
1279 "Preconditions."); | |
1280 // Otherwise, record the number of word's we'll examine. | |
1281 size_t words_done = (nextTop - start); | |
1282 // Find the first marked object at or after "start". | |
1283 start = _bm->getNextMarkedWordAddress(start, nextTop); | |
1284 size_t marked_bytes = 0; | |
1285 | |
1286 // Below, the term "card num" means the result of shifting an address | |
1287 // by the card shift -- address 0 corresponds to card number 0. One | |
1288 // must subtract the card num of the bottom of the heap to obtain a | |
1289 // card table index. | |
1290 // The first card num of the sequence of live cards currently being | |
1291 // constructed. -1 ==> no sequence. | |
1292 intptr_t start_card_num = -1; | |
1293 // The last card num of the sequence of live cards currently being | |
1294 // constructed. -1 ==> no sequence. | |
1295 intptr_t last_card_num = -1; | |
1296 | |
1297 while (start < nextTop) { | |
1298 if (_yield && _cm->do_yield_check()) { | |
1299 // We yielded. It might be for a full collection, in which case | |
1300 // all bets are off; terminate the traversal. | |
1301 if (_cm->has_aborted()) { | |
1302 _changed = false; | |
1303 return true; | |
1304 } else { | |
1305 // Otherwise, it might be a collection pause, and the region | |
1306 // we're looking at might be in the collection set. We'll | |
1307 // abandon this region. | |
1308 return false; | |
1309 } | |
1310 } | |
1311 oop obj = oop(start); | |
1312 int obj_sz = obj->size(); | |
1313 // The card num of the start of the current object. | |
1314 intptr_t obj_card_num = | |
1315 intptr_t(uintptr_t(start) >> CardTableModRefBS::card_shift); | |
1316 | |
1317 HeapWord* obj_last = start + obj_sz - 1; | |
1318 intptr_t obj_last_card_num = | |
1319 intptr_t(uintptr_t(obj_last) >> CardTableModRefBS::card_shift); | |
1320 | |
1321 if (obj_card_num != last_card_num) { | |
1322 if (start_card_num == -1) { | |
1323 assert(last_card_num == -1, "Both or neither."); | |
1324 start_card_num = obj_card_num; | |
1325 } else { | |
1326 assert(last_card_num != -1, "Both or neither."); | |
1327 assert(obj_card_num >= last_card_num, "Inv"); | |
1328 if ((obj_card_num - last_card_num) > 1) { | |
1329 // Mark the last run, and start a new one. | |
1330 mark_card_num_range(start_card_num, last_card_num); | |
1331 start_card_num = obj_card_num; | |
1332 } | |
1333 } | |
1334 #if CARD_BM_TEST_MODE | |
1335 /* | |
1336 gclog_or_tty->print_cr("Setting bits from %d/%d.", | |
1337 obj_card_num - _bottom_card_num, | |
1338 obj_last_card_num - _bottom_card_num); | |
1339 */ | |
1340 for (intptr_t j = obj_card_num; j <= obj_last_card_num; j++) { | |
1341 _card_bm->par_at_put(j - _bottom_card_num, 1); | |
1342 } | |
1343 #endif | |
1344 } | |
1345 // In any case, we set the last card num. | |
1346 last_card_num = obj_last_card_num; | |
1347 | |
1030
dfdaf65c3423
6858886: G1: guarantee(_next_marked_bytes <= used(),"invariant") at heapRegion.hpp:359
apetrusenko
parents:
1023
diff
changeset
|
1348 marked_bytes += (size_t)obj_sz * HeapWordSize; |
342 | 1349 // Find the next marked object after this one. |
1350 start = _bm->getNextMarkedWordAddress(start + 1, nextTop); | |
1351 _changed = true; | |
1352 } | |
1353 // Handle the last range, if any. | |
1354 if (start_card_num != -1) | |
1355 mark_card_num_range(start_card_num, last_card_num); | |
1356 if (_final) { | |
1357 // Mark the allocated-since-marking portion... | |
1358 HeapWord* tp = hr->top(); | |
1359 if (nextTop < tp) { | |
1360 start_card_num = | |
1361 intptr_t(uintptr_t(nextTop) >> CardTableModRefBS::card_shift); | |
1362 last_card_num = | |
1363 intptr_t(uintptr_t(tp) >> CardTableModRefBS::card_shift); | |
1364 mark_card_num_range(start_card_num, last_card_num); | |
1365 // This definitely means the region has live objects. | |
829 | 1366 set_bit_for_region(hr); |
342 | 1367 } |
1368 } | |
1369 | |
1370 hr->add_to_marked_bytes(marked_bytes); | |
1371 // Update the live region bitmap. | |
1372 if (marked_bytes > 0) { | |
829 | 1373 set_bit_for_region(hr); |
342 | 1374 } |
1375 hr->set_top_at_conc_mark_count(nextTop); | |
1376 _tot_live += hr->next_live_bytes(); | |
1377 _tot_used += hr->used(); | |
1378 _words_done = words_done; | |
1379 | |
1380 if (!_final) { | |
1381 ++_regions_done; | |
1382 if (_regions_done % 10 == 0) { | |
1383 double end_vtime_sec = os::elapsedVTime(); | |
1384 double elapsed_vtime_sec = end_vtime_sec - _start_vtime_sec; | |
1385 if (elapsed_vtime_sec > (10.0 / 1000.0)) { | |
1386 jlong sleep_time_ms = | |
1387 (jlong) (elapsed_vtime_sec * _cm->cleanup_sleep_factor() * 1000.0); | |
1388 os::sleep(Thread::current(), sleep_time_ms, false); | |
1389 _start_vtime_sec = end_vtime_sec; | |
1390 } | |
1391 } | |
1392 } | |
1393 | |
1394 return false; | |
1395 } | |
1396 | |
1397 bool changed() { return _changed; } | |
1398 void reset() { _changed = false; _words_done = 0; } | |
1399 void no_yield() { _yield = false; } | |
1400 size_t words_done() { return _words_done; } | |
1401 size_t tot_live() { return _tot_live; } | |
1402 size_t tot_used() { return _tot_used; } | |
1403 }; | |
1404 | |
1405 | |
1406 void ConcurrentMark::calcDesiredRegions() { | |
1407 _region_bm.clear(); | |
1408 _card_bm.clear(); | |
1409 CalcLiveObjectsClosure calccl(false /*final*/, | |
1410 nextMarkBitMap(), this, | |
936 | 1411 &_region_bm, &_card_bm); |
342 | 1412 G1CollectedHeap *g1h = G1CollectedHeap::heap(); |
1413 g1h->heap_region_iterate(&calccl); | |
1414 | |
1415 do { | |
1416 calccl.reset(); | |
1417 g1h->heap_region_iterate(&calccl); | |
1418 } while (calccl.changed()); | |
1419 } | |
1420 | |
1421 class G1ParFinalCountTask: public AbstractGangTask { | |
1422 protected: | |
1423 G1CollectedHeap* _g1h; | |
1424 CMBitMap* _bm; | |
1425 size_t _n_workers; | |
1426 size_t *_live_bytes; | |
1427 size_t *_used_bytes; | |
1428 BitMap* _region_bm; | |
1429 BitMap* _card_bm; | |
1430 public: | |
1431 G1ParFinalCountTask(G1CollectedHeap* g1h, CMBitMap* bm, | |
1432 BitMap* region_bm, BitMap* card_bm) : | |
1433 AbstractGangTask("G1 final counting"), _g1h(g1h), | |
1434 _bm(bm), _region_bm(region_bm), _card_bm(card_bm) | |
1435 { | |
1436 if (ParallelGCThreads > 0) | |
1437 _n_workers = _g1h->workers()->total_workers(); | |
1438 else | |
1439 _n_workers = 1; | |
1440 _live_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | |
1441 _used_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | |
1442 } | |
1443 | |
1444 ~G1ParFinalCountTask() { | |
1445 FREE_C_HEAP_ARRAY(size_t, _live_bytes); | |
1446 FREE_C_HEAP_ARRAY(size_t, _used_bytes); | |
1447 } | |
1448 | |
1449 void work(int i) { | |
1450 CalcLiveObjectsClosure calccl(true /*final*/, | |
1451 _bm, _g1h->concurrent_mark(), | |
936 | 1452 _region_bm, _card_bm); |
342 | 1453 calccl.no_yield(); |
1454 if (ParallelGCThreads > 0) { | |
355 | 1455 _g1h->heap_region_par_iterate_chunked(&calccl, i, |
1456 HeapRegion::FinalCountClaimValue); | |
342 | 1457 } else { |
1458 _g1h->heap_region_iterate(&calccl); | |
1459 } | |
1460 assert(calccl.complete(), "Shouldn't have yielded!"); | |
1461 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1462 assert((size_t) i < _n_workers, "invariant"); |
342 | 1463 _live_bytes[i] = calccl.tot_live(); |
1464 _used_bytes[i] = calccl.tot_used(); | |
1465 } | |
1466 size_t live_bytes() { | |
1467 size_t live_bytes = 0; | |
1468 for (size_t i = 0; i < _n_workers; ++i) | |
1469 live_bytes += _live_bytes[i]; | |
1470 return live_bytes; | |
1471 } | |
1472 size_t used_bytes() { | |
1473 size_t used_bytes = 0; | |
1474 for (size_t i = 0; i < _n_workers; ++i) | |
1475 used_bytes += _used_bytes[i]; | |
1476 return used_bytes; | |
1477 } | |
1478 }; | |
1479 | |
1480 class G1ParNoteEndTask; | |
1481 | |
1482 class G1NoteEndOfConcMarkClosure : public HeapRegionClosure { | |
1483 G1CollectedHeap* _g1; | |
1484 int _worker_num; | |
1485 size_t _max_live_bytes; | |
1486 size_t _regions_claimed; | |
1487 size_t _freed_bytes; | |
1488 size_t _cleared_h_regions; | |
1489 size_t _freed_regions; | |
1490 UncleanRegionList* _unclean_region_list; | |
1491 double _claimed_region_time; | |
1492 double _max_region_time; | |
1493 | |
1494 public: | |
1495 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1, | |
1496 UncleanRegionList* list, | |
1497 int worker_num); | |
1498 size_t freed_bytes() { return _freed_bytes; } | |
1499 size_t cleared_h_regions() { return _cleared_h_regions; } | |
1500 size_t freed_regions() { return _freed_regions; } | |
1501 UncleanRegionList* unclean_region_list() { | |
1502 return _unclean_region_list; | |
1503 } | |
1504 | |
1505 bool doHeapRegion(HeapRegion *r); | |
1506 | |
1507 size_t max_live_bytes() { return _max_live_bytes; } | |
1508 size_t regions_claimed() { return _regions_claimed; } | |
1509 double claimed_region_time_sec() { return _claimed_region_time; } | |
1510 double max_region_time_sec() { return _max_region_time; } | |
1511 }; | |
1512 | |
1513 class G1ParNoteEndTask: public AbstractGangTask { | |
1514 friend class G1NoteEndOfConcMarkClosure; | |
1515 protected: | |
1516 G1CollectedHeap* _g1h; | |
1517 size_t _max_live_bytes; | |
1518 size_t _freed_bytes; | |
1519 ConcurrentMark::ParCleanupThreadState** _par_cleanup_thread_state; | |
1520 public: | |
1521 G1ParNoteEndTask(G1CollectedHeap* g1h, | |
1522 ConcurrentMark::ParCleanupThreadState** | |
1523 par_cleanup_thread_state) : | |
1524 AbstractGangTask("G1 note end"), _g1h(g1h), | |
1525 _max_live_bytes(0), _freed_bytes(0), | |
1526 _par_cleanup_thread_state(par_cleanup_thread_state) | |
1527 {} | |
1528 | |
1529 void work(int i) { | |
1530 double start = os::elapsedTime(); | |
1531 G1NoteEndOfConcMarkClosure g1_note_end(_g1h, | |
1532 &_par_cleanup_thread_state[i]->list, | |
1533 i); | |
1534 if (ParallelGCThreads > 0) { | |
355 | 1535 _g1h->heap_region_par_iterate_chunked(&g1_note_end, i, |
1536 HeapRegion::NoteEndClaimValue); | |
342 | 1537 } else { |
1538 _g1h->heap_region_iterate(&g1_note_end); | |
1539 } | |
1540 assert(g1_note_end.complete(), "Shouldn't have yielded!"); | |
1541 | |
1542 // Now finish up freeing the current thread's regions. | |
1543 _g1h->finish_free_region_work(g1_note_end.freed_bytes(), | |
1544 g1_note_end.cleared_h_regions(), | |
1545 0, NULL); | |
1546 { | |
1547 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); | |
1548 _max_live_bytes += g1_note_end.max_live_bytes(); | |
1549 _freed_bytes += g1_note_end.freed_bytes(); | |
1550 } | |
1551 double end = os::elapsedTime(); | |
1552 if (G1PrintParCleanupStats) { | |
1553 gclog_or_tty->print(" Worker thread %d [%8.3f..%8.3f = %8.3f ms] " | |
1554 "claimed %d regions (tot = %8.3f ms, max = %8.3f ms).\n", | |
1555 i, start, end, (end-start)*1000.0, | |
1556 g1_note_end.regions_claimed(), | |
1557 g1_note_end.claimed_region_time_sec()*1000.0, | |
1558 g1_note_end.max_region_time_sec()*1000.0); | |
1559 } | |
1560 } | |
1561 size_t max_live_bytes() { return _max_live_bytes; } | |
1562 size_t freed_bytes() { return _freed_bytes; } | |
1563 }; | |
1564 | |
1565 class G1ParScrubRemSetTask: public AbstractGangTask { | |
1566 protected: | |
1567 G1RemSet* _g1rs; | |
1568 BitMap* _region_bm; | |
1569 BitMap* _card_bm; | |
1570 public: | |
1571 G1ParScrubRemSetTask(G1CollectedHeap* g1h, | |
1572 BitMap* region_bm, BitMap* card_bm) : | |
1573 AbstractGangTask("G1 ScrubRS"), _g1rs(g1h->g1_rem_set()), | |
1574 _region_bm(region_bm), _card_bm(card_bm) | |
1575 {} | |
1576 | |
1577 void work(int i) { | |
1578 if (ParallelGCThreads > 0) { | |
355 | 1579 _g1rs->scrub_par(_region_bm, _card_bm, i, |
1580 HeapRegion::ScrubRemSetClaimValue); | |
342 | 1581 } else { |
1582 _g1rs->scrub(_region_bm, _card_bm); | |
1583 } | |
1584 } | |
1585 | |
1586 }; | |
1587 | |
1588 G1NoteEndOfConcMarkClosure:: | |
1589 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1, | |
1590 UncleanRegionList* list, | |
1591 int worker_num) | |
1592 : _g1(g1), _worker_num(worker_num), | |
1593 _max_live_bytes(0), _regions_claimed(0), | |
1594 _freed_bytes(0), _cleared_h_regions(0), _freed_regions(0), | |
1595 _claimed_region_time(0.0), _max_region_time(0.0), | |
1596 _unclean_region_list(list) | |
1597 {} | |
1598 | |
1599 bool G1NoteEndOfConcMarkClosure::doHeapRegion(HeapRegion *r) { | |
1600 // We use a claim value of zero here because all regions | |
1601 // were claimed with value 1 in the FinalCount task. | |
1602 r->reset_gc_time_stamp(); | |
1603 if (!r->continuesHumongous()) { | |
1604 double start = os::elapsedTime(); | |
1605 _regions_claimed++; | |
1606 r->note_end_of_marking(); | |
1607 _max_live_bytes += r->max_live_bytes(); | |
1608 _g1->free_region_if_totally_empty_work(r, | |
1609 _freed_bytes, | |
1610 _cleared_h_regions, | |
1611 _freed_regions, | |
1612 _unclean_region_list, | |
1613 true /*par*/); | |
1614 double region_time = (os::elapsedTime() - start); | |
1615 _claimed_region_time += region_time; | |
1616 if (region_time > _max_region_time) _max_region_time = region_time; | |
1617 } | |
1618 return false; | |
1619 } | |
1620 | |
1621 void ConcurrentMark::cleanup() { | |
1622 // world is stopped at this checkpoint | |
1623 assert(SafepointSynchronize::is_at_safepoint(), | |
1624 "world should be stopped"); | |
1625 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1626 | |
1627 // If a full collection has happened, we shouldn't do this. | |
1628 if (has_aborted()) { | |
1629 g1h->set_marking_complete(); // So bitmap clearing isn't confused | |
1630 return; | |
1631 } | |
1632 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1633 if (VerifyDuringGC) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1634 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1635 gclog_or_tty->print(" VerifyDuringGC:(before)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1636 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1637 Universe::verify(/* allow dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1638 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1639 /* prev marking */ true); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1640 } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1641 |
342 | 1642 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy(); |
1643 g1p->record_concurrent_mark_cleanup_start(); | |
1644 | |
1645 double start = os::elapsedTime(); | |
1646 | |
1647 // Do counting once more with the world stopped for good measure. | |
1648 G1ParFinalCountTask g1_par_count_task(g1h, nextMarkBitMap(), | |
1649 &_region_bm, &_card_bm); | |
1650 if (ParallelGCThreads > 0) { | |
355 | 1651 assert(g1h->check_heap_region_claim_values( |
1652 HeapRegion::InitialClaimValue), | |
1653 "sanity check"); | |
1654 | |
342 | 1655 int n_workers = g1h->workers()->total_workers(); |
1656 g1h->set_par_threads(n_workers); | |
1657 g1h->workers()->run_task(&g1_par_count_task); | |
1658 g1h->set_par_threads(0); | |
355 | 1659 |
1660 assert(g1h->check_heap_region_claim_values( | |
1661 HeapRegion::FinalCountClaimValue), | |
1662 "sanity check"); | |
342 | 1663 } else { |
1664 g1_par_count_task.work(0); | |
1665 } | |
1666 | |
1667 size_t known_garbage_bytes = | |
1668 g1_par_count_task.used_bytes() - g1_par_count_task.live_bytes(); | |
1669 #if 0 | |
1670 gclog_or_tty->print_cr("used %1.2lf, live %1.2lf, garbage %1.2lf", | |
1671 (double) g1_par_count_task.used_bytes() / (double) (1024 * 1024), | |
1672 (double) g1_par_count_task.live_bytes() / (double) (1024 * 1024), | |
1673 (double) known_garbage_bytes / (double) (1024 * 1024)); | |
1674 #endif // 0 | |
1675 g1p->set_known_garbage_bytes(known_garbage_bytes); | |
1676 | |
1677 size_t start_used_bytes = g1h->used(); | |
1678 _at_least_one_mark_complete = true; | |
1679 g1h->set_marking_complete(); | |
1680 | |
1681 double count_end = os::elapsedTime(); | |
1682 double this_final_counting_time = (count_end - start); | |
1683 if (G1PrintParCleanupStats) { | |
1684 gclog_or_tty->print_cr("Cleanup:"); | |
1685 gclog_or_tty->print_cr(" Finalize counting: %8.3f ms", | |
1686 this_final_counting_time*1000.0); | |
1687 } | |
1688 _total_counting_time += this_final_counting_time; | |
1689 | |
1690 // Install newly created mark bitMap as "prev". | |
1691 swapMarkBitMaps(); | |
1692 | |
1693 g1h->reset_gc_time_stamp(); | |
1694 | |
1695 // Note end of marking in all heap regions. | |
1696 double note_end_start = os::elapsedTime(); | |
1697 G1ParNoteEndTask g1_par_note_end_task(g1h, _par_cleanup_thread_state); | |
1698 if (ParallelGCThreads > 0) { | |
1699 int n_workers = g1h->workers()->total_workers(); | |
1700 g1h->set_par_threads(n_workers); | |
1701 g1h->workers()->run_task(&g1_par_note_end_task); | |
1702 g1h->set_par_threads(0); | |
355 | 1703 |
1704 assert(g1h->check_heap_region_claim_values(HeapRegion::NoteEndClaimValue), | |
1705 "sanity check"); | |
342 | 1706 } else { |
1707 g1_par_note_end_task.work(0); | |
1708 } | |
1709 g1h->set_unclean_regions_coming(true); | |
1710 double note_end_end = os::elapsedTime(); | |
1711 // Tell the mutators that there might be unclean regions coming... | |
1712 if (G1PrintParCleanupStats) { | |
1713 gclog_or_tty->print_cr(" note end of marking: %8.3f ms.", | |
1714 (note_end_end - note_end_start)*1000.0); | |
1715 } | |
1716 | |
355 | 1717 |
342 | 1718 // call below, since it affects the metric by which we sort the heap |
1719 // regions. | |
1720 if (G1ScrubRemSets) { | |
1721 double rs_scrub_start = os::elapsedTime(); | |
1722 G1ParScrubRemSetTask g1_par_scrub_rs_task(g1h, &_region_bm, &_card_bm); | |
1723 if (ParallelGCThreads > 0) { | |
1724 int n_workers = g1h->workers()->total_workers(); | |
1725 g1h->set_par_threads(n_workers); | |
1726 g1h->workers()->run_task(&g1_par_scrub_rs_task); | |
1727 g1h->set_par_threads(0); | |
355 | 1728 |
1729 assert(g1h->check_heap_region_claim_values( | |
1730 HeapRegion::ScrubRemSetClaimValue), | |
1731 "sanity check"); | |
342 | 1732 } else { |
1733 g1_par_scrub_rs_task.work(0); | |
1734 } | |
1735 | |
1736 double rs_scrub_end = os::elapsedTime(); | |
1737 double this_rs_scrub_time = (rs_scrub_end - rs_scrub_start); | |
1738 _total_rs_scrub_time += this_rs_scrub_time; | |
1739 } | |
1740 | |
1741 // this will also free any regions totally full of garbage objects, | |
1742 // and sort the regions. | |
1743 g1h->g1_policy()->record_concurrent_mark_cleanup_end( | |
1744 g1_par_note_end_task.freed_bytes(), | |
1745 g1_par_note_end_task.max_live_bytes()); | |
1746 | |
1747 // Statistics. | |
1748 double end = os::elapsedTime(); | |
1749 _cleanup_times.add((end - start) * 1000.0); | |
1750 | |
1751 // G1CollectedHeap::heap()->print(); | |
1752 // gclog_or_tty->print_cr("HEAP GC TIME STAMP : %d", | |
1753 // G1CollectedHeap::heap()->get_gc_time_stamp()); | |
1754 | |
1755 if (PrintGC || PrintGCDetails) { | |
1756 g1h->print_size_transition(gclog_or_tty, | |
1757 start_used_bytes, | |
1758 g1h->used(), | |
1759 g1h->capacity()); | |
1760 } | |
1761 | |
1762 size_t cleaned_up_bytes = start_used_bytes - g1h->used(); | |
1763 g1p->decrease_known_garbage_bytes(cleaned_up_bytes); | |
1764 | |
1765 // We need to make this be a "collection" so any collection pause that | |
1766 // races with it goes around and waits for completeCleanup to finish. | |
1767 g1h->increment_total_collections(); | |
1768 | |
751 | 1769 if (VerifyDuringGC) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1770 HandleMark hm; // handle scope |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1771 gclog_or_tty->print(" VerifyDuringGC:(after)"); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1772 Universe::heap()->prepare_for_verify(); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1773 Universe::verify(/* allow dirty */ true, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1774 /* silent */ false, |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1775 /* prev marking */ true); |
342 | 1776 } |
1777 } | |
1778 | |
1779 void ConcurrentMark::completeCleanup() { | |
1780 // A full collection intervened. | |
1781 if (has_aborted()) return; | |
1782 | |
1783 int first = 0; | |
1784 int last = (int)MAX2(ParallelGCThreads, (size_t)1); | |
1785 for (int t = 0; t < last; t++) { | |
1786 UncleanRegionList* list = &_par_cleanup_thread_state[t]->list; | |
1787 assert(list->well_formed(), "Inv"); | |
1788 HeapRegion* hd = list->hd(); | |
1789 while (hd != NULL) { | |
1790 // Now finish up the other stuff. | |
1791 hd->rem_set()->clear(); | |
1792 HeapRegion* next_hd = hd->next_from_unclean_list(); | |
1793 (void)list->pop(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1794 assert(list->hd() == next_hd, "how not?"); |
342 | 1795 _g1h->put_region_on_unclean_list(hd); |
1796 if (!hd->isHumongous()) { | |
1797 // Add this to the _free_regions count by 1. | |
1798 _g1h->finish_free_region_work(0, 0, 1, NULL); | |
1799 } | |
1800 hd = list->hd(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1801 assert(hd == next_hd, "how not?"); |
342 | 1802 } |
1803 } | |
1804 } | |
1805 | |
1806 | |
1807 class G1CMIsAliveClosure: public BoolObjectClosure { | |
1808 G1CollectedHeap* _g1; | |
1809 public: | |
1810 G1CMIsAliveClosure(G1CollectedHeap* g1) : | |
1811 _g1(g1) | |
1812 {} | |
1813 | |
1814 void do_object(oop obj) { | |
1815 assert(false, "not to be invoked"); | |
1816 } | |
1817 bool do_object_b(oop obj) { | |
1818 HeapWord* addr = (HeapWord*)obj; | |
1819 return addr != NULL && | |
1820 (!_g1->is_in_g1_reserved(addr) || !_g1->is_obj_ill(obj)); | |
1821 } | |
1822 }; | |
1823 | |
1824 class G1CMKeepAliveClosure: public OopClosure { | |
1825 G1CollectedHeap* _g1; | |
1826 ConcurrentMark* _cm; | |
1827 CMBitMap* _bitMap; | |
1828 public: | |
1829 G1CMKeepAliveClosure(G1CollectedHeap* g1, ConcurrentMark* cm, | |
1830 CMBitMap* bitMap) : | |
1831 _g1(g1), _cm(cm), | |
1832 _bitMap(bitMap) {} | |
1833 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1834 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1835 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1836 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1837 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
1838 oop thisOop = oopDesc::load_decode_heap_oop(p); |
342 | 1839 HeapWord* addr = (HeapWord*)thisOop; |
1840 if (_g1->is_in_g1_reserved(addr) && _g1->is_obj_ill(thisOop)) { | |
1841 _bitMap->mark(addr); | |
1842 _cm->mark_stack_push(thisOop); | |
1843 } | |
1844 } | |
1845 }; | |
1846 | |
1847 class G1CMDrainMarkingStackClosure: public VoidClosure { | |
1848 CMMarkStack* _markStack; | |
1849 CMBitMap* _bitMap; | |
1850 G1CMKeepAliveClosure* _oopClosure; | |
1851 public: | |
1852 G1CMDrainMarkingStackClosure(CMBitMap* bitMap, CMMarkStack* markStack, | |
1853 G1CMKeepAliveClosure* oopClosure) : | |
1854 _bitMap(bitMap), | |
1855 _markStack(markStack), | |
1856 _oopClosure(oopClosure) | |
1857 {} | |
1858 | |
1859 void do_void() { | |
1860 _markStack->drain((OopClosure*)_oopClosure, _bitMap, false); | |
1861 } | |
1862 }; | |
1863 | |
1864 void ConcurrentMark::weakRefsWork(bool clear_all_soft_refs) { | |
1865 ResourceMark rm; | |
1866 HandleMark hm; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1867 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1868 ReferenceProcessor* rp = g1h->ref_processor(); |
342 | 1869 |
1870 // Process weak references. | |
457
27a80744a83b
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
ysr
parents:
453
diff
changeset
|
1871 rp->setup_policy(clear_all_soft_refs); |
342 | 1872 assert(_markStack.isEmpty(), "mark stack should be empty"); |
1873 | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1874 G1CMIsAliveClosure g1IsAliveClosure (g1h); |
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1875 G1CMKeepAliveClosure g1KeepAliveClosure(g1h, this, nextMarkBitMap()); |
342 | 1876 G1CMDrainMarkingStackClosure |
1877 g1DrainMarkingStackClosure(nextMarkBitMap(), &_markStack, | |
1878 &g1KeepAliveClosure); | |
1879 | |
1880 // XXXYYY Also: copy the parallel ref processing code from CMS. | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
355
diff
changeset
|
1881 rp->process_discovered_references(&g1IsAliveClosure, |
342 | 1882 &g1KeepAliveClosure, |
1883 &g1DrainMarkingStackClosure, | |
1884 NULL); | |
1885 assert(_markStack.overflow() || _markStack.isEmpty(), | |
1886 "mark stack should be empty (unless it overflowed)"); | |
1887 if (_markStack.overflow()) { | |
1888 set_has_overflown(); | |
1889 } | |
1890 | |
1891 rp->enqueue_discovered_references(); | |
1892 rp->verify_no_references_recorded(); | |
1893 assert(!rp->discovery_enabled(), "should have been disabled"); | |
1894 | |
1895 // Now clean up stale oops in SymbolTable and StringTable | |
1896 SymbolTable::unlink(&g1IsAliveClosure); | |
1897 StringTable::unlink(&g1IsAliveClosure); | |
1898 } | |
1899 | |
1900 void ConcurrentMark::swapMarkBitMaps() { | |
1901 CMBitMapRO* temp = _prevMarkBitMap; | |
1902 _prevMarkBitMap = (CMBitMapRO*)_nextMarkBitMap; | |
1903 _nextMarkBitMap = (CMBitMap*) temp; | |
1904 } | |
1905 | |
1906 class CMRemarkTask: public AbstractGangTask { | |
1907 private: | |
1908 ConcurrentMark *_cm; | |
1909 | |
1910 public: | |
1911 void work(int worker_i) { | |
1912 // Since all available tasks are actually started, we should | |
1913 // only proceed if we're supposed to be actived. | |
1914 if ((size_t)worker_i < _cm->active_tasks()) { | |
1915 CMTask* task = _cm->task(worker_i); | |
1916 task->record_start_time(); | |
1917 do { | |
1918 task->do_marking_step(1000000000.0 /* something very large */); | |
1919 } while (task->has_aborted() && !_cm->has_overflown()); | |
1920 // If we overflow, then we do not want to restart. We instead | |
1921 // want to abort remark and do concurrent marking again. | |
1922 task->record_end_time(); | |
1923 } | |
1924 } | |
1925 | |
1926 CMRemarkTask(ConcurrentMark* cm) : | |
1927 AbstractGangTask("Par Remark"), _cm(cm) { } | |
1928 }; | |
1929 | |
1930 void ConcurrentMark::checkpointRootsFinalWork() { | |
1931 ResourceMark rm; | |
1932 HandleMark hm; | |
1933 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1934 | |
1935 g1h->ensure_parsability(false); | |
1936 | |
1937 if (ParallelGCThreads > 0) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
1938 G1CollectedHeap::StrongRootsScope srs(g1h); |
342 | 1939 // this is remark, so we'll use up all available threads |
1940 int active_workers = ParallelGCThreads; | |
1941 set_phase(active_workers, false); | |
1942 | |
1943 CMRemarkTask remarkTask(this); | |
1944 // We will start all available threads, even if we decide that the | |
1945 // active_workers will be fewer. The extra ones will just bail out | |
1946 // immediately. | |
1947 int n_workers = g1h->workers()->total_workers(); | |
1948 g1h->set_par_threads(n_workers); | |
1949 g1h->workers()->run_task(&remarkTask); | |
1950 g1h->set_par_threads(0); | |
1951 } else { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
912
diff
changeset
|
1952 G1CollectedHeap::StrongRootsScope srs(g1h); |
342 | 1953 // this is remark, so we'll use up all available threads |
1954 int active_workers = 1; | |
1955 set_phase(active_workers, false); | |
1956 | |
1957 CMRemarkTask remarkTask(this); | |
1958 // We will start all available threads, even if we decide that the | |
1959 // active_workers will be fewer. The extra ones will just bail out | |
1960 // immediately. | |
1961 remarkTask.work(0); | |
1962 } | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1963 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
1964 guarantee(satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 1965 |
1966 print_stats(); | |
1967 | |
1968 if (!restart_for_overflow()) | |
1969 set_non_marking_state(); | |
1970 | |
1971 #if VERIFY_OBJS_PROCESSED | |
1972 if (_scan_obj_cl.objs_processed != ThreadLocalObjQueue::objs_enqueued) { | |
1973 gclog_or_tty->print_cr("Processed = %d, enqueued = %d.", | |
1974 _scan_obj_cl.objs_processed, | |
1975 ThreadLocalObjQueue::objs_enqueued); | |
1976 guarantee(_scan_obj_cl.objs_processed == | |
1977 ThreadLocalObjQueue::objs_enqueued, | |
1978 "Different number of objs processed and enqueued."); | |
1979 } | |
1980 #endif | |
1981 } | |
1982 | |
1044 | 1983 #ifndef PRODUCT |
1984 | |
1388 | 1985 class PrintReachableOopClosure: public OopClosure { |
342 | 1986 private: |
1987 G1CollectedHeap* _g1h; | |
1988 CMBitMapRO* _bitmap; | |
1989 outputStream* _out; | |
1044 | 1990 bool _use_prev_marking; |
1388 | 1991 bool _all; |
342 | 1992 |
1993 public: | |
1388 | 1994 PrintReachableOopClosure(CMBitMapRO* bitmap, |
1995 outputStream* out, | |
1996 bool use_prev_marking, | |
1997 bool all) : | |
1044 | 1998 _g1h(G1CollectedHeap::heap()), |
1388 | 1999 _bitmap(bitmap), _out(out), _use_prev_marking(use_prev_marking), _all(all) { } |
342 | 2000 |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2001 void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2002 void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2003 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2004 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2005 oop obj = oopDesc::load_decode_heap_oop(p); |
342 | 2006 const char* str = NULL; |
2007 const char* str2 = ""; | |
2008 | |
1388 | 2009 if (obj == NULL) { |
2010 str = ""; | |
2011 } else if (!_g1h->is_in_g1_reserved(obj)) { | |
2012 str = " O"; | |
2013 } else { | |
342 | 2014 HeapRegion* hr = _g1h->heap_region_containing(obj); |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2015 guarantee(hr != NULL, "invariant"); |
1044 | 2016 bool over_tams = false; |
2017 if (_use_prev_marking) { | |
2018 over_tams = hr->obj_allocated_since_prev_marking(obj); | |
2019 } else { | |
2020 over_tams = hr->obj_allocated_since_next_marking(obj); | |
2021 } | |
1388 | 2022 bool marked = _bitmap->isMarked((HeapWord*) obj); |
1044 | 2023 |
2024 if (over_tams) { | |
1388 | 2025 str = " >"; |
2026 if (marked) { | |
342 | 2027 str2 = " AND MARKED"; |
1044 | 2028 } |
1388 | 2029 } else if (marked) { |
2030 str = " M"; | |
1044 | 2031 } else { |
1388 | 2032 str = " NOT"; |
1044 | 2033 } |
342 | 2034 } |
2035 | |
1388 | 2036 _out->print_cr(" "PTR_FORMAT": "PTR_FORMAT"%s%s", |
342 | 2037 p, (void*) obj, str, str2); |
2038 } | |
2039 }; | |
2040 | |
1388 | 2041 class PrintReachableObjectClosure : public ObjectClosure { |
342 | 2042 private: |
1044 | 2043 CMBitMapRO* _bitmap; |
342 | 2044 outputStream* _out; |
1044 | 2045 bool _use_prev_marking; |
1388 | 2046 bool _all; |
2047 HeapRegion* _hr; | |
342 | 2048 |
2049 public: | |
1388 | 2050 PrintReachableObjectClosure(CMBitMapRO* bitmap, |
2051 outputStream* out, | |
2052 bool use_prev_marking, | |
2053 bool all, | |
2054 HeapRegion* hr) : | |
2055 _bitmap(bitmap), _out(out), | |
2056 _use_prev_marking(use_prev_marking), _all(all), _hr(hr) { } | |
2057 | |
2058 void do_object(oop o) { | |
2059 bool over_tams; | |
2060 if (_use_prev_marking) { | |
2061 over_tams = _hr->obj_allocated_since_prev_marking(o); | |
2062 } else { | |
2063 over_tams = _hr->obj_allocated_since_next_marking(o); | |
2064 } | |
2065 bool marked = _bitmap->isMarked((HeapWord*) o); | |
2066 bool print_it = _all || over_tams || marked; | |
2067 | |
2068 if (print_it) { | |
2069 _out->print_cr(" "PTR_FORMAT"%s", | |
2070 o, (over_tams) ? " >" : (marked) ? " M" : ""); | |
2071 PrintReachableOopClosure oopCl(_bitmap, _out, _use_prev_marking, _all); | |
2072 o->oop_iterate(&oopCl); | |
2073 } | |
342 | 2074 } |
2075 }; | |
2076 | |
1388 | 2077 class PrintReachableRegionClosure : public HeapRegionClosure { |
342 | 2078 private: |
1044 | 2079 CMBitMapRO* _bitmap; |
342 | 2080 outputStream* _out; |
1044 | 2081 bool _use_prev_marking; |
1388 | 2082 bool _all; |
342 | 2083 |
2084 public: | |
2085 bool doHeapRegion(HeapRegion* hr) { | |
2086 HeapWord* b = hr->bottom(); | |
2087 HeapWord* e = hr->end(); | |
2088 HeapWord* t = hr->top(); | |
1044 | 2089 HeapWord* p = NULL; |
2090 if (_use_prev_marking) { | |
2091 p = hr->prev_top_at_mark_start(); | |
2092 } else { | |
2093 p = hr->next_top_at_mark_start(); | |
2094 } | |
342 | 2095 _out->print_cr("** ["PTR_FORMAT", "PTR_FORMAT"] top: "PTR_FORMAT" " |
1044 | 2096 "TAMS: "PTR_FORMAT, b, e, t, p); |
1388 | 2097 _out->cr(); |
2098 | |
2099 HeapWord* from = b; | |
2100 HeapWord* to = t; | |
2101 | |
2102 if (to > from) { | |
2103 _out->print_cr("Objects in ["PTR_FORMAT", "PTR_FORMAT"]", from, to); | |
2104 _out->cr(); | |
2105 PrintReachableObjectClosure ocl(_bitmap, _out, | |
2106 _use_prev_marking, _all, hr); | |
2107 hr->object_iterate_mem_careful(MemRegion(from, to), &ocl); | |
2108 _out->cr(); | |
2109 } | |
342 | 2110 |
2111 return false; | |
2112 } | |
2113 | |
1388 | 2114 PrintReachableRegionClosure(CMBitMapRO* bitmap, |
2115 outputStream* out, | |
2116 bool use_prev_marking, | |
2117 bool all) : | |
2118 _bitmap(bitmap), _out(out), _use_prev_marking(use_prev_marking), _all(all) { } | |
342 | 2119 }; |
2120 | |
1388 | 2121 void ConcurrentMark::print_reachable(const char* str, |
2122 bool use_prev_marking, | |
2123 bool all) { | |
2124 gclog_or_tty->cr(); | |
2125 gclog_or_tty->print_cr("== Doing heap dump... "); | |
1044 | 2126 |
2127 if (G1PrintReachableBaseFile == NULL) { | |
2128 gclog_or_tty->print_cr(" #### error: no base file defined"); | |
2129 return; | |
2130 } | |
2131 | |
2132 if (strlen(G1PrintReachableBaseFile) + 1 + strlen(str) > | |
2133 (JVM_MAXPATHLEN - 1)) { | |
2134 gclog_or_tty->print_cr(" #### error: file name too long"); | |
2135 return; | |
2136 } | |
2137 | |
2138 char file_name[JVM_MAXPATHLEN]; | |
2139 sprintf(file_name, "%s.%s", G1PrintReachableBaseFile, str); | |
2140 gclog_or_tty->print_cr(" dumping to file %s", file_name); | |
2141 | |
2142 fileStream fout(file_name); | |
2143 if (!fout.is_open()) { | |
2144 gclog_or_tty->print_cr(" #### error: could not open file"); | |
2145 return; | |
2146 } | |
2147 | |
2148 outputStream* out = &fout; | |
2149 | |
2150 CMBitMapRO* bitmap = NULL; | |
2151 if (use_prev_marking) { | |
2152 bitmap = _prevMarkBitMap; | |
2153 } else { | |
2154 bitmap = _nextMarkBitMap; | |
2155 } | |
2156 | |
2157 out->print_cr("-- USING %s", (use_prev_marking) ? "PTAMS" : "NTAMS"); | |
2158 out->cr(); | |
2159 | |
1388 | 2160 out->print_cr("--- ITERATING OVER REGIONS"); |
1044 | 2161 out->cr(); |
1388 | 2162 PrintReachableRegionClosure rcl(bitmap, out, use_prev_marking, all); |
2163 _g1h->heap_region_iterate(&rcl); | |
1044 | 2164 out->cr(); |
2165 | |
2166 gclog_or_tty->print_cr(" done"); | |
1388 | 2167 gclog_or_tty->flush(); |
342 | 2168 } |
2169 | |
1044 | 2170 #endif // PRODUCT |
2171 | |
342 | 2172 // This note is for drainAllSATBBuffers and the code in between. |
2173 // In the future we could reuse a task to do this work during an | |
2174 // evacuation pause (since now tasks are not active and can be claimed | |
2175 // during an evacuation pause). This was a late change to the code and | |
2176 // is currently not being taken advantage of. | |
2177 | |
2178 class CMGlobalObjectClosure : public ObjectClosure { | |
2179 private: | |
2180 ConcurrentMark* _cm; | |
2181 | |
2182 public: | |
2183 void do_object(oop obj) { | |
2184 _cm->deal_with_reference(obj); | |
2185 } | |
2186 | |
2187 CMGlobalObjectClosure(ConcurrentMark* cm) : _cm(cm) { } | |
2188 }; | |
2189 | |
2190 void ConcurrentMark::deal_with_reference(oop obj) { | |
2191 if (verbose_high()) | |
2192 gclog_or_tty->print_cr("[global] we're dealing with reference "PTR_FORMAT, | |
2193 (void*) obj); | |
2194 | |
2195 | |
2196 HeapWord* objAddr = (HeapWord*) obj; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2197 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
342 | 2198 if (_g1h->is_in_g1_reserved(objAddr)) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2199 assert(obj != NULL, "is_in_g1_reserved should ensure this"); |
342 | 2200 HeapRegion* hr = _g1h->heap_region_containing(obj); |
2201 if (_g1h->is_obj_ill(obj, hr)) { | |
2202 if (verbose_high()) | |
2203 gclog_or_tty->print_cr("[global] "PTR_FORMAT" is not considered " | |
2204 "marked", (void*) obj); | |
2205 | |
2206 // we need to mark it first | |
2207 if (_nextMarkBitMap->parMark(objAddr)) { | |
2208 // No OrderAccess:store_load() is needed. It is implicit in the | |
2209 // CAS done in parMark(objAddr) above | |
2210 HeapWord* finger = _finger; | |
2211 if (objAddr < finger) { | |
2212 if (verbose_high()) | |
2213 gclog_or_tty->print_cr("[global] below the global finger " | |
2214 "("PTR_FORMAT"), pushing it", finger); | |
2215 if (!mark_stack_push(obj)) { | |
2216 if (verbose_low()) | |
2217 gclog_or_tty->print_cr("[global] global stack overflow during " | |
2218 "deal_with_reference"); | |
2219 } | |
2220 } | |
2221 } | |
2222 } | |
2223 } | |
2224 } | |
2225 | |
2226 void ConcurrentMark::drainAllSATBBuffers() { | |
2227 CMGlobalObjectClosure oc(this); | |
2228 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
2229 satb_mq_set.set_closure(&oc); | |
2230 | |
2231 while (satb_mq_set.apply_closure_to_completed_buffer()) { | |
2232 if (verbose_medium()) | |
2233 gclog_or_tty->print_cr("[global] processed an SATB buffer"); | |
2234 } | |
2235 | |
2236 // no need to check whether we should do this, as this is only | |
2237 // called during an evacuation pause | |
2238 satb_mq_set.iterate_closure_all_threads(); | |
2239 | |
2240 satb_mq_set.set_closure(NULL); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2241 assert(satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 2242 } |
2243 | |
2244 void ConcurrentMark::markPrev(oop p) { | |
2245 // Note we are overriding the read-only view of the prev map here, via | |
2246 // the cast. | |
2247 ((CMBitMap*)_prevMarkBitMap)->mark((HeapWord*)p); | |
2248 } | |
2249 | |
2250 void ConcurrentMark::clear(oop p) { | |
2251 assert(p != NULL && p->is_oop(), "expected an oop"); | |
2252 HeapWord* addr = (HeapWord*)p; | |
2253 assert(addr >= _nextMarkBitMap->startWord() || | |
2254 addr < _nextMarkBitMap->endWord(), "in a region"); | |
2255 | |
2256 _nextMarkBitMap->clear(addr); | |
2257 } | |
2258 | |
2259 void ConcurrentMark::clearRangeBothMaps(MemRegion mr) { | |
2260 // Note we are overriding the read-only view of the prev map here, via | |
2261 // the cast. | |
2262 ((CMBitMap*)_prevMarkBitMap)->clearRange(mr); | |
2263 _nextMarkBitMap->clearRange(mr); | |
2264 } | |
2265 | |
2266 HeapRegion* | |
2267 ConcurrentMark::claim_region(int task_num) { | |
2268 // "checkpoint" the finger | |
2269 HeapWord* finger = _finger; | |
2270 | |
2271 // _heap_end will not change underneath our feet; it only changes at | |
2272 // yield points. | |
2273 while (finger < _heap_end) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2274 assert(_g1h->is_in_g1_reserved(finger), "invariant"); |
342 | 2275 |
2276 // is the gap between reading the finger and doing the CAS too long? | |
2277 | |
2278 HeapRegion* curr_region = _g1h->heap_region_containing(finger); | |
2279 HeapWord* bottom = curr_region->bottom(); | |
2280 HeapWord* end = curr_region->end(); | |
2281 HeapWord* limit = curr_region->next_top_at_mark_start(); | |
2282 | |
2283 if (verbose_low()) | |
2284 gclog_or_tty->print_cr("[%d] curr_region = "PTR_FORMAT" " | |
2285 "["PTR_FORMAT", "PTR_FORMAT"), " | |
2286 "limit = "PTR_FORMAT, | |
2287 task_num, curr_region, bottom, end, limit); | |
2288 | |
2289 HeapWord* res = | |
2290 (HeapWord*) Atomic::cmpxchg_ptr(end, &_finger, finger); | |
2291 if (res == finger) { | |
2292 // we succeeded | |
2293 | |
2294 // notice that _finger == end cannot be guaranteed here since, | |
2295 // someone else might have moved the finger even further | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2296 assert(_finger >= end, "the finger should have moved forward"); |
342 | 2297 |
2298 if (verbose_low()) | |
2299 gclog_or_tty->print_cr("[%d] we were successful with region = " | |
2300 PTR_FORMAT, task_num, curr_region); | |
2301 | |
2302 if (limit > bottom) { | |
2303 if (verbose_low()) | |
2304 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is not empty, " | |
2305 "returning it ", task_num, curr_region); | |
2306 return curr_region; | |
2307 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2308 assert(limit == bottom, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2309 "the region limit should be at bottom"); |
342 | 2310 if (verbose_low()) |
2311 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is empty, " | |
2312 "returning NULL", task_num, curr_region); | |
2313 // we return NULL and the caller should try calling | |
2314 // claim_region() again. | |
2315 return NULL; | |
2316 } | |
2317 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2318 assert(_finger > finger, "the finger should have moved forward"); |
342 | 2319 if (verbose_low()) |
2320 gclog_or_tty->print_cr("[%d] somebody else moved the finger, " | |
2321 "global finger = "PTR_FORMAT", " | |
2322 "our finger = "PTR_FORMAT, | |
2323 task_num, _finger, finger); | |
2324 | |
2325 // read it again | |
2326 finger = _finger; | |
2327 } | |
2328 } | |
2329 | |
2330 return NULL; | |
2331 } | |
2332 | |
2333 void ConcurrentMark::oops_do(OopClosure* cl) { | |
2334 if (_markStack.size() > 0 && verbose_low()) | |
2335 gclog_or_tty->print_cr("[global] scanning the global marking stack, " | |
2336 "size = %d", _markStack.size()); | |
2337 // we first iterate over the contents of the mark stack... | |
2338 _markStack.oops_do(cl); | |
2339 | |
2340 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2341 OopTaskQueue* queue = _task_queues->queue((int)i); | |
2342 | |
2343 if (queue->size() > 0 && verbose_low()) | |
2344 gclog_or_tty->print_cr("[global] scanning task queue of task %d, " | |
2345 "size = %d", i, queue->size()); | |
2346 | |
2347 // ...then over the contents of the all the task queues. | |
2348 queue->oops_do(cl); | |
2349 } | |
2350 | |
2351 // finally, invalidate any entries that in the region stack that | |
2352 // point into the collection set | |
2353 if (_regionStack.invalidate_entries_into_cset()) { | |
2354 // otherwise, any gray objects copied during the evacuation pause | |
2355 // might not be visited. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2356 assert(_should_gray_objects, "invariant"); |
342 | 2357 } |
2358 } | |
2359 | |
2360 void ConcurrentMark::clear_marking_state() { | |
2361 _markStack.setEmpty(); | |
2362 _markStack.clear_overflow(); | |
2363 _regionStack.setEmpty(); | |
2364 _regionStack.clear_overflow(); | |
2365 clear_has_overflown(); | |
2366 _finger = _heap_start; | |
2367 | |
2368 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2369 OopTaskQueue* queue = _task_queues->queue(i); | |
2370 queue->set_empty(); | |
2371 } | |
2372 } | |
2373 | |
2374 void ConcurrentMark::print_stats() { | |
2375 if (verbose_stats()) { | |
2376 gclog_or_tty->print_cr("---------------------------------------------------------------------"); | |
2377 for (size_t i = 0; i < _active_tasks; ++i) { | |
2378 _tasks[i]->print_stats(); | |
2379 gclog_or_tty->print_cr("---------------------------------------------------------------------"); | |
2380 } | |
2381 } | |
2382 } | |
2383 | |
2384 class CSMarkOopClosure: public OopClosure { | |
2385 friend class CSMarkBitMapClosure; | |
2386 | |
2387 G1CollectedHeap* _g1h; | |
2388 CMBitMap* _bm; | |
2389 ConcurrentMark* _cm; | |
2390 oop* _ms; | |
2391 jint* _array_ind_stack; | |
2392 int _ms_size; | |
2393 int _ms_ind; | |
2394 int _array_increment; | |
2395 | |
2396 bool push(oop obj, int arr_ind = 0) { | |
2397 if (_ms_ind == _ms_size) { | |
2398 gclog_or_tty->print_cr("Mark stack is full."); | |
2399 return false; | |
2400 } | |
2401 _ms[_ms_ind] = obj; | |
2402 if (obj->is_objArray()) _array_ind_stack[_ms_ind] = arr_ind; | |
2403 _ms_ind++; | |
2404 return true; | |
2405 } | |
2406 | |
2407 oop pop() { | |
2408 if (_ms_ind == 0) return NULL; | |
2409 else { | |
2410 _ms_ind--; | |
2411 return _ms[_ms_ind]; | |
2412 } | |
2413 } | |
2414 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2415 template <class T> bool drain() { |
342 | 2416 while (_ms_ind > 0) { |
2417 oop obj = pop(); | |
2418 assert(obj != NULL, "Since index was non-zero."); | |
2419 if (obj->is_objArray()) { | |
2420 jint arr_ind = _array_ind_stack[_ms_ind]; | |
2421 objArrayOop aobj = objArrayOop(obj); | |
2422 jint len = aobj->length(); | |
2423 jint next_arr_ind = arr_ind + _array_increment; | |
2424 if (next_arr_ind < len) { | |
2425 push(obj, next_arr_ind); | |
2426 } | |
2427 // Now process this portion of this one. | |
2428 int lim = MIN2(next_arr_ind, len); | |
2429 for (int j = arr_ind; j < lim; j++) { | |
912
308762b2bf14
6872000: G1: compilation fails on linux/older gcc
apetrusenko
parents:
866
diff
changeset
|
2430 do_oop(aobj->objArrayOopDesc::obj_at_addr<T>(j)); |
342 | 2431 } |
2432 | |
2433 } else { | |
2434 obj->oop_iterate(this); | |
2435 } | |
2436 if (abort()) return false; | |
2437 } | |
2438 return true; | |
2439 } | |
2440 | |
2441 public: | |
2442 CSMarkOopClosure(ConcurrentMark* cm, int ms_size) : | |
2443 _g1h(G1CollectedHeap::heap()), | |
2444 _cm(cm), | |
2445 _bm(cm->nextMarkBitMap()), | |
2446 _ms_size(ms_size), _ms_ind(0), | |
2447 _ms(NEW_C_HEAP_ARRAY(oop, ms_size)), | |
2448 _array_ind_stack(NEW_C_HEAP_ARRAY(jint, ms_size)), | |
2449 _array_increment(MAX2(ms_size/8, 16)) | |
2450 {} | |
2451 | |
2452 ~CSMarkOopClosure() { | |
2453 FREE_C_HEAP_ARRAY(oop, _ms); | |
2454 FREE_C_HEAP_ARRAY(jint, _array_ind_stack); | |
2455 } | |
2456 | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2457 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2458 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2459 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2460 template <class T> void do_oop_work(T* p) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2461 T heap_oop = oopDesc::load_heap_oop(p); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2462 if (oopDesc::is_null(heap_oop)) return; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2463 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
342 | 2464 if (obj->is_forwarded()) { |
2465 // If the object has already been forwarded, we have to make sure | |
2466 // that it's marked. So follow the forwarding pointer. Note that | |
2467 // this does the right thing for self-forwarding pointers in the | |
2468 // evacuation failure case. | |
2469 obj = obj->forwardee(); | |
2470 } | |
2471 HeapRegion* hr = _g1h->heap_region_containing(obj); | |
2472 if (hr != NULL) { | |
2473 if (hr->in_collection_set()) { | |
2474 if (_g1h->is_obj_ill(obj)) { | |
2475 _bm->mark((HeapWord*)obj); | |
2476 if (!push(obj)) { | |
2477 gclog_or_tty->print_cr("Setting abort in CSMarkOopClosure because push failed."); | |
2478 set_abort(); | |
2479 } | |
2480 } | |
2481 } else { | |
2482 // Outside the collection set; we need to gray it | |
2483 _cm->deal_with_reference(obj); | |
2484 } | |
2485 } | |
2486 } | |
2487 }; | |
2488 | |
2489 class CSMarkBitMapClosure: public BitMapClosure { | |
2490 G1CollectedHeap* _g1h; | |
2491 CMBitMap* _bitMap; | |
2492 ConcurrentMark* _cm; | |
2493 CSMarkOopClosure _oop_cl; | |
2494 public: | |
2495 CSMarkBitMapClosure(ConcurrentMark* cm, int ms_size) : | |
2496 _g1h(G1CollectedHeap::heap()), | |
2497 _bitMap(cm->nextMarkBitMap()), | |
2498 _oop_cl(cm, ms_size) | |
2499 {} | |
2500 | |
2501 ~CSMarkBitMapClosure() {} | |
2502 | |
2503 bool do_bit(size_t offset) { | |
2504 // convert offset into a HeapWord* | |
2505 HeapWord* addr = _bitMap->offsetToHeapWord(offset); | |
2506 assert(_bitMap->endWord() && addr < _bitMap->endWord(), | |
2507 "address out of range"); | |
2508 assert(_bitMap->isMarked(addr), "tautology"); | |
2509 oop obj = oop(addr); | |
2510 if (!obj->is_forwarded()) { | |
2511 if (!_oop_cl.push(obj)) return false; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2512 if (UseCompressedOops) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2513 if (!_oop_cl.drain<narrowOop>()) return false; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2514 } else { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2515 if (!_oop_cl.drain<oop>()) return false; |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2516 } |
342 | 2517 } |
2518 // Otherwise... | |
2519 return true; | |
2520 } | |
2521 }; | |
2522 | |
2523 | |
2524 class CompleteMarkingInCSHRClosure: public HeapRegionClosure { | |
2525 CMBitMap* _bm; | |
2526 CSMarkBitMapClosure _bit_cl; | |
2527 enum SomePrivateConstants { | |
2528 MSSize = 1000 | |
2529 }; | |
2530 bool _completed; | |
2531 public: | |
2532 CompleteMarkingInCSHRClosure(ConcurrentMark* cm) : | |
2533 _bm(cm->nextMarkBitMap()), | |
2534 _bit_cl(cm, MSSize), | |
2535 _completed(true) | |
2536 {} | |
2537 | |
2538 ~CompleteMarkingInCSHRClosure() {} | |
2539 | |
2540 bool doHeapRegion(HeapRegion* r) { | |
2541 if (!r->evacuation_failed()) { | |
2542 MemRegion mr = MemRegion(r->bottom(), r->next_top_at_mark_start()); | |
2543 if (!mr.is_empty()) { | |
2544 if (!_bm->iterate(&_bit_cl, mr)) { | |
2545 _completed = false; | |
2546 return true; | |
2547 } | |
2548 } | |
2549 } | |
2550 return false; | |
2551 } | |
2552 | |
2553 bool completed() { return _completed; } | |
2554 }; | |
2555 | |
2556 class ClearMarksInHRClosure: public HeapRegionClosure { | |
2557 CMBitMap* _bm; | |
2558 public: | |
2559 ClearMarksInHRClosure(CMBitMap* bm): _bm(bm) { } | |
2560 | |
2561 bool doHeapRegion(HeapRegion* r) { | |
2562 if (!r->used_region().is_empty() && !r->evacuation_failed()) { | |
2563 MemRegion usedMR = r->used_region(); | |
2564 _bm->clearRange(r->used_region()); | |
2565 } | |
2566 return false; | |
2567 } | |
2568 }; | |
2569 | |
2570 void ConcurrentMark::complete_marking_in_collection_set() { | |
2571 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
2572 | |
2573 if (!g1h->mark_in_progress()) { | |
2574 g1h->g1_policy()->record_mark_closure_time(0.0); | |
2575 return; | |
2576 } | |
2577 | |
2578 int i = 1; | |
2579 double start = os::elapsedTime(); | |
2580 while (true) { | |
2581 i++; | |
2582 CompleteMarkingInCSHRClosure cmplt(this); | |
2583 g1h->collection_set_iterate(&cmplt); | |
2584 if (cmplt.completed()) break; | |
2585 } | |
2586 double end_time = os::elapsedTime(); | |
2587 double elapsed_time_ms = (end_time - start) * 1000.0; | |
2588 g1h->g1_policy()->record_mark_closure_time(elapsed_time_ms); | |
2589 | |
2590 ClearMarksInHRClosure clr(nextMarkBitMap()); | |
2591 g1h->collection_set_iterate(&clr); | |
2592 } | |
2593 | |
2594 // The next two methods deal with the following optimisation. Some | |
2595 // objects are gray by being marked and located above the finger. If | |
2596 // they are copied, during an evacuation pause, below the finger then | |
2597 // the need to be pushed on the stack. The observation is that, if | |
2598 // there are no regions in the collection set located above the | |
2599 // finger, then the above cannot happen, hence we do not need to | |
2600 // explicitly gray any objects when copying them to below the | |
2601 // finger. The global stack will be scanned to ensure that, if it | |
2602 // points to objects being copied, it will update their | |
2603 // location. There is a tricky situation with the gray objects in | |
2604 // region stack that are being coped, however. See the comment in | |
2605 // newCSet(). | |
2606 | |
2607 void ConcurrentMark::newCSet() { | |
2608 if (!concurrent_marking_in_progress()) | |
2609 // nothing to do if marking is not in progress | |
2610 return; | |
2611 | |
2612 // find what the lowest finger is among the global and local fingers | |
2613 _min_finger = _finger; | |
2614 for (int i = 0; i < (int)_max_task_num; ++i) { | |
2615 CMTask* task = _tasks[i]; | |
2616 HeapWord* task_finger = task->finger(); | |
2617 if (task_finger != NULL && task_finger < _min_finger) | |
2618 _min_finger = task_finger; | |
2619 } | |
2620 | |
2621 _should_gray_objects = false; | |
2622 | |
2623 // This fixes a very subtle and fustrating bug. It might be the case | |
2624 // that, during en evacuation pause, heap regions that contain | |
2625 // objects that are gray (by being in regions contained in the | |
2626 // region stack) are included in the collection set. Since such gray | |
2627 // objects will be moved, and because it's not easy to redirect | |
2628 // region stack entries to point to a new location (because objects | |
2629 // in one region might be scattered to multiple regions after they | |
2630 // are copied), one option is to ensure that all marked objects | |
2631 // copied during a pause are pushed on the stack. Notice, however, | |
2632 // that this problem can only happen when the region stack is not | |
2633 // empty during an evacuation pause. So, we make the fix a bit less | |
2634 // conservative and ensure that regions are pushed on the stack, | |
2635 // irrespective whether all collection set regions are below the | |
2636 // finger, if the region stack is not empty. This is expected to be | |
2637 // a rare case, so I don't think it's necessary to be smarted about it. | |
2638 if (!region_stack_empty()) | |
2639 _should_gray_objects = true; | |
2640 } | |
2641 | |
2642 void ConcurrentMark::registerCSetRegion(HeapRegion* hr) { | |
2643 if (!concurrent_marking_in_progress()) | |
2644 return; | |
2645 | |
2646 HeapWord* region_end = hr->end(); | |
2647 if (region_end > _min_finger) | |
2648 _should_gray_objects = true; | |
2649 } | |
2650 | |
2651 // abandon current marking iteration due to a Full GC | |
2652 void ConcurrentMark::abort() { | |
2653 // Clear all marks to force marking thread to do nothing | |
2654 _nextMarkBitMap->clearAll(); | |
2655 // Empty mark stack | |
2656 clear_marking_state(); | |
2657 for (int i = 0; i < (int)_max_task_num; ++i) | |
2658 _tasks[i]->clear_region_fields(); | |
2659 _has_aborted = true; | |
2660 | |
2661 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
2662 satb_mq_set.abandon_partial_marking(); | |
1317
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
2663 // This can be called either during or outside marking, we'll read |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
2664 // the expected_active value from the SATB queue set. |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
2665 satb_mq_set.set_active_all_threads( |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
2666 false, /* new active value */ |
d4197f8d516a
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
1314
diff
changeset
|
2667 satb_mq_set.is_active() /* expected_active */); |
342 | 2668 } |
2669 | |
2670 static void print_ms_time_info(const char* prefix, const char* name, | |
2671 NumberSeq& ns) { | |
2672 gclog_or_tty->print_cr("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).", | |
2673 prefix, ns.num(), name, ns.sum()/1000.0, ns.avg()); | |
2674 if (ns.num() > 0) { | |
2675 gclog_or_tty->print_cr("%s [std. dev = %8.2f ms, max = %8.2f ms]", | |
2676 prefix, ns.sd(), ns.maximum()); | |
2677 } | |
2678 } | |
2679 | |
2680 void ConcurrentMark::print_summary_info() { | |
2681 gclog_or_tty->print_cr(" Concurrent marking:"); | |
2682 print_ms_time_info(" ", "init marks", _init_times); | |
2683 print_ms_time_info(" ", "remarks", _remark_times); | |
2684 { | |
2685 print_ms_time_info(" ", "final marks", _remark_mark_times); | |
2686 print_ms_time_info(" ", "weak refs", _remark_weak_ref_times); | |
2687 | |
2688 } | |
2689 print_ms_time_info(" ", "cleanups", _cleanup_times); | |
2690 gclog_or_tty->print_cr(" Final counting total time = %8.2f s (avg = %8.2f ms).", | |
2691 _total_counting_time, | |
2692 (_cleanup_times.num() > 0 ? _total_counting_time * 1000.0 / | |
2693 (double)_cleanup_times.num() | |
2694 : 0.0)); | |
2695 if (G1ScrubRemSets) { | |
2696 gclog_or_tty->print_cr(" RS scrub total time = %8.2f s (avg = %8.2f ms).", | |
2697 _total_rs_scrub_time, | |
2698 (_cleanup_times.num() > 0 ? _total_rs_scrub_time * 1000.0 / | |
2699 (double)_cleanup_times.num() | |
2700 : 0.0)); | |
2701 } | |
2702 gclog_or_tty->print_cr(" Total stop_world time = %8.2f s.", | |
2703 (_init_times.sum() + _remark_times.sum() + | |
2704 _cleanup_times.sum())/1000.0); | |
2705 gclog_or_tty->print_cr(" Total concurrent time = %8.2f s " | |
2706 "(%8.2f s marking, %8.2f s counting).", | |
2707 cmThread()->vtime_accum(), | |
2708 cmThread()->vtime_mark_accum(), | |
2709 cmThread()->vtime_count_accum()); | |
2710 } | |
2711 | |
1019 | 2712 void ConcurrentMark::print_worker_threads_on(outputStream* st) const { |
2713 _parallel_workers->print_worker_threads_on(st); | |
2714 } | |
2715 | |
342 | 2716 // Closures |
2717 // XXX: there seems to be a lot of code duplication here; | |
2718 // should refactor and consolidate the shared code. | |
2719 | |
2720 // This closure is used to mark refs into the CMS generation in | |
2721 // the CMS bit map. Called at the first checkpoint. | |
2722 | |
2723 // We take a break if someone is trying to stop the world. | |
2724 bool ConcurrentMark::do_yield_check(int worker_i) { | |
2725 if (should_yield()) { | |
2726 if (worker_i == 0) | |
2727 _g1h->g1_policy()->record_concurrent_pause(); | |
2728 cmThread()->yield(); | |
2729 if (worker_i == 0) | |
2730 _g1h->g1_policy()->record_concurrent_pause_end(); | |
2731 return true; | |
2732 } else { | |
2733 return false; | |
2734 } | |
2735 } | |
2736 | |
2737 bool ConcurrentMark::should_yield() { | |
2738 return cmThread()->should_yield(); | |
2739 } | |
2740 | |
2741 bool ConcurrentMark::containing_card_is_marked(void* p) { | |
2742 size_t offset = pointer_delta(p, _g1h->reserved_region().start(), 1); | |
2743 return _card_bm.at(offset >> CardTableModRefBS::card_shift); | |
2744 } | |
2745 | |
2746 bool ConcurrentMark::containing_cards_are_marked(void* start, | |
2747 void* last) { | |
2748 return | |
2749 containing_card_is_marked(start) && | |
2750 containing_card_is_marked(last); | |
2751 } | |
2752 | |
2753 #ifndef PRODUCT | |
2754 // for debugging purposes | |
2755 void ConcurrentMark::print_finger() { | |
2756 gclog_or_tty->print_cr("heap ["PTR_FORMAT", "PTR_FORMAT"), global finger = "PTR_FORMAT, | |
2757 _heap_start, _heap_end, _finger); | |
2758 for (int i = 0; i < (int) _max_task_num; ++i) { | |
2759 gclog_or_tty->print(" %d: "PTR_FORMAT, i, _tasks[i]->finger()); | |
2760 } | |
2761 gclog_or_tty->print_cr(""); | |
2762 } | |
2763 #endif | |
2764 | |
2765 // Closure for iteration over bitmaps | |
2766 class CMBitMapClosure : public BitMapClosure { | |
2767 private: | |
2768 // the bitmap that is being iterated over | |
2769 CMBitMap* _nextMarkBitMap; | |
2770 ConcurrentMark* _cm; | |
2771 CMTask* _task; | |
2772 // true if we're scanning a heap region claimed by the task (so that | |
2773 // we move the finger along), false if we're not, i.e. currently when | |
2774 // scanning a heap region popped from the region stack (so that we | |
2775 // do not move the task finger along; it'd be a mistake if we did so). | |
2776 bool _scanning_heap_region; | |
2777 | |
2778 public: | |
2779 CMBitMapClosure(CMTask *task, | |
2780 ConcurrentMark* cm, | |
2781 CMBitMap* nextMarkBitMap) | |
2782 : _task(task), _cm(cm), _nextMarkBitMap(nextMarkBitMap) { } | |
2783 | |
2784 void set_scanning_heap_region(bool scanning_heap_region) { | |
2785 _scanning_heap_region = scanning_heap_region; | |
2786 } | |
2787 | |
2788 bool do_bit(size_t offset) { | |
2789 HeapWord* addr = _nextMarkBitMap->offsetToHeapWord(offset); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2790 assert(_nextMarkBitMap->isMarked(addr), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2791 assert( addr < _cm->finger(), "invariant"); |
342 | 2792 |
2793 if (_scanning_heap_region) { | |
2794 statsOnly( _task->increase_objs_found_on_bitmap() ); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2795 assert(addr >= _task->finger(), "invariant"); |
342 | 2796 // We move that task's local finger along. |
2797 _task->move_finger_to(addr); | |
2798 } else { | |
2799 // We move the task's region finger along. | |
2800 _task->move_region_finger_to(addr); | |
2801 } | |
2802 | |
2803 _task->scan_object(oop(addr)); | |
2804 // we only partially drain the local queue and global stack | |
2805 _task->drain_local_queue(true); | |
2806 _task->drain_global_stack(true); | |
2807 | |
2808 // if the has_aborted flag has been raised, we need to bail out of | |
2809 // the iteration | |
2810 return !_task->has_aborted(); | |
2811 } | |
2812 }; | |
2813 | |
2814 // Closure for iterating over objects, currently only used for | |
2815 // processing SATB buffers. | |
2816 class CMObjectClosure : public ObjectClosure { | |
2817 private: | |
2818 CMTask* _task; | |
2819 | |
2820 public: | |
2821 void do_object(oop obj) { | |
2822 _task->deal_with_reference(obj); | |
2823 } | |
2824 | |
2825 CMObjectClosure(CMTask* task) : _task(task) { } | |
2826 }; | |
2827 | |
2828 // Closure for iterating over object fields | |
2829 class CMOopClosure : public OopClosure { | |
2830 private: | |
2831 G1CollectedHeap* _g1h; | |
2832 ConcurrentMark* _cm; | |
2833 CMTask* _task; | |
2834 | |
2835 public: | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2836 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2837 virtual void do_oop( oop* p) { do_oop_work(p); } |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2838 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2839 template <class T> void do_oop_work(T* p) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2840 assert(_g1h->is_in_g1_reserved((HeapWord*) p), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2841 assert(!_g1h->heap_region_containing((HeapWord*) p)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2842 "invariant"); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2843 |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2844 oop obj = oopDesc::load_decode_heap_oop(p); |
342 | 2845 if (_cm->verbose_high()) |
2846 gclog_or_tty->print_cr("[%d] we're looking at location " | |
2847 "*"PTR_FORMAT" = "PTR_FORMAT, | |
2848 _task->task_id(), p, (void*) obj); | |
2849 _task->deal_with_reference(obj); | |
2850 } | |
2851 | |
2852 CMOopClosure(G1CollectedHeap* g1h, | |
2853 ConcurrentMark* cm, | |
2854 CMTask* task) | |
2855 : _g1h(g1h), _cm(cm), _task(task) { } | |
2856 }; | |
2857 | |
2858 void CMTask::setup_for_region(HeapRegion* hr) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2859 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2860 assert(hr != NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2861 "claim_region() should have filtered out continues humongous regions"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2862 assert(!hr->continuesHumongous(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2863 "claim_region() should have filtered out continues humongous regions"); |
342 | 2864 |
2865 if (_cm->verbose_low()) | |
2866 gclog_or_tty->print_cr("[%d] setting up for region "PTR_FORMAT, | |
2867 _task_id, hr); | |
2868 | |
2869 _curr_region = hr; | |
2870 _finger = hr->bottom(); | |
2871 update_region_limit(); | |
2872 } | |
2873 | |
2874 void CMTask::update_region_limit() { | |
2875 HeapRegion* hr = _curr_region; | |
2876 HeapWord* bottom = hr->bottom(); | |
2877 HeapWord* limit = hr->next_top_at_mark_start(); | |
2878 | |
2879 if (limit == bottom) { | |
2880 if (_cm->verbose_low()) | |
2881 gclog_or_tty->print_cr("[%d] found an empty region " | |
2882 "["PTR_FORMAT", "PTR_FORMAT")", | |
2883 _task_id, bottom, limit); | |
2884 // The region was collected underneath our feet. | |
2885 // We set the finger to bottom to ensure that the bitmap | |
2886 // iteration that will follow this will not do anything. | |
2887 // (this is not a condition that holds when we set the region up, | |
2888 // as the region is not supposed to be empty in the first place) | |
2889 _finger = bottom; | |
2890 } else if (limit >= _region_limit) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2891 assert(limit >= _finger, "peace of mind"); |
342 | 2892 } else { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2893 assert(limit < _region_limit, "only way to get here"); |
342 | 2894 // This can happen under some pretty unusual circumstances. An |
2895 // evacuation pause empties the region underneath our feet (NTAMS | |
2896 // at bottom). We then do some allocation in the region (NTAMS | |
2897 // stays at bottom), followed by the region being used as a GC | |
2898 // alloc region (NTAMS will move to top() and the objects | |
2899 // originally below it will be grayed). All objects now marked in | |
2900 // the region are explicitly grayed, if below the global finger, | |
2901 // and we do not need in fact to scan anything else. So, we simply | |
2902 // set _finger to be limit to ensure that the bitmap iteration | |
2903 // doesn't do anything. | |
2904 _finger = limit; | |
2905 } | |
2906 | |
2907 _region_limit = limit; | |
2908 } | |
2909 | |
2910 void CMTask::giveup_current_region() { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2911 assert(_curr_region != NULL, "invariant"); |
342 | 2912 if (_cm->verbose_low()) |
2913 gclog_or_tty->print_cr("[%d] giving up region "PTR_FORMAT, | |
2914 _task_id, _curr_region); | |
2915 clear_region_fields(); | |
2916 } | |
2917 | |
2918 void CMTask::clear_region_fields() { | |
2919 // Values for these three fields that indicate that we're not | |
2920 // holding on to a region. | |
2921 _curr_region = NULL; | |
2922 _finger = NULL; | |
2923 _region_limit = NULL; | |
2924 | |
2925 _region_finger = NULL; | |
2926 } | |
2927 | |
2928 void CMTask::reset(CMBitMap* nextMarkBitMap) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2929 guarantee(nextMarkBitMap != NULL, "invariant"); |
342 | 2930 |
2931 if (_cm->verbose_low()) | |
2932 gclog_or_tty->print_cr("[%d] resetting", _task_id); | |
2933 | |
2934 _nextMarkBitMap = nextMarkBitMap; | |
2935 clear_region_fields(); | |
2936 | |
2937 _calls = 0; | |
2938 _elapsed_time_ms = 0.0; | |
2939 _termination_time_ms = 0.0; | |
2940 _termination_start_time_ms = 0.0; | |
2941 | |
2942 #if _MARKING_STATS_ | |
2943 _local_pushes = 0; | |
2944 _local_pops = 0; | |
2945 _local_max_size = 0; | |
2946 _objs_scanned = 0; | |
2947 _global_pushes = 0; | |
2948 _global_pops = 0; | |
2949 _global_max_size = 0; | |
2950 _global_transfers_to = 0; | |
2951 _global_transfers_from = 0; | |
2952 _region_stack_pops = 0; | |
2953 _regions_claimed = 0; | |
2954 _objs_found_on_bitmap = 0; | |
2955 _satb_buffers_processed = 0; | |
2956 _steal_attempts = 0; | |
2957 _steals = 0; | |
2958 _aborted = 0; | |
2959 _aborted_overflow = 0; | |
2960 _aborted_cm_aborted = 0; | |
2961 _aborted_yield = 0; | |
2962 _aborted_timed_out = 0; | |
2963 _aborted_satb = 0; | |
2964 _aborted_termination = 0; | |
2965 #endif // _MARKING_STATS_ | |
2966 } | |
2967 | |
2968 bool CMTask::should_exit_termination() { | |
2969 regular_clock_call(); | |
2970 // This is called when we are in the termination protocol. We should | |
2971 // quit if, for some reason, this task wants to abort or the global | |
2972 // stack is not empty (this means that we can get work from it). | |
2973 return !_cm->mark_stack_empty() || has_aborted(); | |
2974 } | |
2975 | |
2976 // This determines whether the method below will check both the local | |
2977 // and global fingers when determining whether to push on the stack a | |
2978 // gray object (value 1) or whether it will only check the global one | |
2979 // (value 0). The tradeoffs are that the former will be a bit more | |
2980 // accurate and possibly push less on the stack, but it might also be | |
2981 // a little bit slower. | |
2982 | |
2983 #define _CHECK_BOTH_FINGERS_ 1 | |
2984 | |
2985 void CMTask::deal_with_reference(oop obj) { | |
2986 if (_cm->verbose_high()) | |
2987 gclog_or_tty->print_cr("[%d] we're dealing with reference = "PTR_FORMAT, | |
2988 _task_id, (void*) obj); | |
2989 | |
2990 ++_refs_reached; | |
2991 | |
2992 HeapWord* objAddr = (HeapWord*) obj; | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
831
diff
changeset
|
2993 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
342 | 2994 if (_g1h->is_in_g1_reserved(objAddr)) { |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
2995 assert(obj != NULL, "is_in_g1_reserved should ensure this"); |
342 | 2996 HeapRegion* hr = _g1h->heap_region_containing(obj); |
2997 if (_g1h->is_obj_ill(obj, hr)) { | |
2998 if (_cm->verbose_high()) | |
2999 gclog_or_tty->print_cr("[%d] "PTR_FORMAT" is not considered marked", | |
3000 _task_id, (void*) obj); | |
3001 | |
3002 // we need to mark it first | |
3003 if (_nextMarkBitMap->parMark(objAddr)) { | |
3004 // No OrderAccess:store_load() is needed. It is implicit in the | |
3005 // CAS done in parMark(objAddr) above | |
3006 HeapWord* global_finger = _cm->finger(); | |
3007 | |
3008 #if _CHECK_BOTH_FINGERS_ | |
3009 // we will check both the local and global fingers | |
3010 | |
3011 if (_finger != NULL && objAddr < _finger) { | |
3012 if (_cm->verbose_high()) | |
3013 gclog_or_tty->print_cr("[%d] below the local finger ("PTR_FORMAT"), " | |
3014 "pushing it", _task_id, _finger); | |
3015 push(obj); | |
3016 } else if (_curr_region != NULL && objAddr < _region_limit) { | |
3017 // do nothing | |
3018 } else if (objAddr < global_finger) { | |
3019 // Notice that the global finger might be moving forward | |
3020 // concurrently. This is not a problem. In the worst case, we | |
3021 // mark the object while it is above the global finger and, by | |
3022 // the time we read the global finger, it has moved forward | |
3023 // passed this object. In this case, the object will probably | |
3024 // be visited when a task is scanning the region and will also | |
3025 // be pushed on the stack. So, some duplicate work, but no | |
3026 // correctness problems. | |
3027 | |
3028 if (_cm->verbose_high()) | |
3029 gclog_or_tty->print_cr("[%d] below the global finger " | |
3030 "("PTR_FORMAT"), pushing it", | |
3031 _task_id, global_finger); | |
3032 push(obj); | |
3033 } else { | |
3034 // do nothing | |
3035 } | |
3036 #else // _CHECK_BOTH_FINGERS_ | |
3037 // we will only check the global finger | |
3038 | |
3039 if (objAddr < global_finger) { | |
3040 // see long comment above | |
3041 | |
3042 if (_cm->verbose_high()) | |
3043 gclog_or_tty->print_cr("[%d] below the global finger " | |
3044 "("PTR_FORMAT"), pushing it", | |
3045 _task_id, global_finger); | |
3046 push(obj); | |
3047 } | |
3048 #endif // _CHECK_BOTH_FINGERS_ | |
3049 } | |
3050 } | |
3051 } | |
3052 } | |
3053 | |
3054 void CMTask::push(oop obj) { | |
3055 HeapWord* objAddr = (HeapWord*) obj; | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3056 assert(_g1h->is_in_g1_reserved(objAddr), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3057 assert(!_g1h->heap_region_containing(objAddr)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3058 "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3059 assert(!_g1h->is_obj_ill(obj), "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3060 assert(_nextMarkBitMap->isMarked(objAddr), "invariant"); |
342 | 3061 |
3062 if (_cm->verbose_high()) | |
3063 gclog_or_tty->print_cr("[%d] pushing "PTR_FORMAT, _task_id, (void*) obj); | |
3064 | |
3065 if (!_task_queue->push(obj)) { | |
3066 // The local task queue looks full. We need to push some entries | |
3067 // to the global stack. | |
3068 | |
3069 if (_cm->verbose_medium()) | |
3070 gclog_or_tty->print_cr("[%d] task queue overflow, " | |
3071 "moving entries to the global stack", | |
3072 _task_id); | |
3073 move_entries_to_global_stack(); | |
3074 | |
3075 // this should succeed since, even if we overflow the global | |
3076 // stack, we should have definitely removed some entries from the | |
3077 // local queue. So, there must be space on it. | |
3078 bool success = _task_queue->push(obj); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3079 assert(success, "invariant"); |
342 | 3080 } |
3081 | |
3082 statsOnly( int tmp_size = _task_queue->size(); | |
3083 if (tmp_size > _local_max_size) | |
3084 _local_max_size = tmp_size; | |
3085 ++_local_pushes ); | |
3086 } | |
3087 | |
3088 void CMTask::reached_limit() { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3089 assert(_words_scanned >= _words_scanned_limit || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3090 _refs_reached >= _refs_reached_limit , |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3091 "shouldn't have been called otherwise"); |
342 | 3092 regular_clock_call(); |
3093 } | |
3094 | |
3095 void CMTask::regular_clock_call() { | |
3096 if (has_aborted()) | |
3097 return; | |
3098 | |
3099 // First, we need to recalculate the words scanned and refs reached | |
3100 // limits for the next clock call. | |
3101 recalculate_limits(); | |
3102 | |
3103 // During the regular clock call we do the following | |
3104 | |
3105 // (1) If an overflow has been flagged, then we abort. | |
3106 if (_cm->has_overflown()) { | |
3107 set_has_aborted(); | |
3108 return; | |
3109 } | |
3110 | |
3111 // If we are not concurrent (i.e. we're doing remark) we don't need | |
3112 // to check anything else. The other steps are only needed during | |
3113 // the concurrent marking phase. | |
3114 if (!concurrent()) | |
3115 return; | |
3116 | |
3117 // (2) If marking has been aborted for Full GC, then we also abort. | |
3118 if (_cm->has_aborted()) { | |
3119 set_has_aborted(); | |
3120 statsOnly( ++_aborted_cm_aborted ); | |
3121 return; | |
3122 } | |
3123 | |
3124 double curr_time_ms = os::elapsedVTime() * 1000.0; | |
3125 | |
3126 // (3) If marking stats are enabled, then we update the step history. | |
3127 #if _MARKING_STATS_ | |
3128 if (_words_scanned >= _words_scanned_limit) | |
3129 ++_clock_due_to_scanning; | |
3130 if (_refs_reached >= _refs_reached_limit) | |
3131 ++_clock_due_to_marking; | |
3132 | |
3133 double last_interval_ms = curr_time_ms - _interval_start_time_ms; | |
3134 _interval_start_time_ms = curr_time_ms; | |
3135 _all_clock_intervals_ms.add(last_interval_ms); | |
3136 | |
3137 if (_cm->verbose_medium()) { | |
3138 gclog_or_tty->print_cr("[%d] regular clock, interval = %1.2lfms, " | |
3139 "scanned = %d%s, refs reached = %d%s", | |
3140 _task_id, last_interval_ms, | |
3141 _words_scanned, | |
3142 (_words_scanned >= _words_scanned_limit) ? " (*)" : "", | |
3143 _refs_reached, | |
3144 (_refs_reached >= _refs_reached_limit) ? " (*)" : ""); | |
3145 } | |
3146 #endif // _MARKING_STATS_ | |
3147 | |
3148 // (4) We check whether we should yield. If we have to, then we abort. | |
3149 if (_cm->should_yield()) { | |
3150 // We should yield. To do this we abort the task. The caller is | |
3151 // responsible for yielding. | |
3152 set_has_aborted(); | |
3153 statsOnly( ++_aborted_yield ); | |
3154 return; | |
3155 } | |
3156 | |
3157 // (5) We check whether we've reached our time quota. If we have, | |
3158 // then we abort. | |
3159 double elapsed_time_ms = curr_time_ms - _start_time_ms; | |
3160 if (elapsed_time_ms > _time_target_ms) { | |
3161 set_has_aborted(); | |
3162 _has_aborted_timed_out = true; | |
3163 statsOnly( ++_aborted_timed_out ); | |
3164 return; | |
3165 } | |
3166 | |
3167 // (6) Finally, we check whether there are enough completed STAB | |
3168 // buffers available for processing. If there are, we abort. | |
3169 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
3170 if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) { | |
3171 if (_cm->verbose_low()) | |
3172 gclog_or_tty->print_cr("[%d] aborting to deal with pending SATB buffers", | |
3173 _task_id); | |
3174 // we do need to process SATB buffers, we'll abort and restart | |
3175 // the marking task to do so | |
3176 set_has_aborted(); | |
3177 statsOnly( ++_aborted_satb ); | |
3178 return; | |
3179 } | |
3180 } | |
3181 | |
3182 void CMTask::recalculate_limits() { | |
3183 _real_words_scanned_limit = _words_scanned + words_scanned_period; | |
3184 _words_scanned_limit = _real_words_scanned_limit; | |
3185 | |
3186 _real_refs_reached_limit = _refs_reached + refs_reached_period; | |
3187 _refs_reached_limit = _real_refs_reached_limit; | |
3188 } | |
3189 | |
3190 void CMTask::decrease_limits() { | |
3191 // This is called when we believe that we're going to do an infrequent | |
3192 // operation which will increase the per byte scanned cost (i.e. move | |
3193 // entries to/from the global stack). It basically tries to decrease the | |
3194 // scanning limit so that the clock is called earlier. | |
3195 | |
3196 if (_cm->verbose_medium()) | |
3197 gclog_or_tty->print_cr("[%d] decreasing limits", _task_id); | |
3198 | |
3199 _words_scanned_limit = _real_words_scanned_limit - | |
3200 3 * words_scanned_period / 4; | |
3201 _refs_reached_limit = _real_refs_reached_limit - | |
3202 3 * refs_reached_period / 4; | |
3203 } | |
3204 | |
3205 void CMTask::move_entries_to_global_stack() { | |
3206 // local array where we'll store the entries that will be popped | |
3207 // from the local queue | |
3208 oop buffer[global_stack_transfer_size]; | |
3209 | |
3210 int n = 0; | |
3211 oop obj; | |
3212 while (n < global_stack_transfer_size && _task_queue->pop_local(obj)) { | |
3213 buffer[n] = obj; | |
3214 ++n; | |
3215 } | |
3216 | |
3217 if (n > 0) { | |
3218 // we popped at least one entry from the local queue | |
3219 | |
3220 statsOnly( ++_global_transfers_to; _local_pops += n ); | |
3221 | |
3222 if (!_cm->mark_stack_push(buffer, n)) { | |
3223 if (_cm->verbose_low()) | |
3224 gclog_or_tty->print_cr("[%d] aborting due to global stack overflow", _task_id); | |
3225 set_has_aborted(); | |
3226 } else { | |
3227 // the transfer was successful | |
3228 | |
3229 if (_cm->verbose_medium()) | |
3230 gclog_or_tty->print_cr("[%d] pushed %d entries to the global stack", | |
3231 _task_id, n); | |
3232 statsOnly( int tmp_size = _cm->mark_stack_size(); | |
3233 if (tmp_size > _global_max_size) | |
3234 _global_max_size = tmp_size; | |
3235 _global_pushes += n ); | |
3236 } | |
3237 } | |
3238 | |
3239 // this operation was quite expensive, so decrease the limits | |
3240 decrease_limits(); | |
3241 } | |
3242 | |
3243 void CMTask::get_entries_from_global_stack() { | |
3244 // local array where we'll store the entries that will be popped | |
3245 // from the global stack. | |
3246 oop buffer[global_stack_transfer_size]; | |
3247 int n; | |
3248 _cm->mark_stack_pop(buffer, global_stack_transfer_size, &n); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3249 assert(n <= global_stack_transfer_size, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3250 "we should not pop more than the given limit"); |
342 | 3251 if (n > 0) { |
3252 // yes, we did actually pop at least one entry | |
3253 | |
3254 statsOnly( ++_global_transfers_from; _global_pops += n ); | |
3255 if (_cm->verbose_medium()) | |
3256 gclog_or_tty->print_cr("[%d] popped %d entries from the global stack", | |
3257 _task_id, n); | |
3258 for (int i = 0; i < n; ++i) { | |
3259 bool success = _task_queue->push(buffer[i]); | |
3260 // We only call this when the local queue is empty or under a | |
3261 // given target limit. So, we do not expect this push to fail. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3262 assert(success, "invariant"); |
342 | 3263 } |
3264 | |
3265 statsOnly( int tmp_size = _task_queue->size(); | |
3266 if (tmp_size > _local_max_size) | |
3267 _local_max_size = tmp_size; | |
3268 _local_pushes += n ); | |
3269 } | |
3270 | |
3271 // this operation was quite expensive, so decrease the limits | |
3272 decrease_limits(); | |
3273 } | |
3274 | |
3275 void CMTask::drain_local_queue(bool partially) { | |
3276 if (has_aborted()) | |
3277 return; | |
3278 | |
3279 // Decide what the target size is, depending whether we're going to | |
3280 // drain it partially (so that other tasks can steal if they run out | |
3281 // of things to do) or totally (at the very end). | |
3282 size_t target_size; | |
3283 if (partially) | |
3284 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize); | |
3285 else | |
3286 target_size = 0; | |
3287 | |
3288 if (_task_queue->size() > target_size) { | |
3289 if (_cm->verbose_high()) | |
3290 gclog_or_tty->print_cr("[%d] draining local queue, target size = %d", | |
3291 _task_id, target_size); | |
3292 | |
3293 oop obj; | |
3294 bool ret = _task_queue->pop_local(obj); | |
3295 while (ret) { | |
3296 statsOnly( ++_local_pops ); | |
3297 | |
3298 if (_cm->verbose_high()) | |
3299 gclog_or_tty->print_cr("[%d] popped "PTR_FORMAT, _task_id, | |
3300 (void*) obj); | |
3301 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3302 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" ); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3303 assert(!_g1h->heap_region_containing(obj)->is_on_free_list(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3304 "invariant"); |
342 | 3305 |
3306 scan_object(obj); | |
3307 | |
3308 if (_task_queue->size() <= target_size || has_aborted()) | |
3309 ret = false; | |
3310 else | |
3311 ret = _task_queue->pop_local(obj); | |
3312 } | |
3313 | |
3314 if (_cm->verbose_high()) | |
3315 gclog_or_tty->print_cr("[%d] drained local queue, size = %d", | |
3316 _task_id, _task_queue->size()); | |
3317 } | |
3318 } | |
3319 | |
3320 void CMTask::drain_global_stack(bool partially) { | |
3321 if (has_aborted()) | |
3322 return; | |
3323 | |
3324 // We have a policy to drain the local queue before we attempt to | |
3325 // drain the global stack. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3326 assert(partially || _task_queue->size() == 0, "invariant"); |
342 | 3327 |
3328 // Decide what the target size is, depending whether we're going to | |
3329 // drain it partially (so that other tasks can steal if they run out | |
3330 // of things to do) or totally (at the very end). Notice that, | |
3331 // because we move entries from the global stack in chunks or | |
3332 // because another task might be doing the same, we might in fact | |
3333 // drop below the target. But, this is not a problem. | |
3334 size_t target_size; | |
3335 if (partially) | |
3336 target_size = _cm->partial_mark_stack_size_target(); | |
3337 else | |
3338 target_size = 0; | |
3339 | |
3340 if (_cm->mark_stack_size() > target_size) { | |
3341 if (_cm->verbose_low()) | |
3342 gclog_or_tty->print_cr("[%d] draining global_stack, target size %d", | |
3343 _task_id, target_size); | |
3344 | |
3345 while (!has_aborted() && _cm->mark_stack_size() > target_size) { | |
3346 get_entries_from_global_stack(); | |
3347 drain_local_queue(partially); | |
3348 } | |
3349 | |
3350 if (_cm->verbose_low()) | |
3351 gclog_or_tty->print_cr("[%d] drained global stack, size = %d", | |
3352 _task_id, _cm->mark_stack_size()); | |
3353 } | |
3354 } | |
3355 | |
3356 // SATB Queue has several assumptions on whether to call the par or | |
3357 // non-par versions of the methods. this is why some of the code is | |
3358 // replicated. We should really get rid of the single-threaded version | |
3359 // of the code to simplify things. | |
3360 void CMTask::drain_satb_buffers() { | |
3361 if (has_aborted()) | |
3362 return; | |
3363 | |
3364 // We set this so that the regular clock knows that we're in the | |
3365 // middle of draining buffers and doesn't set the abort flag when it | |
3366 // notices that SATB buffers are available for draining. It'd be | |
3367 // very counter productive if it did that. :-) | |
3368 _draining_satb_buffers = true; | |
3369 | |
3370 CMObjectClosure oc(this); | |
3371 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | |
3372 if (ParallelGCThreads > 0) | |
3373 satb_mq_set.set_par_closure(_task_id, &oc); | |
3374 else | |
3375 satb_mq_set.set_closure(&oc); | |
3376 | |
3377 // This keeps claiming and applying the closure to completed buffers | |
3378 // until we run out of buffers or we need to abort. | |
3379 if (ParallelGCThreads > 0) { | |
3380 while (!has_aborted() && | |
3381 satb_mq_set.par_apply_closure_to_completed_buffer(_task_id)) { | |
3382 if (_cm->verbose_medium()) | |
3383 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | |
3384 statsOnly( ++_satb_buffers_processed ); | |
3385 regular_clock_call(); | |
3386 } | |
3387 } else { | |
3388 while (!has_aborted() && | |
3389 satb_mq_set.apply_closure_to_completed_buffer()) { | |
3390 if (_cm->verbose_medium()) | |
3391 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | |
3392 statsOnly( ++_satb_buffers_processed ); | |
3393 regular_clock_call(); | |
3394 } | |
3395 } | |
3396 | |
3397 if (!concurrent() && !has_aborted()) { | |
3398 // We should only do this during remark. | |
3399 if (ParallelGCThreads > 0) | |
3400 satb_mq_set.par_iterate_closure_all_threads(_task_id); | |
3401 else | |
3402 satb_mq_set.iterate_closure_all_threads(); | |
3403 } | |
3404 | |
3405 _draining_satb_buffers = false; | |
3406 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3407 assert(has_aborted() || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3408 concurrent() || |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3409 satb_mq_set.completed_buffers_num() == 0, "invariant"); |
342 | 3410 |
3411 if (ParallelGCThreads > 0) | |
3412 satb_mq_set.set_par_closure(_task_id, NULL); | |
3413 else | |
3414 satb_mq_set.set_closure(NULL); | |
3415 | |
3416 // again, this was a potentially expensive operation, decrease the | |
3417 // limits to get the regular clock call early | |
3418 decrease_limits(); | |
3419 } | |
3420 | |
3421 void CMTask::drain_region_stack(BitMapClosure* bc) { | |
3422 if (has_aborted()) | |
3423 return; | |
3424 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3425 assert(_region_finger == NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3426 "it should be NULL when we're not scanning a region"); |
342 | 3427 |
3428 if (!_cm->region_stack_empty()) { | |
3429 if (_cm->verbose_low()) | |
3430 gclog_or_tty->print_cr("[%d] draining region stack, size = %d", | |
3431 _task_id, _cm->region_stack_size()); | |
3432 | |
1358
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
3433 MemRegion mr = _cm->region_stack_pop_with_lock(); |
342 | 3434 // it returns MemRegion() if the pop fails |
3435 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | |
3436 | |
3437 while (mr.start() != NULL) { | |
3438 if (_cm->verbose_medium()) | |
3439 gclog_or_tty->print_cr("[%d] we are scanning region " | |
3440 "["PTR_FORMAT", "PTR_FORMAT")", | |
3441 _task_id, mr.start(), mr.end()); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3442 assert(mr.end() <= _cm->finger(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3443 "otherwise the region shouldn't be on the stack"); |
342 | 3444 assert(!mr.is_empty(), "Only non-empty regions live on the region stack"); |
3445 if (_nextMarkBitMap->iterate(bc, mr)) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3446 assert(!has_aborted(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3447 "cannot abort the task without aborting the bitmap iteration"); |
342 | 3448 |
3449 // We finished iterating over the region without aborting. | |
3450 regular_clock_call(); | |
3451 if (has_aborted()) | |
3452 mr = MemRegion(); | |
3453 else { | |
1358
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
3454 mr = _cm->region_stack_pop_with_lock(); |
342 | 3455 // it returns MemRegion() if the pop fails |
3456 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | |
3457 } | |
3458 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3459 assert(has_aborted(), "currently the only way to do so"); |
342 | 3460 |
3461 // The only way to abort the bitmap iteration is to return | |
3462 // false from the do_bit() method. However, inside the | |
3463 // do_bit() method we move the _region_finger to point to the | |
3464 // object currently being looked at. So, if we bail out, we | |
3465 // have definitely set _region_finger to something non-null. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3466 assert(_region_finger != NULL, "invariant"); |
342 | 3467 |
3468 // The iteration was actually aborted. So now _region_finger | |
3469 // points to the address of the object we last scanned. If we | |
3470 // leave it there, when we restart this task, we will rescan | |
3471 // the object. It is easy to avoid this. We move the finger by | |
3472 // enough to point to the next possible object header (the | |
3473 // bitmap knows by how much we need to move it as it knows its | |
3474 // granularity). | |
3475 MemRegion newRegion = | |
3476 MemRegion(_nextMarkBitMap->nextWord(_region_finger), mr.end()); | |
3477 | |
3478 if (!newRegion.is_empty()) { | |
3479 if (_cm->verbose_low()) { | |
3480 gclog_or_tty->print_cr("[%d] pushing unscanned region" | |
3481 "[" PTR_FORMAT "," PTR_FORMAT ") on region stack", | |
3482 _task_id, | |
3483 newRegion.start(), newRegion.end()); | |
3484 } | |
3485 // Now push the part of the region we didn't scan on the | |
3486 // region stack to make sure a task scans it later. | |
1358
72f725c5a7be
6940310: G1: MT-unsafe calls to CM::region_stack_push() / CM::region_stack_pop()
tonyp
parents:
1317
diff
changeset
|
3487 _cm->region_stack_push_with_lock(newRegion); |
342 | 3488 } |
3489 // break from while | |
3490 mr = MemRegion(); | |
3491 } | |
3492 _region_finger = NULL; | |
3493 } | |
3494 | |
3495 if (_cm->verbose_low()) | |
3496 gclog_or_tty->print_cr("[%d] drained region stack, size = %d", | |
3497 _task_id, _cm->region_stack_size()); | |
3498 } | |
3499 } | |
3500 | |
3501 void CMTask::print_stats() { | |
3502 gclog_or_tty->print_cr("Marking Stats, task = %d, calls = %d", | |
3503 _task_id, _calls); | |
3504 gclog_or_tty->print_cr(" Elapsed time = %1.2lfms, Termination time = %1.2lfms", | |
3505 _elapsed_time_ms, _termination_time_ms); | |
3506 gclog_or_tty->print_cr(" Step Times (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms", | |
3507 _step_times_ms.num(), _step_times_ms.avg(), | |
3508 _step_times_ms.sd()); | |
3509 gclog_or_tty->print_cr(" max = %1.2lfms, total = %1.2lfms", | |
3510 _step_times_ms.maximum(), _step_times_ms.sum()); | |
3511 | |
3512 #if _MARKING_STATS_ | |
3513 gclog_or_tty->print_cr(" Clock Intervals (cum): num = %d, avg = %1.2lfms, sd = %1.2lfms", | |
3514 _all_clock_intervals_ms.num(), _all_clock_intervals_ms.avg(), | |
3515 _all_clock_intervals_ms.sd()); | |
3516 gclog_or_tty->print_cr(" max = %1.2lfms, total = %1.2lfms", | |
3517 _all_clock_intervals_ms.maximum(), | |
3518 _all_clock_intervals_ms.sum()); | |
3519 gclog_or_tty->print_cr(" Clock Causes (cum): scanning = %d, marking = %d", | |
3520 _clock_due_to_scanning, _clock_due_to_marking); | |
3521 gclog_or_tty->print_cr(" Objects: scanned = %d, found on the bitmap = %d", | |
3522 _objs_scanned, _objs_found_on_bitmap); | |
3523 gclog_or_tty->print_cr(" Local Queue: pushes = %d, pops = %d, max size = %d", | |
3524 _local_pushes, _local_pops, _local_max_size); | |
3525 gclog_or_tty->print_cr(" Global Stack: pushes = %d, pops = %d, max size = %d", | |
3526 _global_pushes, _global_pops, _global_max_size); | |
3527 gclog_or_tty->print_cr(" transfers to = %d, transfers from = %d", | |
3528 _global_transfers_to,_global_transfers_from); | |
3529 gclog_or_tty->print_cr(" Regions: claimed = %d, Region Stack: pops = %d", | |
3530 _regions_claimed, _region_stack_pops); | |
3531 gclog_or_tty->print_cr(" SATB buffers: processed = %d", _satb_buffers_processed); | |
3532 gclog_or_tty->print_cr(" Steals: attempts = %d, successes = %d", | |
3533 _steal_attempts, _steals); | |
3534 gclog_or_tty->print_cr(" Aborted: %d, due to", _aborted); | |
3535 gclog_or_tty->print_cr(" overflow: %d, global abort: %d, yield: %d", | |
3536 _aborted_overflow, _aborted_cm_aborted, _aborted_yield); | |
3537 gclog_or_tty->print_cr(" time out: %d, SATB: %d, termination: %d", | |
3538 _aborted_timed_out, _aborted_satb, _aborted_termination); | |
3539 #endif // _MARKING_STATS_ | |
3540 } | |
3541 | |
3542 /***************************************************************************** | |
3543 | |
3544 The do_marking_step(time_target_ms) method is the building block | |
3545 of the parallel marking framework. It can be called in parallel | |
3546 with other invocations of do_marking_step() on different tasks | |
3547 (but only one per task, obviously) and concurrently with the | |
3548 mutator threads, or during remark, hence it eliminates the need | |
3549 for two versions of the code. When called during remark, it will | |
3550 pick up from where the task left off during the concurrent marking | |
3551 phase. Interestingly, tasks are also claimable during evacuation | |
3552 pauses too, since do_marking_step() ensures that it aborts before | |
3553 it needs to yield. | |
3554 | |
3555 The data structures that is uses to do marking work are the | |
3556 following: | |
3557 | |
3558 (1) Marking Bitmap. If there are gray objects that appear only | |
3559 on the bitmap (this happens either when dealing with an overflow | |
3560 or when the initial marking phase has simply marked the roots | |
3561 and didn't push them on the stack), then tasks claim heap | |
3562 regions whose bitmap they then scan to find gray objects. A | |
3563 global finger indicates where the end of the last claimed region | |
3564 is. A local finger indicates how far into the region a task has | |
3565 scanned. The two fingers are used to determine how to gray an | |
3566 object (i.e. whether simply marking it is OK, as it will be | |
3567 visited by a task in the future, or whether it needs to be also | |
3568 pushed on a stack). | |
3569 | |
3570 (2) Local Queue. The local queue of the task which is accessed | |
3571 reasonably efficiently by the task. Other tasks can steal from | |
3572 it when they run out of work. Throughout the marking phase, a | |
3573 task attempts to keep its local queue short but not totally | |
3574 empty, so that entries are available for stealing by other | |
3575 tasks. Only when there is no more work, a task will totally | |
3576 drain its local queue. | |
3577 | |
3578 (3) Global Mark Stack. This handles local queue overflow. During | |
3579 marking only sets of entries are moved between it and the local | |
3580 queues, as access to it requires a mutex and more fine-grain | |
3581 interaction with it which might cause contention. If it | |
3582 overflows, then the marking phase should restart and iterate | |
3583 over the bitmap to identify gray objects. Throughout the marking | |
3584 phase, tasks attempt to keep the global mark stack at a small | |
3585 length but not totally empty, so that entries are available for | |
3586 popping by other tasks. Only when there is no more work, tasks | |
3587 will totally drain the global mark stack. | |
3588 | |
3589 (4) Global Region Stack. Entries on it correspond to areas of | |
3590 the bitmap that need to be scanned since they contain gray | |
3591 objects. Pushes on the region stack only happen during | |
3592 evacuation pauses and typically correspond to areas covered by | |
3593 GC LABS. If it overflows, then the marking phase should restart | |
3594 and iterate over the bitmap to identify gray objects. Tasks will | |
3595 try to totally drain the region stack as soon as possible. | |
3596 | |
3597 (5) SATB Buffer Queue. This is where completed SATB buffers are | |
3598 made available. Buffers are regularly removed from this queue | |
3599 and scanned for roots, so that the queue doesn't get too | |
3600 long. During remark, all completed buffers are processed, as | |
3601 well as the filled in parts of any uncompleted buffers. | |
3602 | |
3603 The do_marking_step() method tries to abort when the time target | |
3604 has been reached. There are a few other cases when the | |
3605 do_marking_step() method also aborts: | |
3606 | |
3607 (1) When the marking phase has been aborted (after a Full GC). | |
3608 | |
3609 (2) When a global overflow (either on the global stack or the | |
3610 region stack) has been triggered. Before the task aborts, it | |
3611 will actually sync up with the other tasks to ensure that all | |
3612 the marking data structures (local queues, stacks, fingers etc.) | |
3613 are re-initialised so that when do_marking_step() completes, | |
3614 the marking phase can immediately restart. | |
3615 | |
3616 (3) When enough completed SATB buffers are available. The | |
3617 do_marking_step() method only tries to drain SATB buffers right | |
3618 at the beginning. So, if enough buffers are available, the | |
3619 marking step aborts and the SATB buffers are processed at | |
3620 the beginning of the next invocation. | |
3621 | |
3622 (4) To yield. when we have to yield then we abort and yield | |
3623 right at the end of do_marking_step(). This saves us from a lot | |
3624 of hassle as, by yielding we might allow a Full GC. If this | |
3625 happens then objects will be compacted underneath our feet, the | |
3626 heap might shrink, etc. We save checking for this by just | |
3627 aborting and doing the yield right at the end. | |
3628 | |
3629 From the above it follows that the do_marking_step() method should | |
3630 be called in a loop (or, otherwise, regularly) until it completes. | |
3631 | |
3632 If a marking step completes without its has_aborted() flag being | |
3633 true, it means it has completed the current marking phase (and | |
3634 also all other marking tasks have done so and have all synced up). | |
3635 | |
3636 A method called regular_clock_call() is invoked "regularly" (in | |
3637 sub ms intervals) throughout marking. It is this clock method that | |
3638 checks all the abort conditions which were mentioned above and | |
3639 decides when the task should abort. A work-based scheme is used to | |
3640 trigger this clock method: when the number of object words the | |
3641 marking phase has scanned or the number of references the marking | |
3642 phase has visited reach a given limit. Additional invocations to | |
3643 the method clock have been planted in a few other strategic places | |
3644 too. The initial reason for the clock method was to avoid calling | |
3645 vtime too regularly, as it is quite expensive. So, once it was in | |
3646 place, it was natural to piggy-back all the other conditions on it | |
3647 too and not constantly check them throughout the code. | |
3648 | |
3649 *****************************************************************************/ | |
3650 | |
3651 void CMTask::do_marking_step(double time_target_ms) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3652 assert(time_target_ms >= 1.0, "minimum granularity is 1ms"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3653 assert(concurrent() == _cm->concurrent(), "they should be the same"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3654 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3655 assert(concurrent() || _cm->region_stack_empty(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3656 "the region stack should have been cleared before remark"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3657 assert(_region_finger == NULL, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3658 "this should be non-null only when a region is being scanned"); |
342 | 3659 |
3660 G1CollectorPolicy* g1_policy = _g1h->g1_policy(); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3661 assert(_task_queues != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3662 assert(_task_queue != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3663 assert(_task_queues->queue(_task_id) == _task_queue, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3664 |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3665 assert(!_claimed, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3666 "only one thread should claim this task at any one time"); |
342 | 3667 |
3668 // OK, this doesn't safeguard again all possible scenarios, as it is | |
3669 // possible for two threads to set the _claimed flag at the same | |
3670 // time. But it is only for debugging purposes anyway and it will | |
3671 // catch most problems. | |
3672 _claimed = true; | |
3673 | |
3674 _start_time_ms = os::elapsedVTime() * 1000.0; | |
3675 statsOnly( _interval_start_time_ms = _start_time_ms ); | |
3676 | |
3677 double diff_prediction_ms = | |
3678 g1_policy->get_new_prediction(&_marking_step_diffs_ms); | |
3679 _time_target_ms = time_target_ms - diff_prediction_ms; | |
3680 | |
3681 // set up the variables that are used in the work-based scheme to | |
3682 // call the regular clock method | |
3683 _words_scanned = 0; | |
3684 _refs_reached = 0; | |
3685 recalculate_limits(); | |
3686 | |
3687 // clear all flags | |
3688 clear_has_aborted(); | |
3689 _has_aborted_timed_out = false; | |
3690 _draining_satb_buffers = false; | |
3691 | |
3692 ++_calls; | |
3693 | |
3694 if (_cm->verbose_low()) | |
3695 gclog_or_tty->print_cr("[%d] >>>>>>>>>> START, call = %d, " | |
3696 "target = %1.2lfms >>>>>>>>>>", | |
3697 _task_id, _calls, _time_target_ms); | |
3698 | |
3699 // Set up the bitmap and oop closures. Anything that uses them is | |
3700 // eventually called from this method, so it is OK to allocate these | |
3701 // statically. | |
3702 CMBitMapClosure bitmap_closure(this, _cm, _nextMarkBitMap); | |
3703 CMOopClosure oop_closure(_g1h, _cm, this); | |
3704 set_oop_closure(&oop_closure); | |
3705 | |
3706 if (_cm->has_overflown()) { | |
3707 // This can happen if the region stack or the mark stack overflows | |
3708 // during a GC pause and this task, after a yield point, | |
3709 // restarts. We have to abort as we need to get into the overflow | |
3710 // protocol which happens right at the end of this task. | |
3711 set_has_aborted(); | |
3712 } | |
3713 | |
3714 // First drain any available SATB buffers. After this, we will not | |
3715 // look at SATB buffers before the next invocation of this method. | |
3716 // If enough completed SATB buffers are queued up, the regular clock | |
3717 // will abort this task so that it restarts. | |
3718 drain_satb_buffers(); | |
3719 // ...then partially drain the local queue and the global stack | |
3720 drain_local_queue(true); | |
3721 drain_global_stack(true); | |
3722 | |
3723 // Then totally drain the region stack. We will not look at | |
3724 // it again before the next invocation of this method. Entries on | |
3725 // the region stack are only added during evacuation pauses, for | |
3726 // which we have to yield. When we do, we abort the task anyway so | |
3727 // it will look at the region stack again when it restarts. | |
3728 bitmap_closure.set_scanning_heap_region(false); | |
3729 drain_region_stack(&bitmap_closure); | |
3730 // ...then partially drain the local queue and the global stack | |
3731 drain_local_queue(true); | |
3732 drain_global_stack(true); | |
3733 | |
3734 do { | |
3735 if (!has_aborted() && _curr_region != NULL) { | |
3736 // This means that we're already holding on to a region. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3737 assert(_finger != NULL, "if region is not NULL, then the finger " |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3738 "should not be NULL either"); |
342 | 3739 |
3740 // We might have restarted this task after an evacuation pause | |
3741 // which might have evacuated the region we're holding on to | |
3742 // underneath our feet. Let's read its limit again to make sure | |
3743 // that we do not iterate over a region of the heap that | |
3744 // contains garbage (update_region_limit() will also move | |
3745 // _finger to the start of the region if it is found empty). | |
3746 update_region_limit(); | |
3747 // We will start from _finger not from the start of the region, | |
3748 // as we might be restarting this task after aborting half-way | |
3749 // through scanning this region. In this case, _finger points to | |
3750 // the address where we last found a marked object. If this is a | |
3751 // fresh region, _finger points to start(). | |
3752 MemRegion mr = MemRegion(_finger, _region_limit); | |
3753 | |
3754 if (_cm->verbose_low()) | |
3755 gclog_or_tty->print_cr("[%d] we're scanning part " | |
3756 "["PTR_FORMAT", "PTR_FORMAT") " | |
3757 "of region "PTR_FORMAT, | |
3758 _task_id, _finger, _region_limit, _curr_region); | |
3759 | |
3760 // Let's iterate over the bitmap of the part of the | |
3761 // region that is left. | |
3762 bitmap_closure.set_scanning_heap_region(true); | |
3763 if (mr.is_empty() || | |
3764 _nextMarkBitMap->iterate(&bitmap_closure, mr)) { | |
3765 // We successfully completed iterating over the region. Now, | |
3766 // let's give up the region. | |
3767 giveup_current_region(); | |
3768 regular_clock_call(); | |
3769 } else { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3770 assert(has_aborted(), "currently the only way to do so"); |
342 | 3771 // The only way to abort the bitmap iteration is to return |
3772 // false from the do_bit() method. However, inside the | |
3773 // do_bit() method we move the _finger to point to the | |
3774 // object currently being looked at. So, if we bail out, we | |
3775 // have definitely set _finger to something non-null. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3776 assert(_finger != NULL, "invariant"); |
342 | 3777 |
3778 // Region iteration was actually aborted. So now _finger | |
3779 // points to the address of the object we last scanned. If we | |
3780 // leave it there, when we restart this task, we will rescan | |
3781 // the object. It is easy to avoid this. We move the finger by | |
3782 // enough to point to the next possible object header (the | |
3783 // bitmap knows by how much we need to move it as it knows its | |
3784 // granularity). | |
1314
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3785 assert(_finger < _region_limit, "invariant"); |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3786 HeapWord* new_finger = _nextMarkBitMap->nextWord(_finger); |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3787 // Check if bitmap iteration was aborted while scanning the last object |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3788 if (new_finger >= _region_limit) { |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3789 giveup_current_region(); |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3790 } else { |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3791 move_finger_to(new_finger); |
3f0549ed0c98
6921710: G1: assert(new_finger >= _finger && new_finger < _region_limit,"invariant")
apetrusenko
parents:
1284
diff
changeset
|
3792 } |
342 | 3793 } |
3794 } | |
3795 // At this point we have either completed iterating over the | |
3796 // region we were holding on to, or we have aborted. | |
3797 | |
3798 // We then partially drain the local queue and the global stack. | |
3799 // (Do we really need this?) | |
3800 drain_local_queue(true); | |
3801 drain_global_stack(true); | |
3802 | |
3803 // Read the note on the claim_region() method on why it might | |
3804 // return NULL with potentially more regions available for | |
3805 // claiming and why we have to check out_of_regions() to determine | |
3806 // whether we're done or not. | |
3807 while (!has_aborted() && _curr_region == NULL && !_cm->out_of_regions()) { | |
3808 // We are going to try to claim a new region. We should have | |
3809 // given up on the previous one. | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3810 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3811 assert(_curr_region == NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3812 assert(_finger == NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3813 assert(_region_limit == NULL, "invariant"); |
342 | 3814 if (_cm->verbose_low()) |
3815 gclog_or_tty->print_cr("[%d] trying to claim a new region", _task_id); | |
3816 HeapRegion* claimed_region = _cm->claim_region(_task_id); | |
3817 if (claimed_region != NULL) { | |
3818 // Yes, we managed to claim one | |
3819 statsOnly( ++_regions_claimed ); | |
3820 | |
3821 if (_cm->verbose_low()) | |
3822 gclog_or_tty->print_cr("[%d] we successfully claimed " | |
3823 "region "PTR_FORMAT, | |
3824 _task_id, claimed_region); | |
3825 | |
3826 setup_for_region(claimed_region); | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3827 assert(_curr_region == claimed_region, "invariant"); |
342 | 3828 } |
3829 // It is important to call the regular clock here. It might take | |
3830 // a while to claim a region if, for example, we hit a large | |
3831 // block of empty regions. So we need to call the regular clock | |
3832 // method once round the loop to make sure it's called | |
3833 // frequently enough. | |
3834 regular_clock_call(); | |
3835 } | |
3836 | |
3837 if (!has_aborted() && _curr_region == NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3838 assert(_cm->out_of_regions(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3839 "at this point we should be out of regions"); |
342 | 3840 } |
3841 } while ( _curr_region != NULL && !has_aborted()); | |
3842 | |
3843 if (!has_aborted()) { | |
3844 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3845 // tasks might be pushing objects to it concurrently. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3846 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3847 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3848 assert(_cm->out_of_regions(), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3849 "at this point we should be out of regions"); |
342 | 3850 |
3851 if (_cm->verbose_low()) | |
3852 gclog_or_tty->print_cr("[%d] all regions claimed", _task_id); | |
3853 | |
3854 // Try to reduce the number of available SATB buffers so that | |
3855 // remark has less work to do. | |
3856 drain_satb_buffers(); | |
3857 } | |
3858 | |
3859 // Since we've done everything else, we can now totally drain the | |
3860 // local queue and global stack. | |
3861 drain_local_queue(false); | |
3862 drain_global_stack(false); | |
3863 | |
3864 // Attempt at work stealing from other task's queues. | |
3865 if (!has_aborted()) { | |
3866 // We have not aborted. This means that we have finished all that | |
3867 // we could. Let's try to do some stealing... | |
3868 | |
3869 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3870 // tasks might be pushing objects to it concurrently. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3871 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3872 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3873 assert(_cm->out_of_regions() && _task_queue->size() == 0, |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3874 "only way to reach here"); |
342 | 3875 |
3876 if (_cm->verbose_low()) | |
3877 gclog_or_tty->print_cr("[%d] starting to steal", _task_id); | |
3878 | |
3879 while (!has_aborted()) { | |
3880 oop obj; | |
3881 statsOnly( ++_steal_attempts ); | |
3882 | |
3883 if (_cm->try_stealing(_task_id, &_hash_seed, obj)) { | |
3884 if (_cm->verbose_medium()) | |
3885 gclog_or_tty->print_cr("[%d] stolen "PTR_FORMAT" successfully", | |
3886 _task_id, (void*) obj); | |
3887 | |
3888 statsOnly( ++_steals ); | |
3889 | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3890 assert(_nextMarkBitMap->isMarked((HeapWord*) obj), |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3891 "any stolen object should be marked"); |
342 | 3892 scan_object(obj); |
3893 | |
3894 // And since we're towards the end, let's totally drain the | |
3895 // local queue and global stack. | |
3896 drain_local_queue(false); | |
3897 drain_global_stack(false); | |
3898 } else { | |
3899 break; | |
3900 } | |
3901 } | |
3902 } | |
3903 | |
3904 // We still haven't aborted. Now, let's try to get into the | |
3905 // termination protocol. | |
3906 if (!has_aborted()) { | |
3907 // We cannot check whether the global stack is empty, since other | |
343
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3908 // tasks might be concurrently pushing objects on it. We also cannot |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3909 // check if the region stack is empty because if a thread is aborting |
afc1ce1efe66
6710665: G1: guarantee(_cm->out_of_regions() && _cm->region_stack_empty() && _task_queue->size() == 0, ...)
iveresov
parents:
342
diff
changeset
|
3910 // it can push a partially done region back. |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3911 // Separated the asserts so that we know which one fires. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3912 assert(_cm->out_of_regions(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3913 assert(_task_queue->size() == 0, "only way to reach here"); |
342 | 3914 |
3915 if (_cm->verbose_low()) | |
3916 gclog_or_tty->print_cr("[%d] starting termination protocol", _task_id); | |
3917 | |
3918 _termination_start_time_ms = os::elapsedVTime() * 1000.0; | |
3919 // The CMTask class also extends the TerminatorTerminator class, | |
3920 // hence its should_exit_termination() method will also decide | |
3921 // whether to exit the termination protocol or not. | |
3922 bool finished = _cm->terminator()->offer_termination(this); | |
3923 double termination_end_time_ms = os::elapsedVTime() * 1000.0; | |
3924 _termination_time_ms += | |
3925 termination_end_time_ms - _termination_start_time_ms; | |
3926 | |
3927 if (finished) { | |
3928 // We're all done. | |
3929 | |
3930 if (_task_id == 0) { | |
3931 // let's allow task 0 to do this | |
3932 if (concurrent()) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3933 assert(_cm->concurrent_marking_in_progress(), "invariant"); |
342 | 3934 // we need to set this to false before the next |
3935 // safepoint. This way we ensure that the marking phase | |
3936 // doesn't observe any more heap expansions. | |
3937 _cm->clear_concurrent_marking_in_progress(); | |
3938 } | |
3939 } | |
3940 | |
3941 // We can now guarantee that the global stack is empty, since | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3942 // all other tasks have finished. We separated the guarantees so |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3943 // that, if a condition is false, we can immediately find out |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3944 // which one. |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3945 guarantee(_cm->out_of_regions(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3946 guarantee(_cm->region_stack_empty(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3947 guarantee(_cm->mark_stack_empty(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3948 guarantee(_task_queue->size() == 0, "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3949 guarantee(!_cm->has_overflown(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3950 guarantee(!_cm->mark_stack_overflow(), "only way to reach here"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
3951 guarantee(!_cm->region_stack_overflow(), "only way to reach here"); |
342 | 3952 |
3953 if (_cm->verbose_low()) | |
3954 gclog_or_tty->print_cr("[%d] all tasks terminated", _task_id); | |
3955 } else { | |
3956 // Apparently there's more work to do. Let's abort this task. It | |
3957 // will restart it and we can hopefully find more things to do. | |
3958 | |
3959 if (_cm->verbose_low()) | |
3960 gclog_or_tty->print_cr("[%d] apparently there is more work to do", _task_id); | |
3961 | |
3962 set_has_aborted(); | |
3963 statsOnly( ++_aborted_termination ); | |
3964 } | |
3965 } | |
3966 | |
3967 // Mainly for debugging purposes to make sure that a pointer to the | |
3968 // closure which was statically allocated in this frame doesn't | |
3969 // escape it by accident. | |
3970 set_oop_closure(NULL); | |
3971 double end_time_ms = os::elapsedVTime() * 1000.0; | |
3972 double elapsed_time_ms = end_time_ms - _start_time_ms; | |
3973 // Update the step history. | |
3974 _step_times_ms.add(elapsed_time_ms); | |
3975 | |
3976 if (has_aborted()) { | |
3977 // The task was aborted for some reason. | |
3978 | |
3979 statsOnly( ++_aborted ); | |
3980 | |
3981 if (_has_aborted_timed_out) { | |
3982 double diff_ms = elapsed_time_ms - _time_target_ms; | |
3983 // Keep statistics of how well we did with respect to hitting | |
3984 // our target only if we actually timed out (if we aborted for | |
3985 // other reasons, then the results might get skewed). | |
3986 _marking_step_diffs_ms.add(diff_ms); | |
3987 } | |
3988 | |
3989 if (_cm->has_overflown()) { | |
3990 // This is the interesting one. We aborted because a global | |
3991 // overflow was raised. This means we have to restart the | |
3992 // marking phase and start iterating over regions. However, in | |
3993 // order to do this we have to make sure that all tasks stop | |
3994 // what they are doing and re-initialise in a safe manner. We | |
3995 // will achieve this with the use of two barrier sync points. | |
3996 | |
3997 if (_cm->verbose_low()) | |
3998 gclog_or_tty->print_cr("[%d] detected overflow", _task_id); | |
3999 | |
4000 _cm->enter_first_sync_barrier(_task_id); | |
4001 // When we exit this sync barrier we know that all tasks have | |
4002 // stopped doing marking work. So, it's now safe to | |
4003 // re-initialise our data structures. At the end of this method, | |
4004 // task 0 will clear the global data structures. | |
4005 | |
4006 statsOnly( ++_aborted_overflow ); | |
4007 | |
4008 // We clear the local state of this task... | |
4009 clear_region_fields(); | |
4010 | |
4011 // ...and enter the second barrier. | |
4012 _cm->enter_second_sync_barrier(_task_id); | |
4013 // At this point everything has bee re-initialised and we're | |
4014 // ready to restart. | |
4015 } | |
4016 | |
4017 if (_cm->verbose_low()) { | |
4018 gclog_or_tty->print_cr("[%d] <<<<<<<<<< ABORTING, target = %1.2lfms, " | |
4019 "elapsed = %1.2lfms <<<<<<<<<<", | |
4020 _task_id, _time_target_ms, elapsed_time_ms); | |
4021 if (_cm->has_aborted()) | |
4022 gclog_or_tty->print_cr("[%d] ========== MARKING ABORTED ==========", | |
4023 _task_id); | |
4024 } | |
4025 } else { | |
4026 if (_cm->verbose_low()) | |
4027 gclog_or_tty->print_cr("[%d] <<<<<<<<<< FINISHED, target = %1.2lfms, " | |
4028 "elapsed = %1.2lfms <<<<<<<<<<", | |
4029 _task_id, _time_target_ms, elapsed_time_ms); | |
4030 } | |
4031 | |
4032 _claimed = false; | |
4033 } | |
4034 | |
4035 CMTask::CMTask(int task_id, | |
4036 ConcurrentMark* cm, | |
4037 CMTaskQueue* task_queue, | |
4038 CMTaskQueueSet* task_queues) | |
4039 : _g1h(G1CollectedHeap::heap()), | |
4040 _task_id(task_id), _cm(cm), | |
4041 _claimed(false), | |
4042 _nextMarkBitMap(NULL), _hash_seed(17), | |
4043 _task_queue(task_queue), | |
4044 _task_queues(task_queues), | |
4045 _oop_closure(NULL) { | |
1023
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
4046 guarantee(task_queue != NULL, "invariant"); |
11d4857fe5e1
6888619: G1: too many guarantees in concurrent marking
tonyp
parents:
1022
diff
changeset
|
4047 guarantee(task_queues != NULL, "invariant"); |
342 | 4048 |
4049 statsOnly( _clock_due_to_scanning = 0; | |
4050 _clock_due_to_marking = 0 ); | |
4051 | |
4052 _marking_step_diffs_ms.add(0.5); | |
4053 } |