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