annotate src/share/vm/gc_implementation/g1/concurrentMark.hpp @ 4914:1534133741c2

8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo Summary: Improve the output of G1PrintRegionLivenessInfo by adding a per-region remembered set size information column Reviewed-by: jwilhelm, johnc
author tschatzl
date Thu, 19 Dec 2013 09:21:18 +0100
parents ea5503c5095e
children 0114a0a4434c
rev   line source
ysr@342 1 /*
johnc@4196 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
stefank@1879 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
stefank@1879 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
stefank@1879 27
tonyp@2037 28 #include "gc_implementation/g1/heapRegionSets.hpp"
stefank@1879 29 #include "utilities/taskqueue.hpp"
stefank@1879 30
ysr@342 31 class G1CollectedHeap;
ysr@342 32 class CMTask;
zgu@3863 33 typedef GenericTaskQueue<oop, mtGC> CMTaskQueue;
zgu@3863 34 typedef GenericTaskQueueSet<CMTaskQueue, mtGC> CMTaskQueueSet;
ysr@342 35
johnc@1944 36 // Closure used by CM during concurrent reference discovery
johnc@1944 37 // and reference processing (during remarking) to determine
johnc@1944 38 // if a particular object is alive. It is primarily used
johnc@1944 39 // to determine if referents of discovered reference objects
johnc@1944 40 // are alive. An instance is also embedded into the
johnc@1944 41 // reference processor as the _is_alive_non_header field
johnc@1944 42 class G1CMIsAliveClosure: public BoolObjectClosure {
johnc@1944 43 G1CollectedHeap* _g1;
johnc@1944 44 public:
tonyp@3659 45 G1CMIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) { }
johnc@1944 46
johnc@1944 47 void do_object(oop obj) {
johnc@1944 48 ShouldNotCallThis();
johnc@1944 49 }
johnc@1944 50 bool do_object_b(oop obj);
johnc@1944 51 };
johnc@1944 52
ysr@342 53 // A generic CM bit map. This is essentially a wrapper around the BitMap
ysr@342 54 // class, with one bit per (1<<_shifter) HeapWords.
ysr@342 55
apetrusenko@549 56 class CMBitMapRO VALUE_OBJ_CLASS_SPEC {
ysr@342 57 protected:
ysr@342 58 HeapWord* _bmStartWord; // base address of range covered by map
ysr@342 59 size_t _bmWordSize; // map size (in #HeapWords covered)
ysr@342 60 const int _shifter; // map to char or bit
ysr@342 61 VirtualSpace _virtual_space; // underlying the bit map
ysr@342 62 BitMap _bm; // the bit map itself
ysr@342 63
ysr@342 64 public:
ysr@342 65 // constructor
ysr@342 66 CMBitMapRO(ReservedSpace rs, int shifter);
ysr@342 67
ysr@342 68 enum { do_yield = true };
ysr@342 69
ysr@342 70 // inquiries
ysr@342 71 HeapWord* startWord() const { return _bmStartWord; }
ysr@342 72 size_t sizeInWords() const { return _bmWordSize; }
ysr@342 73 // the following is one past the last word in space
ysr@342 74 HeapWord* endWord() const { return _bmStartWord + _bmWordSize; }
ysr@342 75
ysr@342 76 // read marks
ysr@342 77
ysr@342 78 bool isMarked(HeapWord* addr) const {
ysr@342 79 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
ysr@342 80 "outside underlying space?");
ysr@342 81 return _bm.at(heapWordToOffset(addr));
ysr@342 82 }
ysr@342 83
ysr@342 84 // iteration
johnc@3110 85 inline bool iterate(BitMapClosure* cl, MemRegion mr);
johnc@3110 86 inline bool iterate(BitMapClosure* cl);
ysr@342 87
ysr@342 88 // Return the address corresponding to the next marked bit at or after
ysr@342 89 // "addr", and before "limit", if "limit" is non-NULL. If there is no
ysr@342 90 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
ysr@342 91 HeapWord* getNextMarkedWordAddress(HeapWord* addr,
ysr@342 92 HeapWord* limit = NULL) const;
ysr@342 93 // Return the address corresponding to the next unmarked bit at or after
ysr@342 94 // "addr", and before "limit", if "limit" is non-NULL. If there is no
ysr@342 95 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
ysr@342 96 HeapWord* getNextUnmarkedWordAddress(HeapWord* addr,
ysr@342 97 HeapWord* limit = NULL) const;
ysr@342 98
ysr@342 99 // conversion utilities
ysr@342 100 // XXX Fix these so that offsets are size_t's...
ysr@342 101 HeapWord* offsetToHeapWord(size_t offset) const {
ysr@342 102 return _bmStartWord + (offset << _shifter);
ysr@342 103 }
ysr@342 104 size_t heapWordToOffset(HeapWord* addr) const {
ysr@342 105 return pointer_delta(addr, _bmStartWord) >> _shifter;
ysr@342 106 }
ysr@342 107 int heapWordDiffToOffsetDiff(size_t diff) const;
ysr@342 108 HeapWord* nextWord(HeapWord* addr) {
ysr@342 109 return offsetToHeapWord(heapWordToOffset(addr) + 1);
ysr@342 110 }
ysr@342 111
ysr@342 112 // debugging
ysr@342 113 NOT_PRODUCT(bool covers(ReservedSpace rs) const;)
ysr@342 114 };
ysr@342 115
ysr@342 116 class CMBitMap : public CMBitMapRO {
ysr@342 117
ysr@342 118 public:
ysr@342 119 // constructor
ysr@342 120 CMBitMap(ReservedSpace rs, int shifter) :
ysr@342 121 CMBitMapRO(rs, shifter) {}
ysr@342 122
ysr@342 123 // write marks
ysr@342 124 void mark(HeapWord* addr) {
ysr@342 125 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
ysr@342 126 "outside underlying space?");
tonyp@2596 127 _bm.set_bit(heapWordToOffset(addr));
ysr@342 128 }
ysr@342 129 void clear(HeapWord* addr) {
ysr@342 130 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
ysr@342 131 "outside underlying space?");
tonyp@2596 132 _bm.clear_bit(heapWordToOffset(addr));
ysr@342 133 }
ysr@342 134 bool parMark(HeapWord* addr) {
ysr@342 135 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
ysr@342 136 "outside underlying space?");
tonyp@2596 137 return _bm.par_set_bit(heapWordToOffset(addr));
ysr@342 138 }
ysr@342 139 bool parClear(HeapWord* addr) {
ysr@342 140 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
ysr@342 141 "outside underlying space?");
tonyp@2596 142 return _bm.par_clear_bit(heapWordToOffset(addr));
ysr@342 143 }
ysr@342 144 void markRange(MemRegion mr);
ysr@342 145 void clearAll();
ysr@342 146 void clearRange(MemRegion mr);
ysr@342 147
ysr@342 148 // Starting at the bit corresponding to "addr" (inclusive), find the next
ysr@342 149 // "1" bit, if any. This bit starts some run of consecutive "1"'s; find
ysr@342 150 // the end of this run (stopping at "end_addr"). Return the MemRegion
ysr@342 151 // covering from the start of the region corresponding to the first bit
ysr@342 152 // of the run to the end of the region corresponding to the last bit of
ysr@342 153 // the run. If there is no "1" bit at or after "addr", return an empty
ysr@342 154 // MemRegion.
ysr@342 155 MemRegion getAndClearMarkedRegion(HeapWord* addr, HeapWord* end_addr);
ysr@342 156 };
ysr@342 157
ysr@342 158 // Represents a marking stack used by the CM collector.
ysr@342 159 // Ideally this should be GrowableArray<> just like MSC's marking stack(s).
apetrusenko@549 160 class CMMarkStack VALUE_OBJ_CLASS_SPEC {
ysr@342 161 ConcurrentMark* _cm;
tonyp@3067 162 oop* _base; // bottom of stack
tonyp@3067 163 jint _index; // one more than last occupied index
tonyp@3067 164 jint _capacity; // max #elements
tonyp@3067 165 jint _saved_index; // value of _index saved at start of GC
ysr@342 166 NOT_PRODUCT(jint _max_depth;) // max depth plumbed during run
ysr@342 167
ysr@342 168 bool _overflow;
ysr@342 169 DEBUG_ONLY(bool _drain_in_progress;)
ysr@342 170 DEBUG_ONLY(bool _drain_in_progress_yields;)
ysr@342 171
ysr@342 172 public:
ysr@342 173 CMMarkStack(ConcurrentMark* cm);
ysr@342 174 ~CMMarkStack();
ysr@342 175
ysr@342 176 void allocate(size_t size);
ysr@342 177
ysr@342 178 oop pop() {
ysr@342 179 if (!isEmpty()) {
ysr@342 180 return _base[--_index] ;
ysr@342 181 }
ysr@342 182 return NULL;
ysr@342 183 }
ysr@342 184
ysr@342 185 // If overflow happens, don't do the push, and record the overflow.
ysr@342 186 // *Requires* that "ptr" is already marked.
ysr@342 187 void push(oop ptr) {
ysr@342 188 if (isFull()) {
ysr@342 189 // Record overflow.
ysr@342 190 _overflow = true;
ysr@342 191 return;
ysr@342 192 } else {
ysr@342 193 _base[_index++] = ptr;
ysr@342 194 NOT_PRODUCT(_max_depth = MAX2(_max_depth, _index));
ysr@342 195 }
ysr@342 196 }
ysr@342 197 // Non-block impl. Note: concurrency is allowed only with other
ysr@342 198 // "par_push" operations, not with "pop" or "drain". We would need
ysr@342 199 // parallel versions of them if such concurrency was desired.
ysr@342 200 void par_push(oop ptr);
ysr@342 201
ysr@342 202 // Pushes the first "n" elements of "ptr_arr" on the stack.
ysr@342 203 // Non-block impl. Note: concurrency is allowed only with other
ysr@342 204 // "par_adjoin_arr" or "push" operations, not with "pop" or "drain".
ysr@342 205 void par_adjoin_arr(oop* ptr_arr, int n);
ysr@342 206
ysr@342 207 // Pushes the first "n" elements of "ptr_arr" on the stack.
ysr@342 208 // Locking impl: concurrency is allowed only with
ysr@342 209 // "par_push_arr" and/or "par_pop_arr" operations, which use the same
ysr@342 210 // locking strategy.
ysr@342 211 void par_push_arr(oop* ptr_arr, int n);
ysr@342 212
ysr@342 213 // If returns false, the array was empty. Otherwise, removes up to "max"
ysr@342 214 // elements from the stack, and transfers them to "ptr_arr" in an
ysr@342 215 // unspecified order. The actual number transferred is given in "n" ("n
ysr@342 216 // == 0" is deliberately redundant with the return value.) Locking impl:
ysr@342 217 // concurrency is allowed only with "par_push_arr" and/or "par_pop_arr"
ysr@342 218 // operations, which use the same locking strategy.
ysr@342 219 bool par_pop_arr(oop* ptr_arr, int max, int* n);
ysr@342 220
ysr@342 221 // Drain the mark stack, applying the given closure to all fields of
ysr@342 222 // objects on the stack. (That is, continue until the stack is empty,
ysr@342 223 // even if closure applications add entries to the stack.) The "bm"
ysr@342 224 // argument, if non-null, may be used to verify that only marked objects
ysr@342 225 // are on the mark stack. If "yield_after" is "true", then the
ysr@342 226 // concurrent marker performing the drain offers to yield after
ysr@342 227 // processing each object. If a yield occurs, stops the drain operation
ysr@342 228 // and returns false. Otherwise, returns true.
ysr@342 229 template<class OopClosureClass>
ysr@342 230 bool drain(OopClosureClass* cl, CMBitMap* bm, bool yield_after = false);
ysr@342 231
ysr@342 232 bool isEmpty() { return _index == 0; }
ysr@342 233 bool isFull() { return _index == _capacity; }
ysr@342 234 int maxElems() { return _capacity; }
ysr@342 235
ysr@342 236 bool overflow() { return _overflow; }
ysr@342 237 void clear_overflow() { _overflow = false; }
ysr@342 238
ysr@342 239 int size() { return _index; }
ysr@342 240
ysr@342 241 void setEmpty() { _index = 0; clear_overflow(); }
ysr@342 242
tonyp@3067 243 // Record the current index.
tonyp@3067 244 void note_start_of_gc();
tonyp@3067 245
tonyp@3067 246 // Make sure that we have not added any entries to the stack during GC.
tonyp@3067 247 void note_end_of_gc();
tonyp@3067 248
ysr@342 249 // iterate over the oops in the mark stack, up to the bound recorded via
ysr@342 250 // the call above.
ysr@342 251 void oops_do(OopClosure* f);
ysr@342 252 };
ysr@342 253
tonyp@2413 254 class ForceOverflowSettings VALUE_OBJ_CLASS_SPEC {
tonyp@2413 255 private:
tonyp@2413 256 #ifndef PRODUCT
tonyp@2413 257 uintx _num_remaining;
tonyp@2413 258 bool _force;
tonyp@2413 259 #endif // !defined(PRODUCT)
tonyp@2413 260
tonyp@2413 261 public:
tonyp@2413 262 void init() PRODUCT_RETURN;
tonyp@2413 263 void update() PRODUCT_RETURN;
tonyp@2413 264 bool should_force() PRODUCT_RETURN_( return false; );
tonyp@2413 265 };
tonyp@2413 266
ysr@342 267 // this will enable a variety of different statistics per GC task
ysr@342 268 #define _MARKING_STATS_ 0
ysr@342 269 // this will enable the higher verbose levels
ysr@342 270 #define _MARKING_VERBOSE_ 0
ysr@342 271
ysr@342 272 #if _MARKING_STATS_
ysr@342 273 #define statsOnly(statement) \
ysr@342 274 do { \
ysr@342 275 statement ; \
ysr@342 276 } while (0)
ysr@342 277 #else // _MARKING_STATS_
ysr@342 278 #define statsOnly(statement) \
ysr@342 279 do { \
ysr@342 280 } while (0)
ysr@342 281 #endif // _MARKING_STATS_
ysr@342 282
ysr@342 283 typedef enum {
ysr@342 284 no_verbose = 0, // verbose turned off
ysr@342 285 stats_verbose, // only prints stats at the end of marking
ysr@342 286 low_verbose, // low verbose, mostly per region and per major event
ysr@342 287 medium_verbose, // a bit more detailed than low
ysr@342 288 high_verbose // per object verbose
ysr@342 289 } CMVerboseLevel;
ysr@342 290
tonyp@3120 291 class YoungList;
tonyp@3120 292
tonyp@3120 293 // Root Regions are regions that are not empty at the beginning of a
tonyp@3120 294 // marking cycle and which we might collect during an evacuation pause
tonyp@3120 295 // while the cycle is active. Given that, during evacuation pauses, we
tonyp@3120 296 // do not copy objects that are explicitly marked, what we have to do
tonyp@3120 297 // for the root regions is to scan them and mark all objects reachable
tonyp@3120 298 // from them. According to the SATB assumptions, we only need to visit
tonyp@3120 299 // each object once during marking. So, as long as we finish this scan
tonyp@3120 300 // before the next evacuation pause, we can copy the objects from the
tonyp@3120 301 // root regions without having to mark them or do anything else to them.
tonyp@3120 302 //
tonyp@3120 303 // Currently, we only support root region scanning once (at the start
tonyp@3120 304 // of the marking cycle) and the root regions are all the survivor
tonyp@3120 305 // regions populated during the initial-mark pause.
tonyp@3120 306 class CMRootRegions VALUE_OBJ_CLASS_SPEC {
tonyp@3120 307 private:
tonyp@3120 308 YoungList* _young_list;
tonyp@3120 309 ConcurrentMark* _cm;
tonyp@3120 310
tonyp@3120 311 volatile bool _scan_in_progress;
tonyp@3120 312 volatile bool _should_abort;
tonyp@3120 313 HeapRegion* volatile _next_survivor;
tonyp@3120 314
tonyp@3120 315 public:
tonyp@3120 316 CMRootRegions();
tonyp@3120 317 // We actually do most of the initialization in this method.
tonyp@3120 318 void init(G1CollectedHeap* g1h, ConcurrentMark* cm);
tonyp@3120 319
tonyp@3120 320 // Reset the claiming / scanning of the root regions.
tonyp@3120 321 void prepare_for_scan();
tonyp@3120 322
tonyp@3120 323 // Forces get_next() to return NULL so that the iteration aborts early.
tonyp@3120 324 void abort() { _should_abort = true; }
tonyp@3120 325
tonyp@3120 326 // Return true if the CM thread are actively scanning root regions,
tonyp@3120 327 // false otherwise.
tonyp@3120 328 bool scan_in_progress() { return _scan_in_progress; }
tonyp@3120 329
tonyp@3120 330 // Claim the next root region to scan atomically, or return NULL if
tonyp@3120 331 // all have been claimed.
tonyp@3120 332 HeapRegion* claim_next();
tonyp@3120 333
tonyp@3120 334 // Flag that we're done with root region scanning and notify anyone
tonyp@3120 335 // who's waiting on it. If aborted is false, assume that all regions
tonyp@3120 336 // have been claimed.
tonyp@3120 337 void scan_finished();
tonyp@3120 338
tonyp@3120 339 // If CM threads are still scanning root regions, wait until they
tonyp@3120 340 // are done. Return true if we had to wait, false otherwise.
tonyp@3120 341 bool wait_until_scan_finished();
tonyp@3120 342 };
ysr@342 343
ysr@342 344 class ConcurrentMarkThread;
ysr@342 345
zgu@3863 346 class ConcurrentMark: public CHeapObj<mtGC> {
ysr@342 347 friend class ConcurrentMarkThread;
ysr@342 348 friend class CMTask;
ysr@342 349 friend class CMBitMapClosure;
ysr@342 350 friend class CMGlobalObjectClosure;
ysr@342 351 friend class CMRemarkTask;
ysr@342 352 friend class CMConcurrentMarkingTask;
ysr@342 353 friend class G1ParNoteEndTask;
ysr@342 354 friend class CalcLiveObjectsClosure;
johnc@2815 355 friend class G1CMRefProcTaskProxy;
johnc@2815 356 friend class G1CMRefProcTaskExecutor;
johnc@4474 357 friend class G1CMKeepAliveAndDrainClosure;
johnc@4474 358 friend class G1CMDrainMarkingStackClosure;
ysr@342 359
ysr@342 360 protected:
ysr@342 361 ConcurrentMarkThread* _cmThread; // the thread doing the work
ysr@342 362 G1CollectedHeap* _g1h; // the heap.
jmasa@3008 363 uint _parallel_marking_threads; // the number of marking
jmasa@2941 364 // threads we're use
jmasa@3008 365 uint _max_parallel_marking_threads; // max number of marking
jmasa@2941 366 // threads we'll ever use
ysr@342 367 double _sleep_factor; // how much we have to sleep, with
ysr@342 368 // respect to the work we just did, to
ysr@342 369 // meet the marking overhead goal
ysr@342 370 double _marking_task_overhead; // marking target overhead for
ysr@342 371 // a single task
ysr@342 372
ysr@342 373 // same as the two above, but for the cleanup task
ysr@342 374 double _cleanup_sleep_factor;
ysr@342 375 double _cleanup_task_overhead;
ysr@342 376
tonyp@2037 377 FreeRegionList _cleanup_list;
ysr@342 378
brutisso@3111 379 // Concurrent marking support structures
ysr@342 380 CMBitMap _markBitMap1;
ysr@342 381 CMBitMap _markBitMap2;
ysr@342 382 CMBitMapRO* _prevMarkBitMap; // completed mark bitmap
ysr@342 383 CMBitMap* _nextMarkBitMap; // under-construction mark bitmap
ysr@342 384
ysr@342 385 BitMap _region_bm;
ysr@342 386 BitMap _card_bm;
ysr@342 387
ysr@342 388 // Heap bounds
ysr@342 389 HeapWord* _heap_start;
ysr@342 390 HeapWord* _heap_end;
ysr@342 391
tonyp@3120 392 // Root region tracking and claiming.
tonyp@3120 393 CMRootRegions _root_regions;
tonyp@3120 394
ysr@342 395 // For gray objects
ysr@342 396 CMMarkStack _markStack; // Grey objects behind global finger.
ysr@342 397 HeapWord* volatile _finger; // the global finger, region aligned,
ysr@342 398 // always points to the end of the
ysr@342 399 // last claimed region
ysr@342 400
ysr@342 401 // marking tasks
jmasa@3008 402 uint _max_task_num; // maximum task number
jmasa@3008 403 uint _active_tasks; // task num currently active
ysr@342 404 CMTask** _tasks; // task queue array (max_task_num len)
ysr@342 405 CMTaskQueueSet* _task_queues; // task queue set
ysr@342 406 ParallelTaskTerminator _terminator; // for termination
ysr@342 407
ysr@342 408 // Two sync barriers that are used to synchronise tasks when an
ysr@342 409 // overflow occurs. The algorithm is the following. All tasks enter
ysr@342 410 // the first one to ensure that they have all stopped manipulating
ysr@342 411 // the global data structures. After they exit it, they re-initialise
ysr@342 412 // their data structures and task 0 re-initialises the global data
ysr@342 413 // structures. Then, they enter the second sync barrier. This
ysr@342 414 // ensure, that no task starts doing work before all data
ysr@342 415 // structures (local and global) have been re-initialised. When they
ysr@342 416 // exit it, they are free to start working again.
ysr@342 417 WorkGangBarrierSync _first_overflow_barrier_sync;
ysr@342 418 WorkGangBarrierSync _second_overflow_barrier_sync;
ysr@342 419
ysr@342 420 // this is set by any task, when an overflow on the global data
ysr@342 421 // structures is detected.
ysr@342 422 volatile bool _has_overflown;
ysr@342 423 // true: marking is concurrent, false: we're in remark
ysr@342 424 volatile bool _concurrent;
ysr@342 425 // set at the end of a Full GC so that marking aborts
ysr@342 426 volatile bool _has_aborted;
johnc@1755 427
ysr@342 428 // used when remark aborts due to an overflow to indicate that
ysr@342 429 // another concurrent marking phase should start
ysr@342 430 volatile bool _restart_for_overflow;
ysr@342 431
ysr@342 432 // This is true from the very start of concurrent marking until the
ysr@342 433 // point when all the tasks complete their work. It is really used
ysr@342 434 // to determine the points between the end of concurrent marking and
ysr@342 435 // time of remark.
ysr@342 436 volatile bool _concurrent_marking_in_progress;
ysr@342 437
ysr@342 438 // verbose level
ysr@342 439 CMVerboseLevel _verbose_level;
ysr@342 440
ysr@342 441 // All of these times are in ms.
ysr@342 442 NumberSeq _init_times;
ysr@342 443 NumberSeq _remark_times;
ysr@342 444 NumberSeq _remark_mark_times;
ysr@342 445 NumberSeq _remark_weak_ref_times;
ysr@342 446 NumberSeq _cleanup_times;
ysr@342 447 double _total_counting_time;
ysr@342 448 double _total_rs_scrub_time;
ysr@342 449
ysr@342 450 double* _accum_task_vtime; // accumulated task vtime
ysr@342 451
jmasa@2941 452 FlexibleWorkGang* _parallel_workers;
ysr@342 453
tonyp@2413 454 ForceOverflowSettings _force_overflow_conc;
tonyp@2413 455 ForceOverflowSettings _force_overflow_stw;
tonyp@2413 456
ysr@342 457 void weakRefsWork(bool clear_all_soft_refs);
ysr@342 458
ysr@342 459 void swapMarkBitMaps();
ysr@342 460
ysr@342 461 // It resets the global marking data structures, as well as the
ysr@342 462 // task local ones; should be called during initial mark.
ysr@342 463 void reset();
johnc@4196 464
johnc@4196 465 // Resets all the marking data structures. Called when we have to restart
johnc@4196 466 // marking or when marking completes (via set_non_marking_state below).
johnc@4196 467 void reset_marking_state(bool clear_overflow = true);
johnc@4196 468
johnc@4196 469 // We do this after we're done with marking so that the marking data
johnc@4196 470 // structures are initialised to a sensible and predictable state.
johnc@4196 471 void set_non_marking_state();
ysr@342 472
johnc@4481 473 // Called to indicate how many threads are currently active.
johnc@4481 474 void set_concurrency(uint active_tasks);
johnc@4481 475
ysr@342 476 // It should be called to indicate which phase we're in (concurrent
ysr@342 477 // mark or remark) and how many threads are currently active.
johnc@4481 478 void set_concurrency_and_phase(uint active_tasks, bool concurrent);
ysr@342 479
ysr@342 480 // prints all gathered CM-related statistics
ysr@342 481 void print_stats();
ysr@342 482
tonyp@2037 483 bool cleanup_list_is_empty() {
tonyp@2037 484 return _cleanup_list.is_empty();
tonyp@2037 485 }
tonyp@2037 486
ysr@342 487 // accessor methods
johnc@4198 488 uint parallel_marking_threads() const { return _parallel_marking_threads; }
johnc@4198 489 uint max_parallel_marking_threads() const { return _max_parallel_marking_threads;}
johnc@4198 490 double sleep_factor() { return _sleep_factor; }
johnc@4198 491 double marking_task_overhead() { return _marking_task_overhead;}
johnc@4198 492 double cleanup_sleep_factor() { return _cleanup_sleep_factor; }
johnc@4198 493 double cleanup_task_overhead() { return _cleanup_task_overhead;}
ysr@342 494
johnc@4198 495 bool use_parallel_marking_threads() const {
johnc@4198 496 assert(parallel_marking_threads() <=
johnc@4198 497 max_parallel_marking_threads(), "sanity");
johnc@4198 498 assert((_parallel_workers == NULL && parallel_marking_threads() == 0) ||
johnc@4198 499 parallel_marking_threads() > 0,
johnc@4198 500 "parallel workers not set up correctly");
johnc@4198 501 return _parallel_workers != NULL;
johnc@4198 502 }
johnc@4198 503
johnc@4198 504 HeapWord* finger() { return _finger; }
johnc@4198 505 bool concurrent() { return _concurrent; }
johnc@4198 506 uint active_tasks() { return _active_tasks; }
johnc@4198 507 ParallelTaskTerminator* terminator() { return &_terminator; }
ysr@342 508
ysr@342 509 // It claims the next available region to be scanned by a marking
ysr@342 510 // task. It might return NULL if the next region is empty or we have
ysr@342 511 // run out of regions. In the latter case, out_of_regions()
ysr@342 512 // determines whether we've really run out of regions or the task
ysr@342 513 // should call claim_region() again. This might seem a bit
ysr@342 514 // awkward. Originally, the code was written so that claim_region()
ysr@342 515 // either successfully returned with a non-empty region or there
ysr@342 516 // were no more regions to be claimed. The problem with this was
ysr@342 517 // that, in certain circumstances, it iterated over large chunks of
ysr@342 518 // the heap finding only empty regions and, while it was working, it
ysr@342 519 // was preventing the calling task to call its regular clock
ysr@342 520 // method. So, this way, each task will spend very little time in
ysr@342 521 // claim_region() and is allowed to call the regular clock method
ysr@342 522 // frequently.
ysr@342 523 HeapRegion* claim_region(int task);
ysr@342 524
ysr@342 525 // It determines whether we've run out of regions to scan.
ysr@342 526 bool out_of_regions() { return _finger == _heap_end; }
ysr@342 527
ysr@342 528 // Returns the task with the given id
ysr@342 529 CMTask* task(int id) {
tonyp@1023 530 assert(0 <= id && id < (int) _active_tasks,
tonyp@1023 531 "task id not within active bounds");
ysr@342 532 return _tasks[id];
ysr@342 533 }
ysr@342 534
ysr@342 535 // Returns the task queue with the given id
ysr@342 536 CMTaskQueue* task_queue(int id) {
tonyp@1023 537 assert(0 <= id && id < (int) _active_tasks,
tonyp@1023 538 "task queue id not within active bounds");
ysr@342 539 return (CMTaskQueue*) _task_queues->queue(id);
ysr@342 540 }
ysr@342 541
ysr@342 542 // Returns the task queue set
ysr@342 543 CMTaskQueueSet* task_queues() { return _task_queues; }
ysr@342 544
ysr@342 545 // Access / manipulation of the overflow flag which is set to
tonyp@3659 546 // indicate that the global stack has overflown
ysr@342 547 bool has_overflown() { return _has_overflown; }
ysr@342 548 void set_has_overflown() { _has_overflown = true; }
ysr@342 549 void clear_has_overflown() { _has_overflown = false; }
tonyp@3120 550 bool restart_for_overflow() { return _restart_for_overflow; }
ysr@342 551
ysr@342 552 // Methods to enter the two overflow sync barriers
ysr@342 553 void enter_first_sync_barrier(int task_num);
ysr@342 554 void enter_second_sync_barrier(int task_num);
ysr@342 555
tonyp@2413 556 ForceOverflowSettings* force_overflow_conc() {
tonyp@2413 557 return &_force_overflow_conc;
tonyp@2413 558 }
tonyp@2413 559
tonyp@2413 560 ForceOverflowSettings* force_overflow_stw() {
tonyp@2413 561 return &_force_overflow_stw;
tonyp@2413 562 }
tonyp@2413 563
tonyp@2413 564 ForceOverflowSettings* force_overflow() {
tonyp@2413 565 if (concurrent()) {
tonyp@2413 566 return force_overflow_conc();
tonyp@2413 567 } else {
tonyp@2413 568 return force_overflow_stw();
tonyp@2413 569 }
tonyp@2413 570 }
tonyp@2413 571
johnc@3119 572 // Live Data Counting data structures...
johnc@3119 573 // These data structures are initialized at the start of
johnc@3119 574 // marking. They are written to while marking is active.
johnc@3119 575 // They are aggregated during remark; the aggregated values
johnc@3119 576 // are then used to populate the _region_bm, _card_bm, and
johnc@3119 577 // the total live bytes, which are then subsequently updated
johnc@3119 578 // during cleanup.
johnc@3119 579
johnc@3119 580 // An array of bitmaps (one bit map per task). Each bitmap
johnc@3119 581 // is used to record the cards spanned by the live objects
johnc@3119 582 // marked by that task/worker.
johnc@3119 583 BitMap* _count_card_bitmaps;
johnc@3119 584
johnc@3119 585 // Used to record the number of marked live bytes
johnc@3119 586 // (for each region, by worker thread).
johnc@3119 587 size_t** _count_marked_bytes;
johnc@3119 588
johnc@3119 589 // Card index of the bottom of the G1 heap. Used for biasing indices into
johnc@3119 590 // the card bitmaps.
johnc@3119 591 intptr_t _heap_bottom_card_num;
johnc@3119 592
ysr@342 593 public:
ysr@342 594 // Manipulation of the global mark stack.
ysr@342 595 // Notice that the first mark_stack_push is CAS-based, whereas the
ysr@342 596 // two below are Mutex-based. This is OK since the first one is only
ysr@342 597 // called during evacuation pauses and doesn't compete with the
ysr@342 598 // other two (which are called by the marking tasks during
ysr@342 599 // concurrent marking or remark).
ysr@342 600 bool mark_stack_push(oop p) {
ysr@342 601 _markStack.par_push(p);
ysr@342 602 if (_markStack.overflow()) {
ysr@342 603 set_has_overflown();
ysr@342 604 return false;
ysr@342 605 }
ysr@342 606 return true;
ysr@342 607 }
ysr@342 608 bool mark_stack_push(oop* arr, int n) {
ysr@342 609 _markStack.par_push_arr(arr, n);
ysr@342 610 if (_markStack.overflow()) {
ysr@342 611 set_has_overflown();
ysr@342 612 return false;
ysr@342 613 }
ysr@342 614 return true;
ysr@342 615 }
ysr@342 616 void mark_stack_pop(oop* arr, int max, int* n) {
ysr@342 617 _markStack.par_pop_arr(arr, max, n);
ysr@342 618 }
tonyp@2601 619 size_t mark_stack_size() { return _markStack.size(); }
ysr@342 620 size_t partial_mark_stack_size_target() { return _markStack.maxElems()/3; }
tonyp@2601 621 bool mark_stack_overflow() { return _markStack.overflow(); }
tonyp@2601 622 bool mark_stack_empty() { return _markStack.isEmpty(); }
ysr@342 623
tonyp@3120 624 CMRootRegions* root_regions() { return &_root_regions; }
tonyp@3120 625
ysr@342 626 bool concurrent_marking_in_progress() {
ysr@342 627 return _concurrent_marking_in_progress;
ysr@342 628 }
ysr@342 629 void set_concurrent_marking_in_progress() {
ysr@342 630 _concurrent_marking_in_progress = true;
ysr@342 631 }
ysr@342 632 void clear_concurrent_marking_in_progress() {
ysr@342 633 _concurrent_marking_in_progress = false;
ysr@342 634 }
ysr@342 635
ysr@342 636 void update_accum_task_vtime(int i, double vtime) {
ysr@342 637 _accum_task_vtime[i] += vtime;
ysr@342 638 }
ysr@342 639
ysr@342 640 double all_task_accum_vtime() {
ysr@342 641 double ret = 0.0;
ysr@342 642 for (int i = 0; i < (int)_max_task_num; ++i)
ysr@342 643 ret += _accum_task_vtime[i];
ysr@342 644 return ret;
ysr@342 645 }
ysr@342 646
ysr@342 647 // Attempts to steal an object from the task queues of other tasks
ysr@342 648 bool try_stealing(int task_num, int* hash_seed, oop& obj) {
ysr@342 649 return _task_queues->steal(task_num, hash_seed, obj);
ysr@342 650 }
ysr@342 651
tonyp@3681 652 ConcurrentMark(ReservedSpace rs, uint max_regions);
ysr@342 653 ~ConcurrentMark();
johnc@3119 654
ysr@342 655 ConcurrentMarkThread* cmThread() { return _cmThread; }
ysr@342 656
ysr@342 657 CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
ysr@342 658 CMBitMap* nextMarkBitMap() const { return _nextMarkBitMap; }
ysr@342 659
jmasa@2941 660 // Returns the number of GC threads to be used in a concurrent
jmasa@2941 661 // phase based on the number of GC threads being used in a STW
jmasa@2941 662 // phase.
jmasa@3008 663 uint scale_parallel_threads(uint n_par_threads);
jmasa@2941 664
jmasa@2941 665 // Calculates the number of GC threads to be used in a concurrent phase.
jmasa@3008 666 uint calc_parallel_marking_threads();
jmasa@2941 667
ysr@342 668 // The following three are interaction between CM and
ysr@342 669 // G1CollectedHeap
ysr@342 670
ysr@342 671 // This notifies CM that a root during initial-mark needs to be
tonyp@3120 672 // grayed. It is MT-safe. word_size is the size of the object in
tonyp@3120 673 // words. It is passed explicitly as sometimes we cannot calculate
tonyp@3120 674 // it from the given object because it might be in an inconsistent
tonyp@3120 675 // state (e.g., in to-space and being copied). So the caller is
tonyp@3120 676 // responsible for dealing with this issue (e.g., get the size from
tonyp@3120 677 // the from-space image when the to-space image might be
tonyp@3120 678 // inconsistent) and always passing the size. hr is the region that
tonyp@3120 679 // contains the object and it's passed optionally from callers who
tonyp@3120 680 // might already have it (no point in recalculating it).
tonyp@3120 681 inline void grayRoot(oop obj, size_t word_size,
tonyp@3120 682 uint worker_id, HeapRegion* hr = NULL);
tonyp@3067 683
tonyp@1388 684 // It iterates over the heap and for each object it comes across it
tonyp@1388 685 // will dump the contents of its reference fields, as well as
tonyp@1388 686 // liveness information for the object and its referents. The dump
tonyp@1388 687 // will be written to a file with the following name:
johnc@2597 688 // G1PrintReachableBaseFile + "." + str.
johnc@2597 689 // vo decides whether the prev (vo == UsePrevMarking), the next
johnc@2597 690 // (vo == UseNextMarking) marking information, or the mark word
johnc@2597 691 // (vo == UseMarkWord) will be used to determine the liveness of
johnc@2597 692 // each object / referent.
johnc@2597 693 // If all is true, all objects in the heap will be dumped, otherwise
johnc@2597 694 // only the live ones. In the dump the following symbols / breviations
johnc@2597 695 // are used:
tonyp@1388 696 // M : an explicitly live object (its bitmap bit is set)
tonyp@1388 697 // > : an implicitly live object (over tams)
tonyp@1388 698 // O : an object outside the G1 heap (typically: in the perm gen)
tonyp@1388 699 // NOT : a reference field whose referent is not live
tonyp@1388 700 // AND MARKED : indicates that an object is both explicitly and
tonyp@1388 701 // implicitly live (it should be one or the other, not both)
tonyp@1388 702 void print_reachable(const char* str,
johnc@2597 703 VerifyOption vo, bool all) PRODUCT_RETURN;
ysr@342 704
ysr@342 705 // Clear the next marking bitmap (will be called concurrently).
ysr@342 706 void clearNextBitmap();
ysr@342 707
ysr@342 708 // These two do the work that needs to be done before and after the
ysr@342 709 // initial root checkpoint. Since this checkpoint can be done at two
ysr@342 710 // different points (i.e. an explicit pause or piggy-backed on a
ysr@342 711 // young collection), then it's nice to be able to easily share the
ysr@342 712 // pre/post code. It might be the case that we can put everything in
ysr@342 713 // the post method. TP
ysr@342 714 void checkpointRootsInitialPre();
ysr@342 715 void checkpointRootsInitialPost();
ysr@342 716
tonyp@3120 717 // Scan all the root regions and mark everything reachable from
tonyp@3120 718 // them.
tonyp@3120 719 void scanRootRegions();
tonyp@3120 720
tonyp@3120 721 // Scan a single root region and mark everything reachable from it.
tonyp@3120 722 void scanRootRegion(HeapRegion* hr, uint worker_id);
tonyp@3120 723
ysr@342 724 // Do concurrent phase of marking, to a tentative transitive closure.
ysr@342 725 void markFromRoots();
ysr@342 726
ysr@342 727 void checkpointRootsFinal(bool clear_all_soft_refs);
ysr@342 728 void checkpointRootsFinalWork();
ysr@342 729 void cleanup();
ysr@342 730 void completeCleanup();
ysr@342 731
ysr@342 732 // Mark in the previous bitmap. NB: this is usually read-only, so use
ysr@342 733 // this carefully!
tonyp@3067 734 inline void markPrev(oop p);
johnc@3119 735
tonyp@3067 736 // Clears marks for all objects in the given range, for the prev,
tonyp@3067 737 // next, or both bitmaps. NB: the previous bitmap is usually
tonyp@3067 738 // read-only, so use this carefully!
tonyp@3067 739 void clearRangePrevBitmap(MemRegion mr);
tonyp@3067 740 void clearRangeNextBitmap(MemRegion mr);
tonyp@3067 741 void clearRangeBothBitmaps(MemRegion mr);
ysr@342 742
tonyp@3067 743 // Notify data structures that a GC has started.
tonyp@3067 744 void note_start_of_gc() {
tonyp@3067 745 _markStack.note_start_of_gc();
ysr@342 746 }
tonyp@3067 747
tonyp@3067 748 // Notify data structures that a GC is finished.
tonyp@3067 749 void note_end_of_gc() {
tonyp@3067 750 _markStack.note_end_of_gc();
tonyp@3067 751 }
tonyp@3067 752
tonyp@3067 753 // Verify that there are no CSet oops on the stacks (taskqueues /
tonyp@3067 754 // global mark stack), enqueued SATB buffers, per-thread SATB
tonyp@3067 755 // buffers, and fingers (global / per-task). The boolean parameters
tonyp@3067 756 // decide which of the above data structures to verify. If marking
tonyp@3067 757 // is not in progress, it's a no-op.
tonyp@3067 758 void verify_no_cset_oops(bool verify_stacks,
tonyp@3067 759 bool verify_enqueued_buffers,
tonyp@3067 760 bool verify_thread_buffers,
tonyp@3067 761 bool verify_fingers) PRODUCT_RETURN;
tonyp@3067 762
ysr@342 763 // It is called at the end of an evacuation pause during marking so
ysr@342 764 // that CM is notified of where the new end of the heap is. It
ysr@342 765 // doesn't do anything if concurrent_marking_in_progress() is false,
ysr@342 766 // unless the force parameter is true.
ysr@342 767 void update_g1_committed(bool force = false);
ysr@342 768
ysr@342 769 bool isMarked(oop p) const {
ysr@342 770 assert(p != NULL && p->is_oop(), "expected an oop");
ysr@342 771 HeapWord* addr = (HeapWord*)p;
ysr@342 772 assert(addr >= _nextMarkBitMap->startWord() ||
ysr@342 773 addr < _nextMarkBitMap->endWord(), "in a region");
ysr@342 774
ysr@342 775 return _nextMarkBitMap->isMarked(addr);
ysr@342 776 }
ysr@342 777
ysr@342 778 inline bool not_yet_marked(oop p) const;
ysr@342 779
ysr@342 780 // XXX Debug code
ysr@342 781 bool containing_card_is_marked(void* p);
ysr@342 782 bool containing_cards_are_marked(void* start, void* last);
ysr@342 783
ysr@342 784 bool isPrevMarked(oop p) const {
ysr@342 785 assert(p != NULL && p->is_oop(), "expected an oop");
ysr@342 786 HeapWord* addr = (HeapWord*)p;
ysr@342 787 assert(addr >= _prevMarkBitMap->startWord() ||
ysr@342 788 addr < _prevMarkBitMap->endWord(), "in a region");
ysr@342 789
ysr@342 790 return _prevMarkBitMap->isMarked(addr);
ysr@342 791 }
ysr@342 792
jmasa@3008 793 inline bool do_yield_check(uint worker_i = 0);
ysr@342 794 inline bool should_yield();
ysr@342 795
ysr@342 796 // Called to abort the marking cycle after a Full GC takes palce.
ysr@342 797 void abort();
ysr@342 798
kevinw@4412 799 bool has_aborted() { return _has_aborted; }
kevinw@4412 800
ysr@342 801 // This prints the global/local fingers. It is used for debugging.
ysr@342 802 NOT_PRODUCT(void print_finger();)
ysr@342 803
ysr@342 804 void print_summary_info();
ysr@342 805
tonyp@1019 806 void print_worker_threads_on(outputStream* st) const;
tonyp@1019 807
ysr@342 808 // The following indicate whether a given verbose level has been
ysr@342 809 // set. Notice that anything above stats is conditional to
ysr@342 810 // _MARKING_VERBOSE_ having been set to 1
tonyp@2601 811 bool verbose_stats() {
tonyp@2601 812 return _verbose_level >= stats_verbose;
tonyp@2601 813 }
tonyp@2601 814 bool verbose_low() {
tonyp@2601 815 return _MARKING_VERBOSE_ && _verbose_level >= low_verbose;
tonyp@2601 816 }
tonyp@2601 817 bool verbose_medium() {
tonyp@2601 818 return _MARKING_VERBOSE_ && _verbose_level >= medium_verbose;
tonyp@2601 819 }
tonyp@2601 820 bool verbose_high() {
tonyp@2601 821 return _MARKING_VERBOSE_ && _verbose_level >= high_verbose;
tonyp@2601 822 }
johnc@3119 823
johnc@4050 824 // Liveness counting
johnc@4050 825
johnc@4050 826 // Utility routine to set an exclusive range of cards on the given
johnc@4050 827 // card liveness bitmap
johnc@4050 828 inline void set_card_bitmap_range(BitMap* card_bm,
johnc@4050 829 BitMap::idx_t start_idx,
johnc@4050 830 BitMap::idx_t end_idx,
johnc@4050 831 bool is_par);
johnc@3119 832
johnc@3119 833 // Returns the card number of the bottom of the G1 heap.
johnc@3119 834 // Used in biasing indices into accounting card bitmaps.
johnc@3119 835 intptr_t heap_bottom_card_num() const {
johnc@3119 836 return _heap_bottom_card_num;
johnc@3119 837 }
johnc@3119 838
johnc@3119 839 // Returns the card bitmap for a given task or worker id.
johnc@3119 840 BitMap* count_card_bitmap_for(uint worker_id) {
johnc@3119 841 assert(0 <= worker_id && worker_id < _max_task_num, "oob");
johnc@3119 842 assert(_count_card_bitmaps != NULL, "uninitialized");
johnc@3119 843 BitMap* task_card_bm = &_count_card_bitmaps[worker_id];
johnc@3119 844 assert(task_card_bm->size() == _card_bm.size(), "size mismatch");
johnc@3119 845 return task_card_bm;
johnc@3119 846 }
johnc@3119 847
johnc@3119 848 // Returns the array containing the marked bytes for each region,
johnc@3119 849 // for the given worker or task id.
johnc@3119 850 size_t* count_marked_bytes_array_for(uint worker_id) {
johnc@3119 851 assert(0 <= worker_id && worker_id < _max_task_num, "oob");
johnc@3119 852 assert(_count_marked_bytes != NULL, "uninitialized");
johnc@3119 853 size_t* marked_bytes_array = _count_marked_bytes[worker_id];
johnc@3119 854 assert(marked_bytes_array != NULL, "uninitialized");
johnc@3119 855 return marked_bytes_array;
johnc@3119 856 }
johnc@3119 857
johnc@3119 858 // Returns the index in the liveness accounting card table bitmap
johnc@3119 859 // for the given address
johnc@3119 860 inline BitMap::idx_t card_bitmap_index_for(HeapWord* addr);
johnc@3119 861
johnc@3119 862 // Counts the size of the given memory region in the the given
johnc@3119 863 // marked_bytes array slot for the given HeapRegion.
johnc@3119 864 // Sets the bits in the given card bitmap that are associated with the
johnc@3119 865 // cards that are spanned by the memory region.
johnc@3119 866 inline void count_region(MemRegion mr, HeapRegion* hr,
johnc@3119 867 size_t* marked_bytes_array,
johnc@3119 868 BitMap* task_card_bm);
johnc@3119 869
johnc@3119 870 // Counts the given memory region in the task/worker counting
johnc@3119 871 // data structures for the given worker id.
tonyp@3120 872 inline void count_region(MemRegion mr, HeapRegion* hr, uint worker_id);
tonyp@3120 873
tonyp@3120 874 // Counts the given memory region in the task/worker counting
tonyp@3120 875 // data structures for the given worker id.
johnc@3119 876 inline void count_region(MemRegion mr, uint worker_id);
johnc@3119 877
johnc@3119 878 // Counts the given object in the given task/worker counting
johnc@3119 879 // data structures.
johnc@3119 880 inline void count_object(oop obj, HeapRegion* hr,
johnc@3119 881 size_t* marked_bytes_array,
johnc@3119 882 BitMap* task_card_bm);
johnc@3119 883
johnc@3119 884 // Counts the given object in the task/worker counting data
johnc@3119 885 // structures for the given worker id.
johnc@3119 886 inline void count_object(oop obj, HeapRegion* hr, uint worker_id);
johnc@3119 887
johnc@3119 888 // Attempts to mark the given object and, if successful, counts
johnc@3119 889 // the object in the given task/worker counting structures.
johnc@3119 890 inline bool par_mark_and_count(oop obj, HeapRegion* hr,
johnc@3119 891 size_t* marked_bytes_array,
johnc@3119 892 BitMap* task_card_bm);
johnc@3119 893
johnc@3119 894 // Attempts to mark the given object and, if successful, counts
johnc@3119 895 // the object in the task/worker counting structures for the
johnc@3119 896 // given worker id.
tonyp@3120 897 inline bool par_mark_and_count(oop obj, size_t word_size,
tonyp@3120 898 HeapRegion* hr, uint worker_id);
tonyp@3120 899
tonyp@3120 900 // Attempts to mark the given object and, if successful, counts
tonyp@3120 901 // the object in the task/worker counting structures for the
tonyp@3120 902 // given worker id.
johnc@3119 903 inline bool par_mark_and_count(oop obj, HeapRegion* hr, uint worker_id);
johnc@3119 904
johnc@3119 905 // Similar to the above routine but we don't know the heap region that
johnc@3119 906 // contains the object to be marked/counted, which this routine looks up.
johnc@3119 907 inline bool par_mark_and_count(oop obj, uint worker_id);
johnc@3119 908
johnc@3119 909 // Similar to the above routine but there are times when we cannot
johnc@3119 910 // safely calculate the size of obj due to races and we, therefore,
johnc@3119 911 // pass the size in as a parameter. It is the caller's reponsibility
johnc@3119 912 // to ensure that the size passed in for obj is valid.
johnc@3119 913 inline bool par_mark_and_count(oop obj, size_t word_size, uint worker_id);
johnc@3119 914
johnc@3119 915 // Unconditionally mark the given object, and unconditinally count
johnc@3119 916 // the object in the counting structures for worker id 0.
johnc@3119 917 // Should *not* be called from parallel code.
johnc@3119 918 inline bool mark_and_count(oop obj, HeapRegion* hr);
johnc@3119 919
johnc@3119 920 // Similar to the above routine but we don't know the heap region that
johnc@3119 921 // contains the object to be marked/counted, which this routine looks up.
johnc@3119 922 // Should *not* be called from parallel code.
johnc@3119 923 inline bool mark_and_count(oop obj);
johnc@3119 924
johnc@3119 925 protected:
johnc@3119 926 // Clear all the per-task bitmaps and arrays used to store the
johnc@3119 927 // counting data.
johnc@3119 928 void clear_all_count_data();
johnc@3119 929
johnc@3119 930 // Aggregates the counting data for each worker/task
johnc@3119 931 // that was constructed while marking. Also sets
johnc@3119 932 // the amount of marked bytes for each region and
johnc@3119 933 // the top at concurrent mark count.
johnc@3119 934 void aggregate_count_data();
johnc@3119 935
johnc@3119 936 // Verification routine
johnc@3119 937 void verify_count_data();
ysr@342 938 };
ysr@342 939
ysr@342 940 // A class representing a marking task.
ysr@342 941 class CMTask : public TerminatorTerminator {
ysr@342 942 private:
ysr@342 943 enum PrivateConstants {
ysr@342 944 // the regular clock call is called once the scanned words reaches
ysr@342 945 // this limit
ysr@342 946 words_scanned_period = 12*1024,
ysr@342 947 // the regular clock call is called once the number of visited
ysr@342 948 // references reaches this limit
ysr@342 949 refs_reached_period = 384,
ysr@342 950 // initial value for the hash seed, used in the work stealing code
ysr@342 951 init_hash_seed = 17,
ysr@342 952 // how many entries will be transferred between global stack and
ysr@342 953 // local queues
ysr@342 954 global_stack_transfer_size = 16
ysr@342 955 };
ysr@342 956
ysr@342 957 int _task_id;
ysr@342 958 G1CollectedHeap* _g1h;
ysr@342 959 ConcurrentMark* _cm;
ysr@342 960 CMBitMap* _nextMarkBitMap;
ysr@342 961 // the task queue of this task
ysr@342 962 CMTaskQueue* _task_queue;
ysr@845 963 private:
ysr@342 964 // the task queue set---needed for stealing
ysr@342 965 CMTaskQueueSet* _task_queues;
ysr@342 966 // indicates whether the task has been claimed---this is only for
ysr@342 967 // debugging purposes
ysr@342 968 bool _claimed;
ysr@342 969
ysr@342 970 // number of calls to this task
ysr@342 971 int _calls;
ysr@342 972
ysr@342 973 // when the virtual timer reaches this time, the marking step should
ysr@342 974 // exit
ysr@342 975 double _time_target_ms;
ysr@342 976 // the start time of the current marking step
ysr@342 977 double _start_time_ms;
ysr@342 978
ysr@342 979 // the oop closure used for iterations over oops
tonyp@2596 980 G1CMOopClosure* _cm_oop_closure;
ysr@342 981
ysr@342 982 // the region this task is scanning, NULL if we're not scanning any
ysr@342 983 HeapRegion* _curr_region;
ysr@342 984 // the local finger of this task, NULL if we're not scanning a region
ysr@342 985 HeapWord* _finger;
ysr@342 986 // limit of the region this task is scanning, NULL if we're not scanning one
ysr@342 987 HeapWord* _region_limit;
ysr@342 988
ysr@342 989 // the number of words this task has scanned
ysr@342 990 size_t _words_scanned;
ysr@342 991 // When _words_scanned reaches this limit, the regular clock is
ysr@342 992 // called. Notice that this might be decreased under certain
ysr@342 993 // circumstances (i.e. when we believe that we did an expensive
ysr@342 994 // operation).
ysr@342 995 size_t _words_scanned_limit;
ysr@342 996 // the initial value of _words_scanned_limit (i.e. what it was
ysr@342 997 // before it was decreased).
ysr@342 998 size_t _real_words_scanned_limit;
ysr@342 999
ysr@342 1000 // the number of references this task has visited
ysr@342 1001 size_t _refs_reached;
ysr@342 1002 // When _refs_reached reaches this limit, the regular clock is
ysr@342 1003 // called. Notice this this might be decreased under certain
ysr@342 1004 // circumstances (i.e. when we believe that we did an expensive
ysr@342 1005 // operation).
ysr@342 1006 size_t _refs_reached_limit;
ysr@342 1007 // the initial value of _refs_reached_limit (i.e. what it was before
ysr@342 1008 // it was decreased).
ysr@342 1009 size_t _real_refs_reached_limit;
ysr@342 1010
ysr@342 1011 // used by the work stealing stuff
ysr@342 1012 int _hash_seed;
ysr@342 1013 // if this is true, then the task has aborted for some reason
ysr@342 1014 bool _has_aborted;
ysr@342 1015 // set when the task aborts because it has met its time quota
johnc@2059 1016 bool _has_timed_out;
ysr@342 1017 // true when we're draining SATB buffers; this avoids the task
ysr@342 1018 // aborting due to SATB buffers being available (as we're already
ysr@342 1019 // dealing with them)
ysr@342 1020 bool _draining_satb_buffers;
ysr@342 1021
ysr@342 1022 // number sequence of past step times
ysr@342 1023 NumberSeq _step_times_ms;
ysr@342 1024 // elapsed time of this task
ysr@342 1025 double _elapsed_time_ms;
ysr@342 1026 // termination time of this task
ysr@342 1027 double _termination_time_ms;
ysr@342 1028 // when this task got into the termination protocol
ysr@342 1029 double _termination_start_time_ms;
ysr@342 1030
ysr@342 1031 // true when the task is during a concurrent phase, false when it is
ysr@342 1032 // in the remark phase (so, in the latter case, we do not have to
ysr@342 1033 // check all the things that we have to check during the concurrent
ysr@342 1034 // phase, i.e. SATB buffer availability...)
ysr@342 1035 bool _concurrent;
ysr@342 1036
ysr@342 1037 TruncatedSeq _marking_step_diffs_ms;
ysr@342 1038
johnc@3119 1039 // Counting data structures. Embedding the task's marked_bytes_array
johnc@3119 1040 // and card bitmap into the actual task saves having to go through
johnc@3119 1041 // the ConcurrentMark object.
johnc@3119 1042 size_t* _marked_bytes_array;
johnc@3119 1043 BitMap* _card_bm;
johnc@3119 1044
ysr@342 1045 // LOTS of statistics related with this task
ysr@342 1046 #if _MARKING_STATS_
ysr@342 1047 NumberSeq _all_clock_intervals_ms;
ysr@342 1048 double _interval_start_time_ms;
ysr@342 1049
ysr@342 1050 int _aborted;
ysr@342 1051 int _aborted_overflow;
ysr@342 1052 int _aborted_cm_aborted;
ysr@342 1053 int _aborted_yield;
ysr@342 1054 int _aborted_timed_out;
ysr@342 1055 int _aborted_satb;
ysr@342 1056 int _aborted_termination;
ysr@342 1057
ysr@342 1058 int _steal_attempts;
ysr@342 1059 int _steals;
ysr@342 1060
ysr@342 1061 int _clock_due_to_marking;
ysr@342 1062 int _clock_due_to_scanning;
ysr@342 1063
ysr@342 1064 int _local_pushes;
ysr@342 1065 int _local_pops;
ysr@342 1066 int _local_max_size;
ysr@342 1067 int _objs_scanned;
ysr@342 1068
ysr@342 1069 int _global_pushes;
ysr@342 1070 int _global_pops;
ysr@342 1071 int _global_max_size;
ysr@342 1072
ysr@342 1073 int _global_transfers_to;
ysr@342 1074 int _global_transfers_from;
ysr@342 1075
ysr@342 1076 int _regions_claimed;
ysr@342 1077 int _objs_found_on_bitmap;
ysr@342 1078
ysr@342 1079 int _satb_buffers_processed;
ysr@342 1080 #endif // _MARKING_STATS_
ysr@342 1081
ysr@342 1082 // it updates the local fields after this task has claimed
ysr@342 1083 // a new region to scan
ysr@342 1084 void setup_for_region(HeapRegion* hr);
ysr@342 1085 // it brings up-to-date the limit of the region
ysr@342 1086 void update_region_limit();
ysr@342 1087
ysr@342 1088 // called when either the words scanned or the refs visited limit
ysr@342 1089 // has been reached
ysr@342 1090 void reached_limit();
ysr@342 1091 // recalculates the words scanned and refs visited limits
ysr@342 1092 void recalculate_limits();
ysr@342 1093 // decreases the words scanned and refs visited limits when we reach
ysr@342 1094 // an expensive operation
ysr@342 1095 void decrease_limits();
ysr@342 1096 // it checks whether the words scanned or refs visited reached their
ysr@342 1097 // respective limit and calls reached_limit() if they have
ysr@342 1098 void check_limits() {
ysr@342 1099 if (_words_scanned >= _words_scanned_limit ||
tonyp@2601 1100 _refs_reached >= _refs_reached_limit) {
ysr@342 1101 reached_limit();
tonyp@2601 1102 }
ysr@342 1103 }
ysr@342 1104 // this is supposed to be called regularly during a marking step as
ysr@342 1105 // it checks a bunch of conditions that might cause the marking step
ysr@342 1106 // to abort
ysr@342 1107 void regular_clock_call();
ysr@342 1108 bool concurrent() { return _concurrent; }
ysr@342 1109
ysr@342 1110 public:
ysr@342 1111 // It resets the task; it should be called right at the beginning of
ysr@342 1112 // a marking phase.
ysr@342 1113 void reset(CMBitMap* _nextMarkBitMap);
ysr@342 1114 // it clears all the fields that correspond to a claimed region.
ysr@342 1115 void clear_region_fields();
ysr@342 1116
ysr@342 1117 void set_concurrent(bool concurrent) { _concurrent = concurrent; }
ysr@342 1118
ysr@342 1119 // The main method of this class which performs a marking step
ysr@342 1120 // trying not to exceed the given duration. However, it might exit
ysr@342 1121 // prematurely, according to some conditions (i.e. SATB buffers are
ysr@342 1122 // available for processing).
johnc@4475 1123 void do_marking_step(double target_ms,
johnc@4475 1124 bool do_termination,
johnc@4475 1125 bool is_serial);
ysr@342 1126
ysr@342 1127 // These two calls start and stop the timer
ysr@342 1128 void record_start_time() {
ysr@342 1129 _elapsed_time_ms = os::elapsedTime() * 1000.0;
ysr@342 1130 }
ysr@342 1131 void record_end_time() {
ysr@342 1132 _elapsed_time_ms = os::elapsedTime() * 1000.0 - _elapsed_time_ms;
ysr@342 1133 }
ysr@342 1134
ysr@342 1135 // returns the task ID
ysr@342 1136 int task_id() { return _task_id; }
ysr@342 1137
ysr@342 1138 // From TerminatorTerminator. It determines whether this task should
ysr@342 1139 // exit the termination protocol after it's entered it.
ysr@342 1140 virtual bool should_exit_termination();
ysr@342 1141
johnc@2475 1142 // Resets the local region fields after a task has finished scanning a
johnc@2475 1143 // region; or when they have become stale as a result of the region
johnc@2475 1144 // being evacuated.
johnc@2475 1145 void giveup_current_region();
johnc@2475 1146
ysr@342 1147 HeapWord* finger() { return _finger; }
ysr@342 1148
ysr@342 1149 bool has_aborted() { return _has_aborted; }
ysr@342 1150 void set_has_aborted() { _has_aborted = true; }
ysr@342 1151 void clear_has_aborted() { _has_aborted = false; }
johnc@2059 1152 bool has_timed_out() { return _has_timed_out; }
johnc@2059 1153 bool claimed() { return _claimed; }
ysr@342 1154
tonyp@2596 1155 void set_cm_oop_closure(G1CMOopClosure* cm_oop_closure);
ysr@342 1156
ysr@342 1157 // It grays the object by marking it and, if necessary, pushing it
ysr@342 1158 // on the local queue
tonyp@2596 1159 inline void deal_with_reference(oop obj);
ysr@342 1160
ysr@342 1161 // It scans an object and visits its children.
tonyp@2596 1162 void scan_object(oop obj);
ysr@342 1163
ysr@342 1164 // It pushes an object on the local queue.
tonyp@2596 1165 inline void push(oop obj);
ysr@342 1166
ysr@342 1167 // These two move entries to/from the global stack.
ysr@342 1168 void move_entries_to_global_stack();
ysr@342 1169 void get_entries_from_global_stack();
ysr@342 1170
ysr@342 1171 // It pops and scans objects from the local queue. If partially is
ysr@342 1172 // true, then it stops when the queue size is of a given limit. If
ysr@342 1173 // partially is false, then it stops when the queue is empty.
ysr@342 1174 void drain_local_queue(bool partially);
ysr@342 1175 // It moves entries from the global stack to the local queue and
ysr@342 1176 // drains the local queue. If partially is true, then it stops when
ysr@342 1177 // both the global stack and the local queue reach a given size. If
ysr@342 1178 // partially if false, it tries to empty them totally.
ysr@342 1179 void drain_global_stack(bool partially);
ysr@342 1180 // It keeps picking SATB buffers and processing them until no SATB
ysr@342 1181 // buffers are available.
ysr@342 1182 void drain_satb_buffers();
tonyp@3067 1183
ysr@342 1184 // moves the local finger to a new location
ysr@342 1185 inline void move_finger_to(HeapWord* new_finger) {
tonyp@1023 1186 assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
ysr@342 1187 _finger = new_finger;
ysr@342 1188 }
ysr@342 1189
ysr@342 1190 CMTask(int task_num, ConcurrentMark *cm,
johnc@3119 1191 size_t* marked_bytes, BitMap* card_bm,
ysr@342 1192 CMTaskQueue* task_queue, CMTaskQueueSet* task_queues);
ysr@342 1193
ysr@342 1194 // it prints statistics associated with this task
ysr@342 1195 void print_stats();
ysr@342 1196
ysr@342 1197 #if _MARKING_STATS_
ysr@342 1198 void increase_objs_found_on_bitmap() { ++_objs_found_on_bitmap; }
ysr@342 1199 #endif // _MARKING_STATS_
ysr@342 1200 };
stefank@1879 1201
tonyp@2282 1202 // Class that's used to to print out per-region liveness
tonyp@2282 1203 // information. It's currently used at the end of marking and also
tonyp@2282 1204 // after we sort the old regions at the end of the cleanup operation.
tonyp@2282 1205 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
tonyp@2282 1206 private:
tonyp@2282 1207 outputStream* _out;
tonyp@2282 1208
tonyp@2282 1209 // Accumulators for these values.
tonyp@2282 1210 size_t _total_used_bytes;
tonyp@2282 1211 size_t _total_capacity_bytes;
tonyp@2282 1212 size_t _total_prev_live_bytes;
tonyp@2282 1213 size_t _total_next_live_bytes;
tonyp@2282 1214
tonyp@2282 1215 // These are set up when we come across a "stars humongous" region
tonyp@2282 1216 // (as this is where most of this information is stored, not in the
tonyp@2282 1217 // subsequent "continues humongous" regions). After that, for every
tonyp@2282 1218 // region in a given humongous region series we deduce the right
tonyp@2282 1219 // values for it by simply subtracting the appropriate amount from
tonyp@2282 1220 // these fields. All these values should reach 0 after we've visited
tonyp@2282 1221 // the last region in the series.
tonyp@2282 1222 size_t _hum_used_bytes;
tonyp@2282 1223 size_t _hum_capacity_bytes;
tonyp@2282 1224 size_t _hum_prev_live_bytes;
tonyp@2282 1225 size_t _hum_next_live_bytes;
tonyp@2282 1226
tschatzl@4914 1227 // Accumulator for the remembered set size
tschatzl@4914 1228 size_t _total_remset_bytes;
tschatzl@4914 1229
tonyp@2282 1230 static double perc(size_t val, size_t total) {
tonyp@2282 1231 if (total == 0) {
tonyp@2282 1232 return 0.0;
tonyp@2282 1233 } else {
tonyp@2282 1234 return 100.0 * ((double) val / (double) total);
tonyp@2282 1235 }
tonyp@2282 1236 }
tonyp@2282 1237
tonyp@2282 1238 static double bytes_to_mb(size_t val) {
tonyp@2282 1239 return (double) val / (double) M;
tonyp@2282 1240 }
tonyp@2282 1241
tonyp@2282 1242 // See the .cpp file.
tonyp@2282 1243 size_t get_hum_bytes(size_t* hum_bytes);
tonyp@2282 1244 void get_hum_bytes(size_t* used_bytes, size_t* capacity_bytes,
tonyp@2282 1245 size_t* prev_live_bytes, size_t* next_live_bytes);
tonyp@2282 1246
tonyp@2282 1247 public:
tonyp@2282 1248 // The header and footer are printed in the constructor and
tonyp@2282 1249 // destructor respectively.
tonyp@2282 1250 G1PrintRegionLivenessInfoClosure(outputStream* out, const char* phase_name);
tonyp@2282 1251 virtual bool doHeapRegion(HeapRegion* r);
tonyp@2282 1252 ~G1PrintRegionLivenessInfoClosure();
tonyp@2282 1253 };
tonyp@2282 1254
stefank@1879 1255 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP