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

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 5697
ff218fdb30ba
child 6168
1de8e5356754
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

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

mercurial