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