annotate src/share/vm/gc_implementation/g1/concurrentMark.hpp @ 3465:d2a62e0f25eb

6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
author zgu
date Thu, 28 Jun 2012 17:03:16 -0400
parents 720b6a76dd9d
children 988bf00cc564
rev   line source
ysr@342 1 /*
tonyp@2981 2 * Copyright (c) 2001, 2012, 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@3465 33 typedef GenericTaskQueue<oop, mtGC> CMTaskQueue;
zgu@3465 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@3256 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@3019 85 inline bool iterate(BitMapClosure* cl, MemRegion mr);
johnc@3019 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@2533 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@2533 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@2533 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@2533 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@2981 162 oop* _base; // bottom of stack
tonyp@2981 163 jint _index; // one more than last occupied index
tonyp@2981 164 jint _capacity; // max #elements
tonyp@2981 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@2981 243 // Record the current index.
tonyp@2981 244 void note_start_of_gc();
tonyp@2981 245
tonyp@2981 246 // Make sure that we have not added any entries to the stack during GC.
tonyp@2981 247 void note_end_of_gc();
tonyp@2981 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@3029 291 class YoungList;
tonyp@3029 292
tonyp@3029 293 // Root Regions are regions that are not empty at the beginning of a
tonyp@3029 294 // marking cycle and which we might collect during an evacuation pause
tonyp@3029 295 // while the cycle is active. Given that, during evacuation pauses, we
tonyp@3029 296 // do not copy objects that are explicitly marked, what we have to do
tonyp@3029 297 // for the root regions is to scan them and mark all objects reachable
tonyp@3029 298 // from them. According to the SATB assumptions, we only need to visit
tonyp@3029 299 // each object once during marking. So, as long as we finish this scan
tonyp@3029 300 // before the next evacuation pause, we can copy the objects from the
tonyp@3029 301 // root regions without having to mark them or do anything else to them.
tonyp@3029 302 //
tonyp@3029 303 // Currently, we only support root region scanning once (at the start
tonyp@3029 304 // of the marking cycle) and the root regions are all the survivor
tonyp@3029 305 // regions populated during the initial-mark pause.
tonyp@3029 306 class CMRootRegions VALUE_OBJ_CLASS_SPEC {
tonyp@3029 307 private:
tonyp@3029 308 YoungList* _young_list;
tonyp@3029 309 ConcurrentMark* _cm;
tonyp@3029 310
tonyp@3029 311 volatile bool _scan_in_progress;
tonyp@3029 312 volatile bool _should_abort;
tonyp@3029 313 HeapRegion* volatile _next_survivor;
tonyp@3029 314
tonyp@3029 315 public:
tonyp@3029 316 CMRootRegions();
tonyp@3029 317 // We actually do most of the initialization in this method.
tonyp@3029 318 void init(G1CollectedHeap* g1h, ConcurrentMark* cm);
tonyp@3029 319
tonyp@3029 320 // Reset the claiming / scanning of the root regions.
tonyp@3029 321 void prepare_for_scan();
tonyp@3029 322
tonyp@3029 323 // Forces get_next() to return NULL so that the iteration aborts early.
tonyp@3029 324 void abort() { _should_abort = true; }
tonyp@3029 325
tonyp@3029 326 // Return true if the CM thread are actively scanning root regions,
tonyp@3029 327 // false otherwise.
tonyp@3029 328 bool scan_in_progress() { return _scan_in_progress; }
tonyp@3029 329
tonyp@3029 330 // Claim the next root region to scan atomically, or return NULL if
tonyp@3029 331 // all have been claimed.
tonyp@3029 332 HeapRegion* claim_next();
tonyp@3029 333
tonyp@3029 334 // Flag that we're done with root region scanning and notify anyone
tonyp@3029 335 // who's waiting on it. If aborted is false, assume that all regions
tonyp@3029 336 // have been claimed.
tonyp@3029 337 void scan_finished();
tonyp@3029 338
tonyp@3029 339 // If CM threads are still scanning root regions, wait until they
tonyp@3029 340 // are done. Return true if we had to wait, false otherwise.
tonyp@3029 341 bool wait_until_scan_finished();
tonyp@3029 342 };
ysr@342 343
ysr@342 344 class ConcurrentMarkThread;
ysr@342 345
zgu@3465 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@2740 355 friend class G1CMRefProcTaskProxy;
johnc@2740 356 friend class G1CMRefProcTaskExecutor;
johnc@2059 357 friend class G1CMParKeepAliveAndDrainClosure;
johnc@2059 358 friend class G1CMParDrainMarkingStackClosure;
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@2922 363 uint _parallel_marking_threads; // the number of marking
jmasa@2859 364 // threads we're use
jmasa@2922 365 uint _max_parallel_marking_threads; // max number of marking
jmasa@2859 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@3020 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@3029 392 // Root region tracking and claiming.
tonyp@3029 393 CMRootRegions _root_regions;
tonyp@3029 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@2922 402 uint _max_task_num; // maximum task number
jmasa@2922 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@2859 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();
ysr@342 464 // It resets all the marking data structures.
tonyp@2413 465 void clear_marking_state(bool clear_overflow = true);
ysr@342 466
ysr@342 467 // It should be called to indicate which phase we're in (concurrent
ysr@342 468 // mark or remark) and how many threads are currently active.
jmasa@2922 469 void set_phase(uint active_tasks, bool concurrent);
ysr@342 470 // We do this after we're done with marking so that the marking data
ysr@342 471 // structures are initialised to a sensible and predictable state.
ysr@342 472 void set_non_marking_state();
ysr@342 473
ysr@342 474 // prints all gathered CM-related statistics
ysr@342 475 void print_stats();
ysr@342 476
tonyp@2037 477 bool cleanup_list_is_empty() {
tonyp@2037 478 return _cleanup_list.is_empty();
tonyp@2037 479 }
tonyp@2037 480
ysr@342 481 // accessor methods
jmasa@2922 482 uint parallel_marking_threads() { return _parallel_marking_threads; }
jmasa@2922 483 uint max_parallel_marking_threads() { return _max_parallel_marking_threads;}
ysr@342 484 double sleep_factor() { return _sleep_factor; }
ysr@342 485 double marking_task_overhead() { return _marking_task_overhead;}
ysr@342 486 double cleanup_sleep_factor() { return _cleanup_sleep_factor; }
ysr@342 487 double cleanup_task_overhead() { return _cleanup_task_overhead;}
ysr@342 488
ysr@342 489 HeapWord* finger() { return _finger; }
ysr@342 490 bool concurrent() { return _concurrent; }
jmasa@2922 491 uint active_tasks() { return _active_tasks; }
ysr@342 492 ParallelTaskTerminator* terminator() { return &_terminator; }
ysr@342 493
ysr@342 494 // It claims the next available region to be scanned by a marking
ysr@342 495 // task. It might return NULL if the next region is empty or we have
ysr@342 496 // run out of regions. In the latter case, out_of_regions()
ysr@342 497 // determines whether we've really run out of regions or the task
ysr@342 498 // should call claim_region() again. This might seem a bit
ysr@342 499 // awkward. Originally, the code was written so that claim_region()
ysr@342 500 // either successfully returned with a non-empty region or there
ysr@342 501 // were no more regions to be claimed. The problem with this was
ysr@342 502 // that, in certain circumstances, it iterated over large chunks of
ysr@342 503 // the heap finding only empty regions and, while it was working, it
ysr@342 504 // was preventing the calling task to call its regular clock
ysr@342 505 // method. So, this way, each task will spend very little time in
ysr@342 506 // claim_region() and is allowed to call the regular clock method
ysr@342 507 // frequently.
ysr@342 508 HeapRegion* claim_region(int task);
ysr@342 509
ysr@342 510 // It determines whether we've run out of regions to scan.
ysr@342 511 bool out_of_regions() { return _finger == _heap_end; }
ysr@342 512
ysr@342 513 // Returns the task with the given id
ysr@342 514 CMTask* task(int id) {
tonyp@1023 515 assert(0 <= id && id < (int) _active_tasks,
tonyp@1023 516 "task id not within active bounds");
ysr@342 517 return _tasks[id];
ysr@342 518 }
ysr@342 519
ysr@342 520 // Returns the task queue with the given id
ysr@342 521 CMTaskQueue* task_queue(int id) {
tonyp@1023 522 assert(0 <= id && id < (int) _active_tasks,
tonyp@1023 523 "task queue id not within active bounds");
ysr@342 524 return (CMTaskQueue*) _task_queues->queue(id);
ysr@342 525 }
ysr@342 526
ysr@342 527 // Returns the task queue set
ysr@342 528 CMTaskQueueSet* task_queues() { return _task_queues; }
ysr@342 529
ysr@342 530 // Access / manipulation of the overflow flag which is set to
tonyp@3256 531 // indicate that the global stack has overflown
ysr@342 532 bool has_overflown() { return _has_overflown; }
ysr@342 533 void set_has_overflown() { _has_overflown = true; }
ysr@342 534 void clear_has_overflown() { _has_overflown = false; }
tonyp@3029 535 bool restart_for_overflow() { return _restart_for_overflow; }
ysr@342 536
ysr@342 537 bool has_aborted() { return _has_aborted; }
ysr@342 538
ysr@342 539 // Methods to enter the two overflow sync barriers
ysr@342 540 void enter_first_sync_barrier(int task_num);
ysr@342 541 void enter_second_sync_barrier(int task_num);
ysr@342 542
tonyp@2413 543 ForceOverflowSettings* force_overflow_conc() {
tonyp@2413 544 return &_force_overflow_conc;
tonyp@2413 545 }
tonyp@2413 546
tonyp@2413 547 ForceOverflowSettings* force_overflow_stw() {
tonyp@2413 548 return &_force_overflow_stw;
tonyp@2413 549 }
tonyp@2413 550
tonyp@2413 551 ForceOverflowSettings* force_overflow() {
tonyp@2413 552 if (concurrent()) {
tonyp@2413 553 return force_overflow_conc();
tonyp@2413 554 } else {
tonyp@2413 555 return force_overflow_stw();
tonyp@2413 556 }
tonyp@2413 557 }
tonyp@2413 558
johnc@3028 559 // Live Data Counting data structures...
johnc@3028 560 // These data structures are initialized at the start of
johnc@3028 561 // marking. They are written to while marking is active.
johnc@3028 562 // They are aggregated during remark; the aggregated values
johnc@3028 563 // are then used to populate the _region_bm, _card_bm, and
johnc@3028 564 // the total live bytes, which are then subsequently updated
johnc@3028 565 // during cleanup.
johnc@3028 566
johnc@3028 567 // An array of bitmaps (one bit map per task). Each bitmap
johnc@3028 568 // is used to record the cards spanned by the live objects
johnc@3028 569 // marked by that task/worker.
johnc@3028 570 BitMap* _count_card_bitmaps;
johnc@3028 571
johnc@3028 572 // Used to record the number of marked live bytes
johnc@3028 573 // (for each region, by worker thread).
johnc@3028 574 size_t** _count_marked_bytes;
johnc@3028 575
johnc@3028 576 // Card index of the bottom of the G1 heap. Used for biasing indices into
johnc@3028 577 // the card bitmaps.
johnc@3028 578 intptr_t _heap_bottom_card_num;
johnc@3028 579
ysr@342 580 public:
ysr@342 581 // Manipulation of the global mark stack.
ysr@342 582 // Notice that the first mark_stack_push is CAS-based, whereas the
ysr@342 583 // two below are Mutex-based. This is OK since the first one is only
ysr@342 584 // called during evacuation pauses and doesn't compete with the
ysr@342 585 // other two (which are called by the marking tasks during
ysr@342 586 // concurrent marking or remark).
ysr@342 587 bool mark_stack_push(oop p) {
ysr@342 588 _markStack.par_push(p);
ysr@342 589 if (_markStack.overflow()) {
ysr@342 590 set_has_overflown();
ysr@342 591 return false;
ysr@342 592 }
ysr@342 593 return true;
ysr@342 594 }
ysr@342 595 bool mark_stack_push(oop* arr, int n) {
ysr@342 596 _markStack.par_push_arr(arr, n);
ysr@342 597 if (_markStack.overflow()) {
ysr@342 598 set_has_overflown();
ysr@342 599 return false;
ysr@342 600 }
ysr@342 601 return true;
ysr@342 602 }
ysr@342 603 void mark_stack_pop(oop* arr, int max, int* n) {
ysr@342 604 _markStack.par_pop_arr(arr, max, n);
ysr@342 605 }
tonyp@2538 606 size_t mark_stack_size() { return _markStack.size(); }
ysr@342 607 size_t partial_mark_stack_size_target() { return _markStack.maxElems()/3; }
tonyp@2538 608 bool mark_stack_overflow() { return _markStack.overflow(); }
tonyp@2538 609 bool mark_stack_empty() { return _markStack.isEmpty(); }
ysr@342 610
tonyp@3029 611 CMRootRegions* root_regions() { return &_root_regions; }
tonyp@3029 612
ysr@342 613 bool concurrent_marking_in_progress() {
ysr@342 614 return _concurrent_marking_in_progress;
ysr@342 615 }
ysr@342 616 void set_concurrent_marking_in_progress() {
ysr@342 617 _concurrent_marking_in_progress = true;
ysr@342 618 }
ysr@342 619 void clear_concurrent_marking_in_progress() {
ysr@342 620 _concurrent_marking_in_progress = false;
ysr@342 621 }
ysr@342 622
ysr@342 623 void update_accum_task_vtime(int i, double vtime) {
ysr@342 624 _accum_task_vtime[i] += vtime;
ysr@342 625 }
ysr@342 626
ysr@342 627 double all_task_accum_vtime() {
ysr@342 628 double ret = 0.0;
ysr@342 629 for (int i = 0; i < (int)_max_task_num; ++i)
ysr@342 630 ret += _accum_task_vtime[i];
ysr@342 631 return ret;
ysr@342 632 }
ysr@342 633
ysr@342 634 // Attempts to steal an object from the task queues of other tasks
ysr@342 635 bool try_stealing(int task_num, int* hash_seed, oop& obj) {
ysr@342 636 return _task_queues->steal(task_num, hash_seed, obj);
ysr@342 637 }
ysr@342 638
tonyp@3278 639 ConcurrentMark(ReservedSpace rs, uint max_regions);
ysr@342 640 ~ConcurrentMark();
johnc@3028 641
ysr@342 642 ConcurrentMarkThread* cmThread() { return _cmThread; }
ysr@342 643
ysr@342 644 CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
ysr@342 645 CMBitMap* nextMarkBitMap() const { return _nextMarkBitMap; }
ysr@342 646
jmasa@2859 647 // Returns the number of GC threads to be used in a concurrent
jmasa@2859 648 // phase based on the number of GC threads being used in a STW
jmasa@2859 649 // phase.
jmasa@2922 650 uint scale_parallel_threads(uint n_par_threads);
jmasa@2859 651
jmasa@2859 652 // Calculates the number of GC threads to be used in a concurrent phase.
jmasa@2922 653 uint calc_parallel_marking_threads();
jmasa@2859 654
ysr@342 655 // The following three are interaction between CM and
ysr@342 656 // G1CollectedHeap
ysr@342 657
ysr@342 658 // This notifies CM that a root during initial-mark needs to be
tonyp@3029 659 // grayed. It is MT-safe. word_size is the size of the object in
tonyp@3029 660 // words. It is passed explicitly as sometimes we cannot calculate
tonyp@3029 661 // it from the given object because it might be in an inconsistent
tonyp@3029 662 // state (e.g., in to-space and being copied). So the caller is
tonyp@3029 663 // responsible for dealing with this issue (e.g., get the size from
tonyp@3029 664 // the from-space image when the to-space image might be
tonyp@3029 665 // inconsistent) and always passing the size. hr is the region that
tonyp@3029 666 // contains the object and it's passed optionally from callers who
tonyp@3029 667 // might already have it (no point in recalculating it).
tonyp@3029 668 inline void grayRoot(oop obj, size_t word_size,
tonyp@3029 669 uint worker_id, HeapRegion* hr = NULL);
tonyp@2981 670
tonyp@1388 671 // It iterates over the heap and for each object it comes across it
tonyp@1388 672 // will dump the contents of its reference fields, as well as
tonyp@1388 673 // liveness information for the object and its referents. The dump
tonyp@1388 674 // will be written to a file with the following name:
johnc@2534 675 // G1PrintReachableBaseFile + "." + str.
johnc@2534 676 // vo decides whether the prev (vo == UsePrevMarking), the next
johnc@2534 677 // (vo == UseNextMarking) marking information, or the mark word
johnc@2534 678 // (vo == UseMarkWord) will be used to determine the liveness of
johnc@2534 679 // each object / referent.
johnc@2534 680 // If all is true, all objects in the heap will be dumped, otherwise
johnc@2534 681 // only the live ones. In the dump the following symbols / breviations
johnc@2534 682 // are used:
tonyp@1388 683 // M : an explicitly live object (its bitmap bit is set)
tonyp@1388 684 // > : an implicitly live object (over tams)
tonyp@1388 685 // O : an object outside the G1 heap (typically: in the perm gen)
tonyp@1388 686 // NOT : a reference field whose referent is not live
tonyp@1388 687 // AND MARKED : indicates that an object is both explicitly and
tonyp@1388 688 // implicitly live (it should be one or the other, not both)
tonyp@1388 689 void print_reachable(const char* str,
johnc@2534 690 VerifyOption vo, bool all) PRODUCT_RETURN;
ysr@342 691
ysr@342 692 // Clear the next marking bitmap (will be called concurrently).
ysr@342 693 void clearNextBitmap();
ysr@342 694
ysr@342 695 // These two do the work that needs to be done before and after the
ysr@342 696 // initial root checkpoint. Since this checkpoint can be done at two
ysr@342 697 // different points (i.e. an explicit pause or piggy-backed on a
ysr@342 698 // young collection), then it's nice to be able to easily share the
ysr@342 699 // pre/post code. It might be the case that we can put everything in
ysr@342 700 // the post method. TP
ysr@342 701 void checkpointRootsInitialPre();
ysr@342 702 void checkpointRootsInitialPost();
ysr@342 703
tonyp@3029 704 // Scan all the root regions and mark everything reachable from
tonyp@3029 705 // them.
tonyp@3029 706 void scanRootRegions();
tonyp@3029 707
tonyp@3029 708 // Scan a single root region and mark everything reachable from it.
tonyp@3029 709 void scanRootRegion(HeapRegion* hr, uint worker_id);
tonyp@3029 710
ysr@342 711 // Do concurrent phase of marking, to a tentative transitive closure.
ysr@342 712 void markFromRoots();
ysr@342 713
ysr@342 714 void checkpointRootsFinal(bool clear_all_soft_refs);
ysr@342 715 void checkpointRootsFinalWork();
ysr@342 716 void cleanup();
ysr@342 717 void completeCleanup();
ysr@342 718
ysr@342 719 // Mark in the previous bitmap. NB: this is usually read-only, so use
ysr@342 720 // this carefully!
tonyp@2981 721 inline void markPrev(oop p);
johnc@3028 722
tonyp@2981 723 // Clears marks for all objects in the given range, for the prev,
tonyp@2981 724 // next, or both bitmaps. NB: the previous bitmap is usually
tonyp@2981 725 // read-only, so use this carefully!
tonyp@2981 726 void clearRangePrevBitmap(MemRegion mr);
tonyp@2981 727 void clearRangeNextBitmap(MemRegion mr);
tonyp@2981 728 void clearRangeBothBitmaps(MemRegion mr);
ysr@342 729
tonyp@2981 730 // Notify data structures that a GC has started.
tonyp@2981 731 void note_start_of_gc() {
tonyp@2981 732 _markStack.note_start_of_gc();
ysr@342 733 }
tonyp@2981 734
tonyp@2981 735 // Notify data structures that a GC is finished.
tonyp@2981 736 void note_end_of_gc() {
tonyp@2981 737 _markStack.note_end_of_gc();
tonyp@2981 738 }
tonyp@2981 739
tonyp@2981 740 // Verify that there are no CSet oops on the stacks (taskqueues /
tonyp@2981 741 // global mark stack), enqueued SATB buffers, per-thread SATB
tonyp@2981 742 // buffers, and fingers (global / per-task). The boolean parameters
tonyp@2981 743 // decide which of the above data structures to verify. If marking
tonyp@2981 744 // is not in progress, it's a no-op.
tonyp@2981 745 void verify_no_cset_oops(bool verify_stacks,
tonyp@2981 746 bool verify_enqueued_buffers,
tonyp@2981 747 bool verify_thread_buffers,
tonyp@2981 748 bool verify_fingers) PRODUCT_RETURN;
tonyp@2981 749
ysr@342 750 // It is called at the end of an evacuation pause during marking so
ysr@342 751 // that CM is notified of where the new end of the heap is. It
ysr@342 752 // doesn't do anything if concurrent_marking_in_progress() is false,
ysr@342 753 // unless the force parameter is true.
ysr@342 754 void update_g1_committed(bool force = false);
ysr@342 755
ysr@342 756 bool isMarked(oop p) const {
ysr@342 757 assert(p != NULL && p->is_oop(), "expected an oop");
ysr@342 758 HeapWord* addr = (HeapWord*)p;
ysr@342 759 assert(addr >= _nextMarkBitMap->startWord() ||
ysr@342 760 addr < _nextMarkBitMap->endWord(), "in a region");
ysr@342 761
ysr@342 762 return _nextMarkBitMap->isMarked(addr);
ysr@342 763 }
ysr@342 764
ysr@342 765 inline bool not_yet_marked(oop p) const;
ysr@342 766
ysr@342 767 // XXX Debug code
ysr@342 768 bool containing_card_is_marked(void* p);
ysr@342 769 bool containing_cards_are_marked(void* start, void* last);
ysr@342 770
ysr@342 771 bool isPrevMarked(oop p) const {
ysr@342 772 assert(p != NULL && p->is_oop(), "expected an oop");
ysr@342 773 HeapWord* addr = (HeapWord*)p;
ysr@342 774 assert(addr >= _prevMarkBitMap->startWord() ||
ysr@342 775 addr < _prevMarkBitMap->endWord(), "in a region");
ysr@342 776
ysr@342 777 return _prevMarkBitMap->isMarked(addr);
ysr@342 778 }
ysr@342 779
jmasa@2922 780 inline bool do_yield_check(uint worker_i = 0);
ysr@342 781 inline bool should_yield();
ysr@342 782
ysr@342 783 // Called to abort the marking cycle after a Full GC takes palce.
ysr@342 784 void abort();
ysr@342 785
ysr@342 786 // This prints the global/local fingers. It is used for debugging.
ysr@342 787 NOT_PRODUCT(void print_finger();)
ysr@342 788
ysr@342 789 void print_summary_info();
ysr@342 790
tonyp@1019 791 void print_worker_threads_on(outputStream* st) const;
tonyp@1019 792
ysr@342 793 // The following indicate whether a given verbose level has been
ysr@342 794 // set. Notice that anything above stats is conditional to
ysr@342 795 // _MARKING_VERBOSE_ having been set to 1
tonyp@2538 796 bool verbose_stats() {
tonyp@2538 797 return _verbose_level >= stats_verbose;
tonyp@2538 798 }
tonyp@2538 799 bool verbose_low() {
tonyp@2538 800 return _MARKING_VERBOSE_ && _verbose_level >= low_verbose;
tonyp@2538 801 }
tonyp@2538 802 bool verbose_medium() {
tonyp@2538 803 return _MARKING_VERBOSE_ && _verbose_level >= medium_verbose;
tonyp@2538 804 }
tonyp@2538 805 bool verbose_high() {
tonyp@2538 806 return _MARKING_VERBOSE_ && _verbose_level >= high_verbose;
tonyp@2538 807 }
johnc@3028 808
johnc@3028 809 // Counting data structure accessors
johnc@3028 810
johnc@3028 811 // Returns the card number of the bottom of the G1 heap.
johnc@3028 812 // Used in biasing indices into accounting card bitmaps.
johnc@3028 813 intptr_t heap_bottom_card_num() const {
johnc@3028 814 return _heap_bottom_card_num;
johnc@3028 815 }
johnc@3028 816
johnc@3028 817 // Returns the card bitmap for a given task or worker id.
johnc@3028 818 BitMap* count_card_bitmap_for(uint worker_id) {
johnc@3028 819 assert(0 <= worker_id && worker_id < _max_task_num, "oob");
johnc@3028 820 assert(_count_card_bitmaps != NULL, "uninitialized");
johnc@3028 821 BitMap* task_card_bm = &_count_card_bitmaps[worker_id];
johnc@3028 822 assert(task_card_bm->size() == _card_bm.size(), "size mismatch");
johnc@3028 823 return task_card_bm;
johnc@3028 824 }
johnc@3028 825
johnc@3028 826 // Returns the array containing the marked bytes for each region,
johnc@3028 827 // for the given worker or task id.
johnc@3028 828 size_t* count_marked_bytes_array_for(uint worker_id) {
johnc@3028 829 assert(0 <= worker_id && worker_id < _max_task_num, "oob");
johnc@3028 830 assert(_count_marked_bytes != NULL, "uninitialized");
johnc@3028 831 size_t* marked_bytes_array = _count_marked_bytes[worker_id];
johnc@3028 832 assert(marked_bytes_array != NULL, "uninitialized");
johnc@3028 833 return marked_bytes_array;
johnc@3028 834 }
johnc@3028 835
johnc@3028 836 // Returns the index in the liveness accounting card table bitmap
johnc@3028 837 // for the given address
johnc@3028 838 inline BitMap::idx_t card_bitmap_index_for(HeapWord* addr);
johnc@3028 839
johnc@3028 840 // Counts the size of the given memory region in the the given
johnc@3028 841 // marked_bytes array slot for the given HeapRegion.
johnc@3028 842 // Sets the bits in the given card bitmap that are associated with the
johnc@3028 843 // cards that are spanned by the memory region.
johnc@3028 844 inline void count_region(MemRegion mr, HeapRegion* hr,
johnc@3028 845 size_t* marked_bytes_array,
johnc@3028 846 BitMap* task_card_bm);
johnc@3028 847
johnc@3028 848 // Counts the given memory region in the task/worker counting
johnc@3028 849 // data structures for the given worker id.
tonyp@3029 850 inline void count_region(MemRegion mr, HeapRegion* hr, uint worker_id);
tonyp@3029 851
tonyp@3029 852 // Counts the given memory region in the task/worker counting
tonyp@3029 853 // data structures for the given worker id.
johnc@3028 854 inline void count_region(MemRegion mr, uint worker_id);
johnc@3028 855
johnc@3028 856 // Counts the given object in the given task/worker counting
johnc@3028 857 // data structures.
johnc@3028 858 inline void count_object(oop obj, HeapRegion* hr,
johnc@3028 859 size_t* marked_bytes_array,
johnc@3028 860 BitMap* task_card_bm);
johnc@3028 861
johnc@3028 862 // Counts the given object in the task/worker counting data
johnc@3028 863 // structures for the given worker id.
johnc@3028 864 inline void count_object(oop obj, HeapRegion* hr, uint worker_id);
johnc@3028 865
johnc@3028 866 // Attempts to mark the given object and, if successful, counts
johnc@3028 867 // the object in the given task/worker counting structures.
johnc@3028 868 inline bool par_mark_and_count(oop obj, HeapRegion* hr,
johnc@3028 869 size_t* marked_bytes_array,
johnc@3028 870 BitMap* task_card_bm);
johnc@3028 871
johnc@3028 872 // Attempts to mark the given object and, if successful, counts
johnc@3028 873 // the object in the task/worker counting structures for the
johnc@3028 874 // given worker id.
tonyp@3029 875 inline bool par_mark_and_count(oop obj, size_t word_size,
tonyp@3029 876 HeapRegion* hr, uint worker_id);
tonyp@3029 877
tonyp@3029 878 // Attempts to mark the given object and, if successful, counts
tonyp@3029 879 // the object in the task/worker counting structures for the
tonyp@3029 880 // given worker id.
johnc@3028 881 inline bool par_mark_and_count(oop obj, HeapRegion* hr, uint worker_id);
johnc@3028 882
johnc@3028 883 // Similar to the above routine but we don't know the heap region that
johnc@3028 884 // contains the object to be marked/counted, which this routine looks up.
johnc@3028 885 inline bool par_mark_and_count(oop obj, uint worker_id);
johnc@3028 886
johnc@3028 887 // Similar to the above routine but there are times when we cannot
johnc@3028 888 // safely calculate the size of obj due to races and we, therefore,
johnc@3028 889 // pass the size in as a parameter. It is the caller's reponsibility
johnc@3028 890 // to ensure that the size passed in for obj is valid.
johnc@3028 891 inline bool par_mark_and_count(oop obj, size_t word_size, uint worker_id);
johnc@3028 892
johnc@3028 893 // Unconditionally mark the given object, and unconditinally count
johnc@3028 894 // the object in the counting structures for worker id 0.
johnc@3028 895 // Should *not* be called from parallel code.
johnc@3028 896 inline bool mark_and_count(oop obj, HeapRegion* hr);
johnc@3028 897
johnc@3028 898 // Similar to the above routine but we don't know the heap region that
johnc@3028 899 // contains the object to be marked/counted, which this routine looks up.
johnc@3028 900 // Should *not* be called from parallel code.
johnc@3028 901 inline bool mark_and_count(oop obj);
johnc@3028 902
johnc@3028 903 protected:
johnc@3028 904 // Clear all the per-task bitmaps and arrays used to store the
johnc@3028 905 // counting data.
johnc@3028 906 void clear_all_count_data();
johnc@3028 907
johnc@3028 908 // Aggregates the counting data for each worker/task
johnc@3028 909 // that was constructed while marking. Also sets
johnc@3028 910 // the amount of marked bytes for each region and
johnc@3028 911 // the top at concurrent mark count.
johnc@3028 912 void aggregate_count_data();
johnc@3028 913
johnc@3028 914 // Verification routine
johnc@3028 915 void verify_count_data();
ysr@342 916 };
ysr@342 917
ysr@342 918 // A class representing a marking task.
ysr@342 919 class CMTask : public TerminatorTerminator {
ysr@342 920 private:
ysr@342 921 enum PrivateConstants {
ysr@342 922 // the regular clock call is called once the scanned words reaches
ysr@342 923 // this limit
ysr@342 924 words_scanned_period = 12*1024,
ysr@342 925 // the regular clock call is called once the number of visited
ysr@342 926 // references reaches this limit
ysr@342 927 refs_reached_period = 384,
ysr@342 928 // initial value for the hash seed, used in the work stealing code
ysr@342 929 init_hash_seed = 17,
ysr@342 930 // how many entries will be transferred between global stack and
ysr@342 931 // local queues
ysr@342 932 global_stack_transfer_size = 16
ysr@342 933 };
ysr@342 934
ysr@342 935 int _task_id;
ysr@342 936 G1CollectedHeap* _g1h;
ysr@342 937 ConcurrentMark* _cm;
ysr@342 938 CMBitMap* _nextMarkBitMap;
ysr@342 939 // the task queue of this task
ysr@342 940 CMTaskQueue* _task_queue;
ysr@845 941 private:
ysr@342 942 // the task queue set---needed for stealing
ysr@342 943 CMTaskQueueSet* _task_queues;
ysr@342 944 // indicates whether the task has been claimed---this is only for
ysr@342 945 // debugging purposes
ysr@342 946 bool _claimed;
ysr@342 947
ysr@342 948 // number of calls to this task
ysr@342 949 int _calls;
ysr@342 950
ysr@342 951 // when the virtual timer reaches this time, the marking step should
ysr@342 952 // exit
ysr@342 953 double _time_target_ms;
ysr@342 954 // the start time of the current marking step
ysr@342 955 double _start_time_ms;
ysr@342 956
ysr@342 957 // the oop closure used for iterations over oops
tonyp@2533 958 G1CMOopClosure* _cm_oop_closure;
ysr@342 959
ysr@342 960 // the region this task is scanning, NULL if we're not scanning any
ysr@342 961 HeapRegion* _curr_region;
ysr@342 962 // the local finger of this task, NULL if we're not scanning a region
ysr@342 963 HeapWord* _finger;
ysr@342 964 // limit of the region this task is scanning, NULL if we're not scanning one
ysr@342 965 HeapWord* _region_limit;
ysr@342 966
ysr@342 967 // the number of words this task has scanned
ysr@342 968 size_t _words_scanned;
ysr@342 969 // When _words_scanned reaches this limit, the regular clock is
ysr@342 970 // called. Notice that this might be decreased under certain
ysr@342 971 // circumstances (i.e. when we believe that we did an expensive
ysr@342 972 // operation).
ysr@342 973 size_t _words_scanned_limit;
ysr@342 974 // the initial value of _words_scanned_limit (i.e. what it was
ysr@342 975 // before it was decreased).
ysr@342 976 size_t _real_words_scanned_limit;
ysr@342 977
ysr@342 978 // the number of references this task has visited
ysr@342 979 size_t _refs_reached;
ysr@342 980 // When _refs_reached reaches this limit, the regular clock is
ysr@342 981 // called. Notice this this might be decreased under certain
ysr@342 982 // circumstances (i.e. when we believe that we did an expensive
ysr@342 983 // operation).
ysr@342 984 size_t _refs_reached_limit;
ysr@342 985 // the initial value of _refs_reached_limit (i.e. what it was before
ysr@342 986 // it was decreased).
ysr@342 987 size_t _real_refs_reached_limit;
ysr@342 988
ysr@342 989 // used by the work stealing stuff
ysr@342 990 int _hash_seed;
ysr@342 991 // if this is true, then the task has aborted for some reason
ysr@342 992 bool _has_aborted;
ysr@342 993 // set when the task aborts because it has met its time quota
johnc@2059 994 bool _has_timed_out;
ysr@342 995 // true when we're draining SATB buffers; this avoids the task
ysr@342 996 // aborting due to SATB buffers being available (as we're already
ysr@342 997 // dealing with them)
ysr@342 998 bool _draining_satb_buffers;
ysr@342 999
ysr@342 1000 // number sequence of past step times
ysr@342 1001 NumberSeq _step_times_ms;
ysr@342 1002 // elapsed time of this task
ysr@342 1003 double _elapsed_time_ms;
ysr@342 1004 // termination time of this task
ysr@342 1005 double _termination_time_ms;
ysr@342 1006 // when this task got into the termination protocol
ysr@342 1007 double _termination_start_time_ms;
ysr@342 1008
ysr@342 1009 // true when the task is during a concurrent phase, false when it is
ysr@342 1010 // in the remark phase (so, in the latter case, we do not have to
ysr@342 1011 // check all the things that we have to check during the concurrent
ysr@342 1012 // phase, i.e. SATB buffer availability...)
ysr@342 1013 bool _concurrent;
ysr@342 1014
ysr@342 1015 TruncatedSeq _marking_step_diffs_ms;
ysr@342 1016
johnc@3028 1017 // Counting data structures. Embedding the task's marked_bytes_array
johnc@3028 1018 // and card bitmap into the actual task saves having to go through
johnc@3028 1019 // the ConcurrentMark object.
johnc@3028 1020 size_t* _marked_bytes_array;
johnc@3028 1021 BitMap* _card_bm;
johnc@3028 1022
ysr@342 1023 // LOTS of statistics related with this task
ysr@342 1024 #if _MARKING_STATS_
ysr@342 1025 NumberSeq _all_clock_intervals_ms;
ysr@342 1026 double _interval_start_time_ms;
ysr@342 1027
ysr@342 1028 int _aborted;
ysr@342 1029 int _aborted_overflow;
ysr@342 1030 int _aborted_cm_aborted;
ysr@342 1031 int _aborted_yield;
ysr@342 1032 int _aborted_timed_out;
ysr@342 1033 int _aborted_satb;
ysr@342 1034 int _aborted_termination;
ysr@342 1035
ysr@342 1036 int _steal_attempts;
ysr@342 1037 int _steals;
ysr@342 1038
ysr@342 1039 int _clock_due_to_marking;
ysr@342 1040 int _clock_due_to_scanning;
ysr@342 1041
ysr@342 1042 int _local_pushes;
ysr@342 1043 int _local_pops;
ysr@342 1044 int _local_max_size;
ysr@342 1045 int _objs_scanned;
ysr@342 1046
ysr@342 1047 int _global_pushes;
ysr@342 1048 int _global_pops;
ysr@342 1049 int _global_max_size;
ysr@342 1050
ysr@342 1051 int _global_transfers_to;
ysr@342 1052 int _global_transfers_from;
ysr@342 1053
ysr@342 1054 int _regions_claimed;
ysr@342 1055 int _objs_found_on_bitmap;
ysr@342 1056
ysr@342 1057 int _satb_buffers_processed;
ysr@342 1058 #endif // _MARKING_STATS_
ysr@342 1059
ysr@342 1060 // it updates the local fields after this task has claimed
ysr@342 1061 // a new region to scan
ysr@342 1062 void setup_for_region(HeapRegion* hr);
ysr@342 1063 // it brings up-to-date the limit of the region
ysr@342 1064 void update_region_limit();
ysr@342 1065
ysr@342 1066 // called when either the words scanned or the refs visited limit
ysr@342 1067 // has been reached
ysr@342 1068 void reached_limit();
ysr@342 1069 // recalculates the words scanned and refs visited limits
ysr@342 1070 void recalculate_limits();
ysr@342 1071 // decreases the words scanned and refs visited limits when we reach
ysr@342 1072 // an expensive operation
ysr@342 1073 void decrease_limits();
ysr@342 1074 // it checks whether the words scanned or refs visited reached their
ysr@342 1075 // respective limit and calls reached_limit() if they have
ysr@342 1076 void check_limits() {
ysr@342 1077 if (_words_scanned >= _words_scanned_limit ||
tonyp@2538 1078 _refs_reached >= _refs_reached_limit) {
ysr@342 1079 reached_limit();
tonyp@2538 1080 }
ysr@342 1081 }
ysr@342 1082 // this is supposed to be called regularly during a marking step as
ysr@342 1083 // it checks a bunch of conditions that might cause the marking step
ysr@342 1084 // to abort
ysr@342 1085 void regular_clock_call();
ysr@342 1086 bool concurrent() { return _concurrent; }
ysr@342 1087
ysr@342 1088 public:
ysr@342 1089 // It resets the task; it should be called right at the beginning of
ysr@342 1090 // a marking phase.
ysr@342 1091 void reset(CMBitMap* _nextMarkBitMap);
ysr@342 1092 // it clears all the fields that correspond to a claimed region.
ysr@342 1093 void clear_region_fields();
ysr@342 1094
ysr@342 1095 void set_concurrent(bool concurrent) { _concurrent = concurrent; }
ysr@342 1096
ysr@342 1097 // The main method of this class which performs a marking step
ysr@342 1098 // trying not to exceed the given duration. However, it might exit
ysr@342 1099 // prematurely, according to some conditions (i.e. SATB buffers are
ysr@342 1100 // available for processing).
johnc@2059 1101 void do_marking_step(double target_ms, bool do_stealing, bool do_termination);
ysr@342 1102
ysr@342 1103 // These two calls start and stop the timer
ysr@342 1104 void record_start_time() {
ysr@342 1105 _elapsed_time_ms = os::elapsedTime() * 1000.0;
ysr@342 1106 }
ysr@342 1107 void record_end_time() {
ysr@342 1108 _elapsed_time_ms = os::elapsedTime() * 1000.0 - _elapsed_time_ms;
ysr@342 1109 }
ysr@342 1110
ysr@342 1111 // returns the task ID
ysr@342 1112 int task_id() { return _task_id; }
ysr@342 1113
ysr@342 1114 // From TerminatorTerminator. It determines whether this task should
ysr@342 1115 // exit the termination protocol after it's entered it.
ysr@342 1116 virtual bool should_exit_termination();
ysr@342 1117
johnc@2475 1118 // Resets the local region fields after a task has finished scanning a
johnc@2475 1119 // region; or when they have become stale as a result of the region
johnc@2475 1120 // being evacuated.
johnc@2475 1121 void giveup_current_region();
johnc@2475 1122
ysr@342 1123 HeapWord* finger() { return _finger; }
ysr@342 1124
ysr@342 1125 bool has_aborted() { return _has_aborted; }
ysr@342 1126 void set_has_aborted() { _has_aborted = true; }
ysr@342 1127 void clear_has_aborted() { _has_aborted = false; }
johnc@2059 1128 bool has_timed_out() { return _has_timed_out; }
johnc@2059 1129 bool claimed() { return _claimed; }
ysr@342 1130
tonyp@2533 1131 void set_cm_oop_closure(G1CMOopClosure* cm_oop_closure);
ysr@342 1132
ysr@342 1133 // It grays the object by marking it and, if necessary, pushing it
ysr@342 1134 // on the local queue
tonyp@2533 1135 inline void deal_with_reference(oop obj);
ysr@342 1136
ysr@342 1137 // It scans an object and visits its children.
tonyp@2533 1138 void scan_object(oop obj);
ysr@342 1139
ysr@342 1140 // It pushes an object on the local queue.
tonyp@2533 1141 inline void push(oop obj);
ysr@342 1142
ysr@342 1143 // These two move entries to/from the global stack.
ysr@342 1144 void move_entries_to_global_stack();
ysr@342 1145 void get_entries_from_global_stack();
ysr@342 1146
ysr@342 1147 // It pops and scans objects from the local queue. If partially is
ysr@342 1148 // true, then it stops when the queue size is of a given limit. If
ysr@342 1149 // partially is false, then it stops when the queue is empty.
ysr@342 1150 void drain_local_queue(bool partially);
ysr@342 1151 // It moves entries from the global stack to the local queue and
ysr@342 1152 // drains the local queue. If partially is true, then it stops when
ysr@342 1153 // both the global stack and the local queue reach a given size. If
ysr@342 1154 // partially if false, it tries to empty them totally.
ysr@342 1155 void drain_global_stack(bool partially);
ysr@342 1156 // It keeps picking SATB buffers and processing them until no SATB
ysr@342 1157 // buffers are available.
ysr@342 1158 void drain_satb_buffers();
tonyp@2981 1159
ysr@342 1160 // moves the local finger to a new location
ysr@342 1161 inline void move_finger_to(HeapWord* new_finger) {
tonyp@1023 1162 assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
ysr@342 1163 _finger = new_finger;
ysr@342 1164 }
ysr@342 1165
ysr@342 1166 CMTask(int task_num, ConcurrentMark *cm,
johnc@3028 1167 size_t* marked_bytes, BitMap* card_bm,
ysr@342 1168 CMTaskQueue* task_queue, CMTaskQueueSet* task_queues);
ysr@342 1169
ysr@342 1170 // it prints statistics associated with this task
ysr@342 1171 void print_stats();
ysr@342 1172
ysr@342 1173 #if _MARKING_STATS_
ysr@342 1174 void increase_objs_found_on_bitmap() { ++_objs_found_on_bitmap; }
ysr@342 1175 #endif // _MARKING_STATS_
ysr@342 1176 };
stefank@1879 1177
tonyp@2282 1178 // Class that's used to to print out per-region liveness
tonyp@2282 1179 // information. It's currently used at the end of marking and also
tonyp@2282 1180 // after we sort the old regions at the end of the cleanup operation.
tonyp@2282 1181 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
tonyp@2282 1182 private:
tonyp@2282 1183 outputStream* _out;
tonyp@2282 1184
tonyp@2282 1185 // Accumulators for these values.
tonyp@2282 1186 size_t _total_used_bytes;
tonyp@2282 1187 size_t _total_capacity_bytes;
tonyp@2282 1188 size_t _total_prev_live_bytes;
tonyp@2282 1189 size_t _total_next_live_bytes;
tonyp@2282 1190
tonyp@2282 1191 // These are set up when we come across a "stars humongous" region
tonyp@2282 1192 // (as this is where most of this information is stored, not in the
tonyp@2282 1193 // subsequent "continues humongous" regions). After that, for every
tonyp@2282 1194 // region in a given humongous region series we deduce the right
tonyp@2282 1195 // values for it by simply subtracting the appropriate amount from
tonyp@2282 1196 // these fields. All these values should reach 0 after we've visited
tonyp@2282 1197 // the last region in the series.
tonyp@2282 1198 size_t _hum_used_bytes;
tonyp@2282 1199 size_t _hum_capacity_bytes;
tonyp@2282 1200 size_t _hum_prev_live_bytes;
tonyp@2282 1201 size_t _hum_next_live_bytes;
tonyp@2282 1202
tonyp@2282 1203 static double perc(size_t val, size_t total) {
tonyp@2282 1204 if (total == 0) {
tonyp@2282 1205 return 0.0;
tonyp@2282 1206 } else {
tonyp@2282 1207 return 100.0 * ((double) val / (double) total);
tonyp@2282 1208 }
tonyp@2282 1209 }
tonyp@2282 1210
tonyp@2282 1211 static double bytes_to_mb(size_t val) {
tonyp@2282 1212 return (double) val / (double) M;
tonyp@2282 1213 }
tonyp@2282 1214
tonyp@2282 1215 // See the .cpp file.
tonyp@2282 1216 size_t get_hum_bytes(size_t* hum_bytes);
tonyp@2282 1217 void get_hum_bytes(size_t* used_bytes, size_t* capacity_bytes,
tonyp@2282 1218 size_t* prev_live_bytes, size_t* next_live_bytes);
tonyp@2282 1219
tonyp@2282 1220 public:
tonyp@2282 1221 // The header and footer are printed in the constructor and
tonyp@2282 1222 // destructor respectively.
tonyp@2282 1223 G1PrintRegionLivenessInfoClosure(outputStream* out, const char* phase_name);
tonyp@2282 1224 virtual bool doHeapRegion(HeapRegion* r);
tonyp@2282 1225 ~G1PrintRegionLivenessInfoClosure();
tonyp@2282 1226 };
tonyp@2282 1227
stefank@1879 1228 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP