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

Mon, 21 Jul 2014 09:40:19 +0200

author
tschatzl
date
Mon, 21 Jul 2014 09:40:19 +0200
changeset 6935
ab5fbf410512
parent 6912
c49dcaf78a65
child 6977
4dfab3faf5e7
permissions
-rw-r--r--

8043722: Swapped usage of idx_t and bm_word_t types in parMarkBitMap.cpp
Summary: Clean up usage of idx_t and uintptr_t when using it in conjunction with BitMap::set_map(), casting to the appropriate type. Fixes compilation on S390.
Reviewed-by: tschatzl
Contributed-by: Dan Horak <dhorak@redhat.com>

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

mercurial