src/share/vm/gc_implementation/g1/concurrentMark.cpp

Sun, 21 Apr 2013 20:41:04 -0700

author
dcubed
date
Sun, 21 Apr 2013 20:41:04 -0700
changeset 4967
5a9fa2ba85f0
parent 4904
7b835924c31c
child 5018
b06ac540229e
permissions
-rw-r--r--

8012907: anti-delta fix for 8010992
Summary: anti-delta fix for 8010992 until 8012902 can be fixed
Reviewed-by: acorn, minqi, rdurbin

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

mercurial