1 /* 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP 27 28 #include "gc_implementation/shared/gcHeapSummary.hpp" 29 #include "gc_implementation/shared/gSpaceCounters.hpp" 30 #include "gc_implementation/shared/gcStats.hpp" 31 #include "gc_implementation/shared/gcWhen.hpp" 32 #include "gc_implementation/shared/generationCounters.hpp" 33 #include "memory/freeBlockDictionary.hpp" 34 #include "memory/generation.hpp" 35 #include "runtime/mutexLocker.hpp" 36 #include "runtime/virtualspace.hpp" 37 #include "services/memoryService.hpp" 38 #include "utilities/bitMap.inline.hpp" 39 #include "utilities/stack.inline.hpp" 40 #include "utilities/taskqueue.hpp" 41 #include "utilities/yieldingWorkgroup.hpp" 42 43 // ConcurrentMarkSweepGeneration is in support of a concurrent 44 // mark-sweep old generation in the Detlefs-Printezis--Boehm-Demers-Schenker 45 // style. We assume, for now, that this generation is always the 46 // seniormost generation (modulo the PermGeneration), and for simplicity 47 // in the first implementation, that this generation is a single compactible 48 // space. Neither of these restrictions appears essential, and will be 49 // relaxed in the future when more time is available to implement the 50 // greater generality (and there's a need for it). 51 // 52 // Concurrent mode failures are currently handled by 53 // means of a sliding mark-compact. 54 55 class CMSAdaptiveSizePolicy; 56 class CMSConcMarkingTask; 57 class CMSGCAdaptivePolicyCounters; 58 class CMSTracer; 59 class ConcurrentGCTimer; 60 class ConcurrentMarkSweepGeneration; 61 class ConcurrentMarkSweepPolicy; 62 class ConcurrentMarkSweepThread; 63 class CompactibleFreeListSpace; 64 class FreeChunk; 65 class PromotionInfo; 66 class ScanMarkedObjectsAgainCarefullyClosure; 67 class SerialOldTracer; 68 69 // A generic CMS bit map. It's the basis for both the CMS marking bit map 70 // as well as for the mod union table (in each case only a subset of the 71 // methods are used). This is essentially a wrapper around the BitMap class, 72 // with one bit per (1<<_shifter) HeapWords. (i.e. for the marking bit map, 73 // we have _shifter == 0. and for the mod union table we have 74 // shifter == CardTableModRefBS::card_shift - LogHeapWordSize.) 75 // XXX 64-bit issues in BitMap? 76 class CMSBitMap VALUE_OBJ_CLASS_SPEC { 77 friend class VMStructs; 78 79 HeapWord* _bmStartWord; // base address of range covered by map 80 size_t _bmWordSize; // map size (in #HeapWords covered) 81 const int _shifter; // shifts to convert HeapWord to bit position 82 VirtualSpace _virtual_space; // underlying the bit map 83 BitMap _bm; // the bit map itself 84 public: 85 Mutex* const _lock; // mutex protecting _bm; 86 87 public: 88 // constructor 89 CMSBitMap(int shifter, int mutex_rank, const char* mutex_name); 90 91 // allocates the actual storage for the map 92 bool allocate(MemRegion mr); 93 // field getter 94 Mutex* lock() const { return _lock; } 95 // locking verifier convenience function 96 void assert_locked() const PRODUCT_RETURN; 97 98 // inquiries 99 HeapWord* startWord() const { return _bmStartWord; } 100 size_t sizeInWords() const { return _bmWordSize; } 101 size_t sizeInBits() const { return _bm.size(); } 102 // the following is one past the last word in space 103 HeapWord* endWord() const { return _bmStartWord + _bmWordSize; } 104 105 // reading marks 106 bool isMarked(HeapWord* addr) const; 107 bool par_isMarked(HeapWord* addr) const; // do not lock checks 108 bool isUnmarked(HeapWord* addr) const; 109 bool isAllClear() const; 110 111 // writing marks 112 void mark(HeapWord* addr); 113 // For marking by parallel GC threads; 114 // returns true if we did, false if another thread did 115 bool par_mark(HeapWord* addr); 116 117 void mark_range(MemRegion mr); 118 void par_mark_range(MemRegion mr); 119 void mark_large_range(MemRegion mr); 120 void par_mark_large_range(MemRegion mr); 121 void par_clear(HeapWord* addr); // For unmarking by parallel GC threads. 122 void clear_range(MemRegion mr); 123 void par_clear_range(MemRegion mr); 124 void clear_large_range(MemRegion mr); 125 void par_clear_large_range(MemRegion mr); 126 void clear_all(); 127 void clear_all_incrementally(); // Not yet implemented!! 128 129 NOT_PRODUCT( 130 // checks the memory region for validity 131 void region_invariant(MemRegion mr); 132 ) 133 134 // iteration 135 void iterate(BitMapClosure* cl) { 136 _bm.iterate(cl); 137 } 138 void iterate(BitMapClosure* cl, HeapWord* left, HeapWord* right); 139 void dirty_range_iterate_clear(MemRegionClosure* cl); 140 void dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl); 141 142 // auxiliary support for iteration 143 HeapWord* getNextMarkedWordAddress(HeapWord* addr) const; 144 HeapWord* getNextMarkedWordAddress(HeapWord* start_addr, 145 HeapWord* end_addr) const; 146 HeapWord* getNextUnmarkedWordAddress(HeapWord* addr) const; 147 HeapWord* getNextUnmarkedWordAddress(HeapWord* start_addr, 148 HeapWord* end_addr) const; 149 MemRegion getAndClearMarkedRegion(HeapWord* addr); 150 MemRegion getAndClearMarkedRegion(HeapWord* start_addr, 151 HeapWord* end_addr); 152 153 // conversion utilities 154 HeapWord* offsetToHeapWord(size_t offset) const; 155 size_t heapWordToOffset(HeapWord* addr) const; 156 size_t heapWordDiffToOffsetDiff(size_t diff) const; 157 158 // debugging 159 // is this address range covered by the bit-map? 160 NOT_PRODUCT( 161 bool covers(MemRegion mr) const; 162 bool covers(HeapWord* start, size_t size = 0) const; 163 ) 164 void verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) PRODUCT_RETURN; 165 }; 166 167 // Represents a marking stack used by the CMS collector. 168 // Ideally this should be GrowableArray<> just like MSC's marking stack(s). 169 class CMSMarkStack: public CHeapObj<mtGC> { 170 // 171 friend class CMSCollector; // to get at expasion stats further below 172 // 173 174 VirtualSpace _virtual_space; // space for the stack 175 oop* _base; // bottom of stack 176 size_t _index; // one more than last occupied index 177 size_t _capacity; // max #elements 178 Mutex _par_lock; // an advisory lock used in case of parallel access 179 NOT_PRODUCT(size_t _max_depth;) // max depth plumbed during run 180 181 protected: 182 size_t _hit_limit; // we hit max stack size limit 183 size_t _failed_double; // we failed expansion before hitting limit 184 185 public: 186 CMSMarkStack(): 187 _par_lock(Mutex::event, "CMSMarkStack._par_lock", true), 188 _hit_limit(0), 189 _failed_double(0) {} 190 191 bool allocate(size_t size); 192 193 size_t capacity() const { return _capacity; } 194 195 oop pop() { 196 if (!isEmpty()) { 197 return _base[--_index] ; 198 } 199 return NULL; 200 } 201 202 bool push(oop ptr) { 203 if (isFull()) { 204 return false; 205 } else { 206 _base[_index++] = ptr; 207 NOT_PRODUCT(_max_depth = MAX2(_max_depth, _index)); 208 return true; 209 } 210 } 211 212 bool isEmpty() const { return _index == 0; } 213 bool isFull() const { 214 assert(_index <= _capacity, "buffer overflow"); 215 return _index == _capacity; 216 } 217 218 size_t length() { return _index; } 219 220 // "Parallel versions" of some of the above 221 oop par_pop() { 222 // lock and pop 223 MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag); 224 return pop(); 225 } 226 227 bool par_push(oop ptr) { 228 // lock and push 229 MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag); 230 return push(ptr); 231 } 232 233 // Forcibly reset the stack, losing all of its contents. 234 void reset() { 235 _index = 0; 236 } 237 238 // Expand the stack, typically in response to an overflow condition 239 void expand(); 240 241 // Compute the least valued stack element. 242 oop least_value(HeapWord* low) { 243 oop least = (oop)low; 244 for (size_t i = 0; i < _index; i++) { 245 least = MIN2(least, _base[i]); 246 } 247 return least; 248 } 249 250 // Exposed here to allow stack expansion in || case 251 Mutex* par_lock() { return &_par_lock; } 252 }; 253 254 class CardTableRS; 255 class CMSParGCThreadState; 256 257 class ModUnionClosure: public MemRegionClosure { 258 protected: 259 CMSBitMap* _t; 260 public: 261 ModUnionClosure(CMSBitMap* t): _t(t) { } 262 void do_MemRegion(MemRegion mr); 263 }; 264 265 class ModUnionClosurePar: public ModUnionClosure { 266 public: 267 ModUnionClosurePar(CMSBitMap* t): ModUnionClosure(t) { } 268 void do_MemRegion(MemRegion mr); 269 }; 270 271 // Survivor Chunk Array in support of parallelization of 272 // Survivor Space rescan. 273 class ChunkArray: public CHeapObj<mtGC> { 274 size_t _index; 275 size_t _capacity; 276 size_t _overflows; 277 HeapWord** _array; // storage for array 278 279 public: 280 ChunkArray() : _index(0), _capacity(0), _overflows(0), _array(NULL) {} 281 ChunkArray(HeapWord** a, size_t c): 282 _index(0), _capacity(c), _overflows(0), _array(a) {} 283 284 HeapWord** array() { return _array; } 285 void set_array(HeapWord** a) { _array = a; } 286 287 size_t capacity() { return _capacity; } 288 void set_capacity(size_t c) { _capacity = c; } 289 290 size_t end() { 291 assert(_index <= capacity(), 292 err_msg("_index (" SIZE_FORMAT ") > _capacity (" SIZE_FORMAT "): out of bounds", 293 _index, _capacity)); 294 return _index; 295 } // exclusive 296 297 HeapWord* nth(size_t n) { 298 assert(n < end(), "Out of bounds access"); 299 return _array[n]; 300 } 301 302 void reset() { 303 _index = 0; 304 if (_overflows > 0 && PrintCMSStatistics > 1) { 305 warning("CMS: ChunkArray[" SIZE_FORMAT "] overflowed " SIZE_FORMAT " times", 306 _capacity, _overflows); 307 } 308 _overflows = 0; 309 } 310 311 void record_sample(HeapWord* p, size_t sz) { 312 // For now we do not do anything with the size 313 if (_index < _capacity) { 314 _array[_index++] = p; 315 } else { 316 ++_overflows; 317 assert(_index == _capacity, 318 err_msg("_index (" SIZE_FORMAT ") > _capacity (" SIZE_FORMAT 319 "): out of bounds at overflow#" SIZE_FORMAT, 320 _index, _capacity, _overflows)); 321 } 322 } 323 }; 324 325 // 326 // Timing, allocation and promotion statistics for gc scheduling and incremental 327 // mode pacing. Most statistics are exponential averages. 328 // 329 class CMSStats VALUE_OBJ_CLASS_SPEC { 330 private: 331 ConcurrentMarkSweepGeneration* const _cms_gen; // The cms (old) gen. 332 333 // The following are exponential averages with factor alpha: 334 // avg = (100 - alpha) * avg + alpha * cur_sample 335 // 336 // The durations measure: end_time[n] - start_time[n] 337 // The periods measure: start_time[n] - start_time[n-1] 338 // 339 // The cms period and duration include only concurrent collections; time spent 340 // in foreground cms collections due to System.gc() or because of a failure to 341 // keep up are not included. 342 // 343 // There are 3 alphas to "bootstrap" the statistics. The _saved_alpha is the 344 // real value, but is used only after the first period. A value of 100 is 345 // used for the first sample so it gets the entire weight. 346 unsigned int _saved_alpha; // 0-100 347 unsigned int _gc0_alpha; 348 unsigned int _cms_alpha; 349 350 double _gc0_duration; 351 double _gc0_period; 352 size_t _gc0_promoted; // bytes promoted per gc0 353 double _cms_duration; 354 double _cms_duration_pre_sweep; // time from initiation to start of sweep 355 double _cms_duration_per_mb; 356 double _cms_period; 357 size_t _cms_allocated; // bytes of direct allocation per gc0 period 358 359 // Timers. 360 elapsedTimer _cms_timer; 361 TimeStamp _gc0_begin_time; 362 TimeStamp _cms_begin_time; 363 TimeStamp _cms_end_time; 364 365 // Snapshots of the amount used in the CMS generation. 366 size_t _cms_used_at_gc0_begin; 367 size_t _cms_used_at_gc0_end; 368 size_t _cms_used_at_cms_begin; 369 370 // Used to prevent the duty cycle from being reduced in the middle of a cms 371 // cycle. 372 bool _allow_duty_cycle_reduction; 373 374 enum { 375 _GC0_VALID = 0x1, 376 _CMS_VALID = 0x2, 377 _ALL_VALID = _GC0_VALID | _CMS_VALID 378 }; 379 380 unsigned int _valid_bits; 381 382 unsigned int _icms_duty_cycle; // icms duty cycle (0-100). 383 384 protected: 385 386 // Return a duty cycle that avoids wild oscillations, by limiting the amount 387 // of change between old_duty_cycle and new_duty_cycle (the latter is treated 388 // as a recommended value). 389 static unsigned int icms_damped_duty_cycle(unsigned int old_duty_cycle, 390 unsigned int new_duty_cycle); 391 unsigned int icms_update_duty_cycle_impl(); 392 393 // In support of adjusting of cms trigger ratios based on history 394 // of concurrent mode failure. 395 double cms_free_adjustment_factor(size_t free) const; 396 void adjust_cms_free_adjustment_factor(bool fail, size_t free); 397 398 public: 399 CMSStats(ConcurrentMarkSweepGeneration* cms_gen, 400 unsigned int alpha = CMSExpAvgFactor); 401 402 // Whether or not the statistics contain valid data; higher level statistics 403 // cannot be called until this returns true (they require at least one young 404 // gen and one cms cycle to have completed). 405 bool valid() const; 406 407 // Record statistics. 408 void record_gc0_begin(); 409 void record_gc0_end(size_t cms_gen_bytes_used); 410 void record_cms_begin(); 411 void record_cms_end(); 412 413 // Allow management of the cms timer, which must be stopped/started around 414 // yield points. 415 elapsedTimer& cms_timer() { return _cms_timer; } 416 void start_cms_timer() { _cms_timer.start(); } 417 void stop_cms_timer() { _cms_timer.stop(); } 418 419 // Basic statistics; units are seconds or bytes. 420 double gc0_period() const { return _gc0_period; } 421 double gc0_duration() const { return _gc0_duration; } 422 size_t gc0_promoted() const { return _gc0_promoted; } 423 double cms_period() const { return _cms_period; } 424 double cms_duration() const { return _cms_duration; } 425 double cms_duration_per_mb() const { return _cms_duration_per_mb; } 426 size_t cms_allocated() const { return _cms_allocated; } 427 428 size_t cms_used_at_gc0_end() const { return _cms_used_at_gc0_end;} 429 430 // Seconds since the last background cms cycle began or ended. 431 double cms_time_since_begin() const; 432 double cms_time_since_end() const; 433 434 // Higher level statistics--caller must check that valid() returns true before 435 // calling. 436 437 // Returns bytes promoted per second of wall clock time. 438 double promotion_rate() const; 439 440 // Returns bytes directly allocated per second of wall clock time. 441 double cms_allocation_rate() const; 442 443 // Rate at which space in the cms generation is being consumed (sum of the 444 // above two). 445 double cms_consumption_rate() const; 446 447 // Returns an estimate of the number of seconds until the cms generation will 448 // fill up, assuming no collection work is done. 449 double time_until_cms_gen_full() const; 450 451 // Returns an estimate of the number of seconds remaining until 452 // the cms generation collection should start. 453 double time_until_cms_start() const; 454 455 // End of higher level statistics. 456 457 // Returns the cms incremental mode duty cycle, as a percentage (0-100). 458 unsigned int icms_duty_cycle() const { return _icms_duty_cycle; } 459 460 // Update the duty cycle and return the new value. 461 unsigned int icms_update_duty_cycle(); 462 463 // Debugging. 464 void print_on(outputStream* st) const PRODUCT_RETURN; 465 void print() const { print_on(gclog_or_tty); } 466 }; 467 468 // A closure related to weak references processing which 469 // we embed in the CMSCollector, since we need to pass 470 // it to the reference processor for secondary filtering 471 // of references based on reachability of referent; 472 // see role of _is_alive_non_header closure in the 473 // ReferenceProcessor class. 474 // For objects in the CMS generation, this closure checks 475 // if the object is "live" (reachable). Used in weak 476 // reference processing. 477 class CMSIsAliveClosure: public BoolObjectClosure { 478 const MemRegion _span; 479 const CMSBitMap* _bit_map; 480 481 friend class CMSCollector; 482 public: 483 CMSIsAliveClosure(MemRegion span, 484 CMSBitMap* bit_map): 485 _span(span), 486 _bit_map(bit_map) { 487 assert(!span.is_empty(), "Empty span could spell trouble"); 488 } 489 490 void do_object(oop obj) { 491 assert(false, "not to be invoked"); 492 } 493 494 bool do_object_b(oop obj); 495 }; 496 497 498 // Implements AbstractRefProcTaskExecutor for CMS. 499 class CMSRefProcTaskExecutor: public AbstractRefProcTaskExecutor { 500 public: 501 502 CMSRefProcTaskExecutor(CMSCollector& collector) 503 : _collector(collector) 504 { } 505 506 // Executes a task using worker threads. 507 virtual void execute(ProcessTask& task); 508 virtual void execute(EnqueueTask& task); 509 private: 510 CMSCollector& _collector; 511 }; 512 513 514 class CMSCollector: public CHeapObj<mtGC> { 515 friend class VMStructs; 516 friend class ConcurrentMarkSweepThread; 517 friend class ConcurrentMarkSweepGeneration; 518 friend class CompactibleFreeListSpace; 519 friend class CMSParRemarkTask; 520 friend class CMSConcMarkingTask; 521 friend class CMSRefProcTaskProxy; 522 friend class CMSRefProcTaskExecutor; 523 friend class ScanMarkedObjectsAgainCarefullyClosure; // for sampling eden 524 friend class SurvivorSpacePrecleanClosure; // --- ditto ------- 525 friend class PushOrMarkClosure; // to access _restart_addr 526 friend class Par_PushOrMarkClosure; // to access _restart_addr 527 friend class MarkFromRootsClosure; // -- ditto -- 528 // ... and for clearing cards 529 friend class Par_MarkFromRootsClosure; // to access _restart_addr 530 // ... and for clearing cards 531 friend class Par_ConcMarkingClosure; // to access _restart_addr etc. 532 friend class MarkFromRootsVerifyClosure; // to access _restart_addr 533 friend class PushAndMarkVerifyClosure; // -- ditto -- 534 friend class MarkRefsIntoAndScanClosure; // to access _overflow_list 535 friend class PushAndMarkClosure; // -- ditto -- 536 friend class Par_PushAndMarkClosure; // -- ditto -- 537 friend class CMSKeepAliveClosure; // -- ditto -- 538 friend class CMSDrainMarkingStackClosure; // -- ditto -- 539 friend class CMSInnerParMarkAndPushClosure; // -- ditto -- 540 NOT_PRODUCT(friend class ScanMarkedObjectsAgainClosure;) // assertion on _overflow_list 541 friend class ReleaseForegroundGC; // to access _foregroundGCShouldWait 542 friend class VM_CMS_Operation; 543 friend class VM_CMS_Initial_Mark; 544 friend class VM_CMS_Final_Remark; 545 friend class TraceCMSMemoryManagerStats; 546 547 private: 548 jlong _time_of_last_gc; 549 void update_time_of_last_gc(jlong now) { 550 _time_of_last_gc = now; 551 } 552 553 OopTaskQueueSet* _task_queues; 554 555 // Overflow list of grey objects, threaded through mark-word 556 // Manipulated with CAS in the parallel/multi-threaded case. 557 oop _overflow_list; 558 // The following array-pair keeps track of mark words 559 // displaced for accomodating overflow list above. 560 // This code will likely be revisited under RFE#4922830. 561 Stack<oop, mtGC> _preserved_oop_stack; 562 Stack<markOop, mtGC> _preserved_mark_stack; 563 564 int* _hash_seed; 565 566 // In support of multi-threaded concurrent phases 567 YieldingFlexibleWorkGang* _conc_workers; 568 569 // Performance Counters 570 CollectorCounters* _gc_counters; 571 572 // Initialization Errors 573 bool _completed_initialization; 574 575 // In support of ExplicitGCInvokesConcurrent 576 static bool _full_gc_requested; 577 unsigned int _collection_count_start; 578 579 // Should we unload classes this concurrent cycle? 580 bool _should_unload_classes; 581 unsigned int _concurrent_cycles_since_last_unload; 582 unsigned int concurrent_cycles_since_last_unload() const { 583 return _concurrent_cycles_since_last_unload; 584 } 585 // Did we (allow) unload classes in the previous concurrent cycle? 586 bool unloaded_classes_last_cycle() const { 587 return concurrent_cycles_since_last_unload() == 0; 588 } 589 // Root scanning options for perm gen 590 int _roots_scanning_options; 591 int roots_scanning_options() const { return _roots_scanning_options; } 592 void add_root_scanning_option(int o) { _roots_scanning_options |= o; } 593 void remove_root_scanning_option(int o) { _roots_scanning_options &= ~o; } 594 595 // Verification support 596 CMSBitMap _verification_mark_bm; 597 void verify_after_remark_work_1(); 598 void verify_after_remark_work_2(); 599 600 // true if any verification flag is on. 601 bool _verifying; 602 bool verifying() const { return _verifying; } 603 void set_verifying(bool v) { _verifying = v; } 604 605 // Collector policy 606 ConcurrentMarkSweepPolicy* _collector_policy; 607 ConcurrentMarkSweepPolicy* collector_policy() { return _collector_policy; } 608 609 // XXX Move these to CMSStats ??? FIX ME !!! 610 elapsedTimer _inter_sweep_timer; // time between sweeps 611 elapsedTimer _intra_sweep_timer; // time _in_ sweeps 612 // padded decaying average estimates of the above 613 AdaptivePaddedAverage _inter_sweep_estimate; 614 AdaptivePaddedAverage _intra_sweep_estimate; 615 616 CMSTracer* _gc_tracer_cm; 617 ConcurrentGCTimer* _gc_timer_cm; 618 619 bool _cms_start_registered; 620 621 GCHeapSummary _last_heap_summary; 622 PermGenSummary _last_perm_gen_summary; 623 624 void register_foreground_gc_start(GCCause::Cause cause); 625 void register_gc_start(GCCause::Cause cause); 626 void register_gc_end(); 627 void save_heap_summary(); 628 void report_heap_summary(GCWhen::Type when); 629 630 protected: 631 ConcurrentMarkSweepGeneration* _cmsGen; // old gen (CMS) 632 ConcurrentMarkSweepGeneration* _permGen; // perm gen 633 MemRegion _span; // span covering above two 634 CardTableRS* _ct; // card table 635 636 // CMS marking support structures 637 CMSBitMap _markBitMap; 638 CMSBitMap _modUnionTable; 639 CMSMarkStack _markStack; 640 CMSMarkStack _revisitStack; // used to keep track of klassKlass objects 641 // to revisit 642 CMSBitMap _perm_gen_verify_bit_map; // Mark bit map for perm gen verification support. 643 644 HeapWord* _restart_addr; // in support of marking stack overflow 645 void lower_restart_addr(HeapWord* low); 646 647 // Counters in support of marking stack / work queue overflow handling: 648 // a non-zero value indicates certain types of overflow events during 649 // the current CMS cycle and could lead to stack resizing efforts at 650 // an opportune future time. 651 size_t _ser_pmc_preclean_ovflw; 652 size_t _ser_pmc_remark_ovflw; 653 size_t _par_pmc_remark_ovflw; 654 size_t _ser_kac_preclean_ovflw; 655 size_t _ser_kac_ovflw; 656 size_t _par_kac_ovflw; 657 NOT_PRODUCT(ssize_t _num_par_pushes;) 658 659 // ("Weak") Reference processing support 660 ReferenceProcessor* _ref_processor; 661 CMSIsAliveClosure _is_alive_closure; 662 // keep this textually after _markBitMap and _span; c'tor dependency 663 664 ConcurrentMarkSweepThread* _cmsThread; // the thread doing the work 665 ModUnionClosure _modUnionClosure; 666 ModUnionClosurePar _modUnionClosurePar; 667 668 // CMS abstract state machine 669 // initial_state: Idling 670 // next_state(Idling) = {Marking} 671 // next_state(Marking) = {Precleaning, Sweeping} 672 // next_state(Precleaning) = {AbortablePreclean, FinalMarking} 673 // next_state(AbortablePreclean) = {FinalMarking} 674 // next_state(FinalMarking) = {Sweeping} 675 // next_state(Sweeping) = {Resizing} 676 // next_state(Resizing) = {Resetting} 677 // next_state(Resetting) = {Idling} 678 // The numeric values below are chosen so that: 679 // . _collectorState <= Idling == post-sweep && pre-mark 680 // . _collectorState in (Idling, Sweeping) == {initial,final}marking || 681 // precleaning || abortablePrecleanb 682 public: 683 enum CollectorState { 684 Resizing = 0, 685 Resetting = 1, 686 Idling = 2, 687 InitialMarking = 3, 688 Marking = 4, 689 Precleaning = 5, 690 AbortablePreclean = 6, 691 FinalMarking = 7, 692 Sweeping = 8 693 }; 694 protected: 695 static CollectorState _collectorState; 696 697 // State related to prologue/epilogue invocation for my generations 698 bool _between_prologue_and_epilogue; 699 700 // Signalling/State related to coordination between fore- and backgroud GC 701 // Note: When the baton has been passed from background GC to foreground GC, 702 // _foregroundGCIsActive is true and _foregroundGCShouldWait is false. 703 static bool _foregroundGCIsActive; // true iff foreground collector is active or 704 // wants to go active 705 static bool _foregroundGCShouldWait; // true iff background GC is active and has not 706 // yet passed the baton to the foreground GC 707 708 // Support for CMSScheduleRemark (abortable preclean) 709 bool _abort_preclean; 710 bool _start_sampling; 711 712 int _numYields; 713 size_t _numDirtyCards; 714 size_t _sweep_count; 715 // number of full gc's since the last concurrent gc. 716 uint _full_gcs_since_conc_gc; 717 718 // occupancy used for bootstrapping stats 719 double _bootstrap_occupancy; 720 721 // timer 722 elapsedTimer _timer; 723 724 // Timing, allocation and promotion statistics, used for scheduling. 725 CMSStats _stats; 726 727 // Allocation limits installed in the young gen, used only in 728 // CMSIncrementalMode. When an allocation in the young gen would cross one of 729 // these limits, the cms generation is notified and the cms thread is started 730 // or stopped, respectively. 731 HeapWord* _icms_start_limit; 732 HeapWord* _icms_stop_limit; 733 734 enum CMS_op_type { 735 CMS_op_checkpointRootsInitial, 736 CMS_op_checkpointRootsFinal 737 }; 738 739 void do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause); 740 bool stop_world_and_do(CMS_op_type op); 741 742 OopTaskQueueSet* task_queues() { return _task_queues; } 743 int* hash_seed(int i) { return &_hash_seed[i]; } 744 YieldingFlexibleWorkGang* conc_workers() { return _conc_workers; } 745 746 // Support for parallelizing Eden rescan in CMS remark phase 747 void sample_eden(); // ... sample Eden space top 748 749 private: 750 // Support for parallelizing young gen rescan in CMS remark phase 751 Generation* _young_gen; // the younger gen 752 HeapWord** _top_addr; // ... Top of Eden 753 HeapWord** _end_addr; // ... End of Eden 754 HeapWord** _eden_chunk_array; // ... Eden partitioning array 755 size_t _eden_chunk_index; // ... top (exclusive) of array 756 size_t _eden_chunk_capacity; // ... max entries in array 757 758 // Support for parallelizing survivor space rescan 759 HeapWord** _survivor_chunk_array; 760 size_t _survivor_chunk_index; 761 size_t _survivor_chunk_capacity; 762 size_t* _cursor; 763 ChunkArray* _survivor_plab_array; 764 765 // Support for marking stack overflow handling 766 bool take_from_overflow_list(size_t num, CMSMarkStack* to_stack); 767 bool par_take_from_overflow_list(size_t num, 768 OopTaskQueue* to_work_q, 769 int no_of_gc_threads); 770 void push_on_overflow_list(oop p); 771 void par_push_on_overflow_list(oop p); 772 // the following is, obviously, not, in general, "MT-stable" 773 bool overflow_list_is_empty() const; 774 775 void preserve_mark_if_necessary(oop p); 776 void par_preserve_mark_if_necessary(oop p); 777 void preserve_mark_work(oop p, markOop m); 778 void restore_preserved_marks_if_any(); 779 NOT_PRODUCT(bool no_preserved_marks() const;) 780 // in support of testing overflow code 781 NOT_PRODUCT(int _overflow_counter;) 782 NOT_PRODUCT(bool simulate_overflow();) // sequential 783 NOT_PRODUCT(bool par_simulate_overflow();) // MT version 784 785 // CMS work methods 786 void checkpointRootsInitialWork(bool asynch); // initial checkpoint work 787 788 // a return value of false indicates failure due to stack overflow 789 bool markFromRootsWork(bool asynch); // concurrent marking work 790 791 public: // FIX ME!!! only for testing 792 bool do_marking_st(bool asynch); // single-threaded marking 793 bool do_marking_mt(bool asynch); // multi-threaded marking 794 795 private: 796 797 // concurrent precleaning work 798 size_t preclean_mod_union_table(ConcurrentMarkSweepGeneration* gen, 799 ScanMarkedObjectsAgainCarefullyClosure* cl); 800 size_t preclean_card_table(ConcurrentMarkSweepGeneration* gen, 801 ScanMarkedObjectsAgainCarefullyClosure* cl); 802 // Does precleaning work, returning a quantity indicative of 803 // the amount of "useful work" done. 804 size_t preclean_work(bool clean_refs, bool clean_survivors); 805 void abortable_preclean(); // Preclean while looking for possible abort 806 void initialize_sequential_subtasks_for_young_gen_rescan(int i); 807 // Helper function for above; merge-sorts the per-thread plab samples 808 void merge_survivor_plab_arrays(ContiguousSpace* surv, int no_of_gc_threads); 809 // Resets (i.e. clears) the per-thread plab sample vectors 810 void reset_survivor_plab_arrays(); 811 812 // final (second) checkpoint work 813 void checkpointRootsFinalWork(bool asynch, bool clear_all_soft_refs, 814 bool init_mark_was_synchronous); 815 // work routine for parallel version of remark 816 void do_remark_parallel(); 817 // work routine for non-parallel version of remark 818 void do_remark_non_parallel(); 819 // reference processing work routine (during second checkpoint) 820 void refProcessingWork(bool asynch, bool clear_all_soft_refs); 821 822 // concurrent sweeping work 823 void sweepWork(ConcurrentMarkSweepGeneration* gen, bool asynch); 824 825 // (concurrent) resetting of support data structures 826 void reset(bool asynch); 827 828 // Clear _expansion_cause fields of constituent generations 829 void clear_expansion_cause(); 830 831 // An auxilliary method used to record the ends of 832 // used regions of each generation to limit the extent of sweep 833 void save_sweep_limits(); 834 835 // Resize the generations included in the collector. 836 void compute_new_size(); 837 838 // A work method used by foreground collection to determine 839 // what type of collection (compacting or not, continuing or fresh) 840 // it should do. 841 void decide_foreground_collection_type(bool clear_all_soft_refs, 842 bool* should_compact, bool* should_start_over); 843 844 // A work method used by the foreground collector to do 845 // a mark-sweep-compact. 846 void do_compaction_work(bool clear_all_soft_refs); 847 848 // A work method used by the foreground collector to do 849 // a mark-sweep, after taking over from a possibly on-going 850 // concurrent mark-sweep collection. 851 void do_mark_sweep_work(bool clear_all_soft_refs, 852 CollectorState first_state, bool should_start_over); 853 854 // Work methods for reporting concurrent mode interruption or failure 855 bool is_external_interruption(); 856 void report_concurrent_mode_interruption(); 857 858 // If the backgrould GC is active, acquire control from the background 859 // GC and do the collection. 860 void acquire_control_and_collect(bool full, bool clear_all_soft_refs); 861 862 // For synchronizing passing of control from background to foreground 863 // GC. waitForForegroundGC() is called by the background 864 // collector. It if had to wait for a foreground collection, 865 // it returns true and the background collection should assume 866 // that the collection was finished by the foreground 867 // collector. 868 bool waitForForegroundGC(); 869 870 // Incremental mode triggering: recompute the icms duty cycle and set the 871 // allocation limits in the young gen. 872 void icms_update_allocation_limits(); 873 874 size_t block_size_using_printezis_bits(HeapWord* addr) const; 875 size_t block_size_if_printezis_bits(HeapWord* addr) const; 876 HeapWord* next_card_start_after_block(HeapWord* addr) const; 877 878 void setup_cms_unloading_and_verification_state(); 879 public: 880 CMSCollector(ConcurrentMarkSweepGeneration* cmsGen, 881 ConcurrentMarkSweepGeneration* permGen, 882 CardTableRS* ct, 883 ConcurrentMarkSweepPolicy* cp); 884 ConcurrentMarkSweepThread* cmsThread() { return _cmsThread; } 885 886 ReferenceProcessor* ref_processor() { return _ref_processor; } 887 void ref_processor_init(); 888 889 Mutex* bitMapLock() const { return _markBitMap.lock(); } 890 static CollectorState abstract_state() { return _collectorState; } 891 892 bool should_abort_preclean() const; // Whether preclean should be aborted. 893 size_t get_eden_used() const; 894 size_t get_eden_capacity() const; 895 896 ConcurrentMarkSweepGeneration* cmsGen() { return _cmsGen; } 897 898 // locking checks 899 NOT_PRODUCT(static bool have_cms_token();) 900 901 // XXXPERM bool should_collect(bool full, size_t size, bool tlab); 902 bool shouldConcurrentCollect(); 903 904 void collect(bool full, 905 bool clear_all_soft_refs, 906 size_t size, 907 bool tlab); 908 void collect_in_background(bool clear_all_soft_refs); 909 void collect_in_foreground(bool clear_all_soft_refs); 910 911 // In support of ExplicitGCInvokesConcurrent 912 static void request_full_gc(unsigned int full_gc_count); 913 // Should we unload classes in a particular concurrent cycle? 914 bool should_unload_classes() const { 915 return _should_unload_classes; 916 } 917 bool update_should_unload_classes(); 918 919 void direct_allocated(HeapWord* start, size_t size); 920 921 // Object is dead if not marked and current phase is sweeping. 922 bool is_dead_obj(oop obj) const; 923 924 // After a promotion (of "start"), do any necessary marking. 925 // If "par", then it's being done by a parallel GC thread. 926 // The last two args indicate if we need precise marking 927 // and if so the size of the object so it can be dirtied 928 // in its entirety. 929 void promoted(bool par, HeapWord* start, 930 bool is_obj_array, size_t obj_size); 931 932 HeapWord* allocation_limit_reached(Space* space, HeapWord* top, 933 size_t word_size); 934 935 void getFreelistLocks() const; 936 void releaseFreelistLocks() const; 937 bool haveFreelistLocks() const; 938 939 // GC prologue and epilogue 940 void gc_prologue(bool full); 941 void gc_epilogue(bool full); 942 943 jlong time_of_last_gc(jlong now) { 944 if (_collectorState <= Idling) { 945 // gc not in progress 946 return _time_of_last_gc; 947 } else { 948 // collection in progress 949 return now; 950 } 951 } 952 953 // Support for parallel remark of survivor space 954 void* get_data_recorder(int thr_num); 955 956 CMSBitMap* markBitMap() { return &_markBitMap; } 957 void directAllocated(HeapWord* start, size_t size); 958 959 // main CMS steps and related support 960 void checkpointRootsInitial(bool asynch); 961 bool markFromRoots(bool asynch); // a return value of false indicates failure 962 // due to stack overflow 963 void preclean(); 964 void checkpointRootsFinal(bool asynch, bool clear_all_soft_refs, 965 bool init_mark_was_synchronous); 966 void sweep(bool asynch); 967 968 // Check that the currently executing thread is the expected 969 // one (foreground collector or background collector). 970 static void check_correct_thread_executing() PRODUCT_RETURN; 971 // XXXPERM void print_statistics() PRODUCT_RETURN; 972 973 bool is_cms_reachable(HeapWord* addr); 974 975 // Performance Counter Support 976 CollectorCounters* counters() { return _gc_counters; } 977 978 // timer stuff 979 void startTimer() { assert(!_timer.is_active(), "Error"); _timer.start(); } 980 void stopTimer() { assert( _timer.is_active(), "Error"); _timer.stop(); } 981 void resetTimer() { assert(!_timer.is_active(), "Error"); _timer.reset(); } 982 double timerValue() { assert(!_timer.is_active(), "Error"); return _timer.seconds(); } 983 984 int yields() { return _numYields; } 985 void resetYields() { _numYields = 0; } 986 void incrementYields() { _numYields++; } 987 void resetNumDirtyCards() { _numDirtyCards = 0; } 988 void incrementNumDirtyCards(size_t num) { _numDirtyCards += num; } 989 size_t numDirtyCards() { return _numDirtyCards; } 990 991 static bool foregroundGCShouldWait() { return _foregroundGCShouldWait; } 992 static void set_foregroundGCShouldWait(bool v) { _foregroundGCShouldWait = v; } 993 static bool foregroundGCIsActive() { return _foregroundGCIsActive; } 994 static void set_foregroundGCIsActive(bool v) { _foregroundGCIsActive = v; } 995 size_t sweep_count() const { return _sweep_count; } 996 void increment_sweep_count() { _sweep_count++; } 997 998 // Timers/stats for gc scheduling and incremental mode pacing. 999 CMSStats& stats() { return _stats; } 1000 1001 // Convenience methods that check whether CMSIncrementalMode is enabled and 1002 // forward to the corresponding methods in ConcurrentMarkSweepThread. 1003 static void start_icms(); 1004 static void stop_icms(); // Called at the end of the cms cycle. 1005 static void disable_icms(); // Called before a foreground collection. 1006 static void enable_icms(); // Called after a foreground collection. 1007 void icms_wait(); // Called at yield points. 1008 1009 // Adaptive size policy 1010 CMSAdaptiveSizePolicy* size_policy(); 1011 CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters(); 1012 1013 // debugging 1014 void verify(); 1015 bool verify_after_remark(); 1016 void verify_ok_to_terminate() const PRODUCT_RETURN; 1017 void verify_work_stacks_empty() const PRODUCT_RETURN; 1018 void verify_overflow_empty() const PRODUCT_RETURN; 1019 1020 // convenience methods in support of debugging 1021 static const size_t skip_header_HeapWords() PRODUCT_RETURN0; 1022 HeapWord* block_start(const void* p) const PRODUCT_RETURN0; 1023 1024 // accessors 1025 CMSMarkStack* verification_mark_stack() { return &_markStack; } 1026 CMSBitMap* verification_mark_bm() { return &_verification_mark_bm; } 1027 1028 // Get the bit map with a perm gen "deadness" information. 1029 CMSBitMap* perm_gen_verify_bit_map() { return &_perm_gen_verify_bit_map; } 1030 1031 // Initialization errors 1032 bool completed_initialization() { return _completed_initialization; } 1033 }; 1034 1035 class CMSExpansionCause : public AllStatic { 1036 public: 1037 enum Cause { 1038 _no_expansion, 1039 _satisfy_free_ratio, 1040 _satisfy_promotion, 1041 _satisfy_allocation, 1042 _allocate_par_lab, 1043 _allocate_par_spooling_space, 1044 _adaptive_size_policy 1045 }; 1046 // Return a string describing the cause of the expansion. 1047 static const char* to_string(CMSExpansionCause::Cause cause); 1048 }; 1049 1050 class ConcurrentMarkSweepGeneration: public CardGeneration { 1051 friend class VMStructs; 1052 friend class ConcurrentMarkSweepThread; 1053 friend class ConcurrentMarkSweep; 1054 friend class CMSCollector; 1055 protected: 1056 static CMSCollector* _collector; // the collector that collects us 1057 CompactibleFreeListSpace* _cmsSpace; // underlying space (only one for now) 1058 1059 // Performance Counters 1060 GenerationCounters* _gen_counters; 1061 GSpaceCounters* _space_counters; 1062 1063 // Words directly allocated, used by CMSStats. 1064 size_t _direct_allocated_words; 1065 1066 // Non-product stat counters 1067 NOT_PRODUCT( 1068 size_t _numObjectsPromoted; 1069 size_t _numWordsPromoted; 1070 size_t _numObjectsAllocated; 1071 size_t _numWordsAllocated; 1072 ) 1073 1074 // Used for sizing decisions 1075 bool _incremental_collection_failed; 1076 bool incremental_collection_failed() { 1077 return _incremental_collection_failed; 1078 } 1079 void set_incremental_collection_failed() { 1080 _incremental_collection_failed = true; 1081 } 1082 void clear_incremental_collection_failed() { 1083 _incremental_collection_failed = false; 1084 } 1085 1086 // accessors 1087 void set_expansion_cause(CMSExpansionCause::Cause v) { _expansion_cause = v;} 1088 CMSExpansionCause::Cause expansion_cause() const { return _expansion_cause; } 1089 1090 private: 1091 // For parallel young-gen GC support. 1092 CMSParGCThreadState** _par_gc_thread_states; 1093 1094 // Reason generation was expanded 1095 CMSExpansionCause::Cause _expansion_cause; 1096 1097 // In support of MinChunkSize being larger than min object size 1098 const double _dilatation_factor; 1099 1100 enum CollectionTypes { 1101 Concurrent_collection_type = 0, 1102 MS_foreground_collection_type = 1, 1103 MSC_foreground_collection_type = 2, 1104 Unknown_collection_type = 3 1105 }; 1106 1107 CollectionTypes _debug_collection_type; 1108 1109 // Fraction of current occupancy at which to start a CMS collection which 1110 // will collect this generation (at least). 1111 double _initiating_occupancy; 1112 1113 protected: 1114 // Shrink generation by specified size (returns false if unable to shrink) 1115 virtual void shrink_by(size_t bytes); 1116 1117 // Update statistics for GC 1118 virtual void update_gc_stats(int level, bool full); 1119 1120 // Maximum available space in the generation (including uncommitted) 1121 // space. 1122 size_t max_available() const; 1123 1124 // getter and initializer for _initiating_occupancy field. 1125 double initiating_occupancy() const { return _initiating_occupancy; } 1126 void init_initiating_occupancy(intx io, intx tr); 1127 1128 public: 1129 ConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size, 1130 int level, CardTableRS* ct, 1131 bool use_adaptive_freelists, 1132 FreeBlockDictionary<FreeChunk>::DictionaryChoice); 1133 1134 // Accessors 1135 CMSCollector* collector() const { return _collector; } 1136 static void set_collector(CMSCollector* collector) { 1137 assert(_collector == NULL, "already set"); 1138 _collector = collector; 1139 } 1140 CompactibleFreeListSpace* cmsSpace() const { return _cmsSpace; } 1141 1142 Mutex* freelistLock() const; 1143 1144 virtual Generation::Name kind() { return Generation::ConcurrentMarkSweep; } 1145 1146 // Adaptive size policy 1147 CMSAdaptiveSizePolicy* size_policy(); 1148 1149 bool refs_discovery_is_atomic() const { return false; } 1150 bool refs_discovery_is_mt() const { 1151 // Note: CMS does MT-discovery during the parallel-remark 1152 // phases. Use ReferenceProcessorMTMutator to make refs 1153 // discovery MT-safe during such phases or other parallel 1154 // discovery phases in the future. This may all go away 1155 // if/when we decide that refs discovery is sufficiently 1156 // rare that the cost of the CAS's involved is in the 1157 // noise. That's a measurement that should be done, and 1158 // the code simplified if that turns out to be the case. 1159 return ConcGCThreads > 1; 1160 } 1161 1162 // Override 1163 virtual void ref_processor_init(); 1164 1165 // Grow generation by specified size (returns false if unable to grow) 1166 bool grow_by(size_t bytes); 1167 // Grow generation to reserved size. 1168 bool grow_to_reserved(); 1169 1170 void clear_expansion_cause() { _expansion_cause = CMSExpansionCause::_no_expansion; } 1171 1172 // Space enquiries 1173 size_t capacity() const; 1174 size_t used() const; 1175 size_t free() const; 1176 double occupancy() const { return ((double)used())/((double)capacity()); } 1177 size_t contiguous_available() const; 1178 size_t unsafe_max_alloc_nogc() const; 1179 1180 // over-rides 1181 MemRegion used_region() const; 1182 MemRegion used_region_at_save_marks() const; 1183 1184 // Does a "full" (forced) collection invoked on this generation collect 1185 // all younger generations as well? Note that the second conjunct is a 1186 // hack to allow the collection of the younger gen first if the flag is 1187 // set. This is better than using th policy's should_collect_gen0_first() 1188 // since that causes us to do an extra unnecessary pair of restart-&-stop-world. 1189 virtual bool full_collects_younger_generations() const { 1190 return UseCMSCompactAtFullCollection && !CollectGen0First; 1191 } 1192 1193 void space_iterate(SpaceClosure* blk, bool usedOnly = false); 1194 1195 // Support for compaction 1196 CompactibleSpace* first_compaction_space() const; 1197 // Adjust quantites in the generation affected by 1198 // the compaction. 1199 void reset_after_compaction(); 1200 1201 // Allocation support 1202 HeapWord* allocate(size_t size, bool tlab); 1203 HeapWord* have_lock_and_allocate(size_t size, bool tlab); 1204 oop promote(oop obj, size_t obj_size); 1205 HeapWord* par_allocate(size_t size, bool tlab) { 1206 return allocate(size, tlab); 1207 } 1208 1209 // Incremental mode triggering. 1210 HeapWord* allocation_limit_reached(Space* space, HeapWord* top, 1211 size_t word_size); 1212 1213 // Used by CMSStats to track direct allocation. The value is sampled and 1214 // reset after each young gen collection. 1215 size_t direct_allocated_words() const { return _direct_allocated_words; } 1216 void reset_direct_allocated_words() { _direct_allocated_words = 0; } 1217 1218 // Overrides for parallel promotion. 1219 virtual oop par_promote(int thread_num, 1220 oop obj, markOop m, size_t word_sz); 1221 // This one should not be called for CMS. 1222 virtual void par_promote_alloc_undo(int thread_num, 1223 HeapWord* obj, size_t word_sz); 1224 virtual void par_promote_alloc_done(int thread_num); 1225 virtual void par_oop_since_save_marks_iterate_done(int thread_num); 1226 1227 virtual bool promotion_attempt_is_safe(size_t promotion_in_bytes) const; 1228 1229 // Inform this (non-young) generation that a promotion failure was 1230 // encountered during a collection of a younger generation that 1231 // promotes into this generation. 1232 virtual void promotion_failure_occurred(); 1233 1234 bool should_collect(bool full, size_t size, bool tlab); 1235 virtual bool should_concurrent_collect() const; 1236 virtual bool is_too_full() const; 1237 void collect(bool full, 1238 bool clear_all_soft_refs, 1239 size_t size, 1240 bool tlab); 1241 1242 HeapWord* expand_and_allocate(size_t word_size, 1243 bool tlab, 1244 bool parallel = false); 1245 1246 // GC prologue and epilogue 1247 void gc_prologue(bool full); 1248 void gc_prologue_work(bool full, bool registerClosure, 1249 ModUnionClosure* modUnionClosure); 1250 void gc_epilogue(bool full); 1251 void gc_epilogue_work(bool full); 1252 1253 // Time since last GC of this generation 1254 jlong time_of_last_gc(jlong now) { 1255 return collector()->time_of_last_gc(now); 1256 } 1257 void update_time_of_last_gc(jlong now) { 1258 collector()-> update_time_of_last_gc(now); 1259 } 1260 1261 // Allocation failure 1262 void expand(size_t bytes, size_t expand_bytes, 1263 CMSExpansionCause::Cause cause); 1264 virtual bool expand(size_t bytes, size_t expand_bytes); 1265 void shrink(size_t bytes); 1266 HeapWord* expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz); 1267 bool expand_and_ensure_spooling_space(PromotionInfo* promo); 1268 1269 // Iteration support and related enquiries 1270 void save_marks(); 1271 bool no_allocs_since_save_marks(); 1272 void object_iterate_since_last_GC(ObjectClosure* cl); 1273 void younger_refs_iterate(OopsInGenClosure* cl); 1274 1275 // Iteration support specific to CMS generations 1276 void save_sweep_limit(); 1277 1278 // More iteration support 1279 virtual void oop_iterate(MemRegion mr, OopClosure* cl); 1280 virtual void oop_iterate(OopClosure* cl); 1281 virtual void safe_object_iterate(ObjectClosure* cl); 1282 virtual void object_iterate(ObjectClosure* cl); 1283 1284 // Need to declare the full complement of closures, whether we'll 1285 // override them or not, or get message from the compiler: 1286 // oop_since_save_marks_iterate_nv hides virtual function... 1287 #define CMS_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ 1288 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl); 1289 ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DECL) 1290 1291 // Smart allocation XXX -- move to CFLSpace? 1292 void setNearLargestChunk(); 1293 bool isNearLargestChunk(HeapWord* addr); 1294 1295 // Get the chunk at the end of the space. Delagates to 1296 // the space. 1297 FreeChunk* find_chunk_at_end(); 1298 1299 // Overriding of unused functionality (sharing not yet supported with CMS) 1300 void pre_adjust_pointers(); 1301 void post_compact(); 1302 1303 // Debugging 1304 void prepare_for_verify(); 1305 void verify(); 1306 void print_statistics() PRODUCT_RETURN; 1307 1308 // Performance Counters support 1309 virtual void update_counters(); 1310 virtual void update_counters(size_t used); 1311 void initialize_performance_counters(); 1312 CollectorCounters* counters() { return collector()->counters(); } 1313 1314 // Support for parallel remark of survivor space 1315 void* get_data_recorder(int thr_num) { 1316 //Delegate to collector 1317 return collector()->get_data_recorder(thr_num); 1318 } 1319 1320 // Printing 1321 const char* name() const; 1322 virtual const char* short_name() const { return "CMS"; } 1323 void print() const; 1324 void printOccupancy(const char* s); 1325 bool must_be_youngest() const { return false; } 1326 bool must_be_oldest() const { return true; } 1327 1328 void compute_new_size(); 1329 1330 CollectionTypes debug_collection_type() { return _debug_collection_type; } 1331 void rotate_debug_collection_type(); 1332 }; 1333 1334 class ASConcurrentMarkSweepGeneration : public ConcurrentMarkSweepGeneration { 1335 1336 // Return the size policy from the heap's collector 1337 // policy casted to CMSAdaptiveSizePolicy*. 1338 CMSAdaptiveSizePolicy* cms_size_policy() const; 1339 1340 // Resize the generation based on the adaptive size 1341 // policy. 1342 void resize(size_t cur_promo, size_t desired_promo); 1343 1344 // Return the GC counters from the collector policy 1345 CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters(); 1346 1347 virtual void shrink_by(size_t bytes); 1348 1349 public: 1350 virtual void compute_new_size(); 1351 ASConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size, 1352 int level, CardTableRS* ct, 1353 bool use_adaptive_freelists, 1354 FreeBlockDictionary<FreeChunk>::DictionaryChoice 1355 dictionaryChoice) : 1356 ConcurrentMarkSweepGeneration(rs, initial_byte_size, level, ct, 1357 use_adaptive_freelists, dictionaryChoice) {} 1358 1359 virtual const char* short_name() const { return "ASCMS"; } 1360 virtual Generation::Name kind() { return Generation::ASConcurrentMarkSweep; } 1361 1362 virtual void update_counters(); 1363 virtual void update_counters(size_t used); 1364 }; 1365 1366 // 1367 // Closures of various sorts used by CMS to accomplish its work 1368 // 1369 1370 // This closure is used to check that a certain set of oops is empty. 1371 class FalseClosure: public OopClosure { 1372 public: 1373 void do_oop(oop* p) { guarantee(false, "Should be an empty set"); } 1374 void do_oop(narrowOop* p) { guarantee(false, "Should be an empty set"); } 1375 }; 1376 1377 // This closure is used to do concurrent marking from the roots 1378 // following the first checkpoint. 1379 class MarkFromRootsClosure: public BitMapClosure { 1380 CMSCollector* _collector; 1381 MemRegion _span; 1382 CMSBitMap* _bitMap; 1383 CMSBitMap* _mut; 1384 CMSMarkStack* _markStack; 1385 CMSMarkStack* _revisitStack; 1386 bool _yield; 1387 int _skipBits; 1388 HeapWord* _finger; 1389 HeapWord* _threshold; 1390 DEBUG_ONLY(bool _verifying;) 1391 1392 public: 1393 MarkFromRootsClosure(CMSCollector* collector, MemRegion span, 1394 CMSBitMap* bitMap, 1395 CMSMarkStack* markStack, 1396 CMSMarkStack* revisitStack, 1397 bool should_yield, bool verifying = false); 1398 bool do_bit(size_t offset); 1399 void reset(HeapWord* addr); 1400 inline void do_yield_check(); 1401 1402 private: 1403 void scanOopsInOop(HeapWord* ptr); 1404 void do_yield_work(); 1405 }; 1406 1407 // This closure is used to do concurrent multi-threaded 1408 // marking from the roots following the first checkpoint. 1409 // XXX This should really be a subclass of The serial version 1410 // above, but i have not had the time to refactor things cleanly. 1411 // That willbe done for Dolphin. 1412 class Par_MarkFromRootsClosure: public BitMapClosure { 1413 CMSCollector* _collector; 1414 MemRegion _whole_span; 1415 MemRegion _span; 1416 CMSBitMap* _bit_map; 1417 CMSBitMap* _mut; 1418 OopTaskQueue* _work_queue; 1419 CMSMarkStack* _overflow_stack; 1420 CMSMarkStack* _revisit_stack; 1421 bool _yield; 1422 int _skip_bits; 1423 HeapWord* _finger; 1424 HeapWord* _threshold; 1425 CMSConcMarkingTask* _task; 1426 public: 1427 Par_MarkFromRootsClosure(CMSConcMarkingTask* task, CMSCollector* collector, 1428 MemRegion span, 1429 CMSBitMap* bit_map, 1430 OopTaskQueue* work_queue, 1431 CMSMarkStack* overflow_stack, 1432 CMSMarkStack* revisit_stack, 1433 bool should_yield); 1434 bool do_bit(size_t offset); 1435 inline void do_yield_check(); 1436 1437 private: 1438 void scan_oops_in_oop(HeapWord* ptr); 1439 void do_yield_work(); 1440 bool get_work_from_overflow_stack(); 1441 }; 1442 1443 // The following closures are used to do certain kinds of verification of 1444 // CMS marking. 1445 class PushAndMarkVerifyClosure: public OopClosure { 1446 CMSCollector* _collector; 1447 MemRegion _span; 1448 CMSBitMap* _verification_bm; 1449 CMSBitMap* _cms_bm; 1450 CMSMarkStack* _mark_stack; 1451 protected: 1452 void do_oop(oop p); 1453 template <class T> inline void do_oop_work(T *p) { 1454 oop obj = oopDesc::load_decode_heap_oop_not_null(p); 1455 do_oop(obj); 1456 } 1457 public: 1458 PushAndMarkVerifyClosure(CMSCollector* cms_collector, 1459 MemRegion span, 1460 CMSBitMap* verification_bm, 1461 CMSBitMap* cms_bm, 1462 CMSMarkStack* mark_stack); 1463 void do_oop(oop* p); 1464 void do_oop(narrowOop* p); 1465 // Deal with a stack overflow condition 1466 void handle_stack_overflow(HeapWord* lost); 1467 }; 1468 1469 class MarkFromRootsVerifyClosure: public BitMapClosure { 1470 CMSCollector* _collector; 1471 MemRegion _span; 1472 CMSBitMap* _verification_bm; 1473 CMSBitMap* _cms_bm; 1474 CMSMarkStack* _mark_stack; 1475 HeapWord* _finger; 1476 PushAndMarkVerifyClosure _pam_verify_closure; 1477 public: 1478 MarkFromRootsVerifyClosure(CMSCollector* collector, MemRegion span, 1479 CMSBitMap* verification_bm, 1480 CMSBitMap* cms_bm, 1481 CMSMarkStack* mark_stack); 1482 bool do_bit(size_t offset); 1483 void reset(HeapWord* addr); 1484 }; 1485 1486 1487 // This closure is used to check that a certain set of bits is 1488 // "empty" (i.e. the bit vector doesn't have any 1-bits). 1489 class FalseBitMapClosure: public BitMapClosure { 1490 public: 1491 bool do_bit(size_t offset) { 1492 guarantee(false, "Should not have a 1 bit"); 1493 return true; 1494 } 1495 }; 1496 1497 // This closure is used during the second checkpointing phase 1498 // to rescan the marked objects on the dirty cards in the mod 1499 // union table and the card table proper. It's invoked via 1500 // MarkFromDirtyCardsClosure below. It uses either 1501 // [Par_]MarkRefsIntoAndScanClosure (Par_ in the parallel case) 1502 // declared in genOopClosures.hpp to accomplish some of its work. 1503 // In the parallel case the bitMap is shared, so access to 1504 // it needs to be suitably synchronized for updates by embedded 1505 // closures that update it; however, this closure itself only 1506 // reads the bit_map and because it is idempotent, is immune to 1507 // reading stale values. 1508 class ScanMarkedObjectsAgainClosure: public UpwardsObjectClosure { 1509 #ifdef ASSERT 1510 CMSCollector* _collector; 1511 MemRegion _span; 1512 union { 1513 CMSMarkStack* _mark_stack; 1514 OopTaskQueue* _work_queue; 1515 }; 1516 #endif // ASSERT 1517 bool _parallel; 1518 CMSBitMap* _bit_map; 1519 union { 1520 MarkRefsIntoAndScanClosure* _scan_closure; 1521 Par_MarkRefsIntoAndScanClosure* _par_scan_closure; 1522 }; 1523 1524 public: 1525 ScanMarkedObjectsAgainClosure(CMSCollector* collector, 1526 MemRegion span, 1527 ReferenceProcessor* rp, 1528 CMSBitMap* bit_map, 1529 CMSMarkStack* mark_stack, 1530 CMSMarkStack* revisit_stack, 1531 MarkRefsIntoAndScanClosure* cl): 1532 #ifdef ASSERT 1533 _collector(collector), 1534 _span(span), 1535 _mark_stack(mark_stack), 1536 #endif // ASSERT 1537 _parallel(false), 1538 _bit_map(bit_map), 1539 _scan_closure(cl) { } 1540 1541 ScanMarkedObjectsAgainClosure(CMSCollector* collector, 1542 MemRegion span, 1543 ReferenceProcessor* rp, 1544 CMSBitMap* bit_map, 1545 OopTaskQueue* work_queue, 1546 CMSMarkStack* revisit_stack, 1547 Par_MarkRefsIntoAndScanClosure* cl): 1548 #ifdef ASSERT 1549 _collector(collector), 1550 _span(span), 1551 _work_queue(work_queue), 1552 #endif // ASSERT 1553 _parallel(true), 1554 _bit_map(bit_map), 1555 _par_scan_closure(cl) { } 1556 1557 void do_object(oop obj) { 1558 guarantee(false, "Call do_object_b(oop, MemRegion) instead"); 1559 } 1560 bool do_object_b(oop obj) { 1561 guarantee(false, "Call do_object_b(oop, MemRegion) form instead"); 1562 return false; 1563 } 1564 bool do_object_bm(oop p, MemRegion mr); 1565 }; 1566 1567 // This closure is used during the second checkpointing phase 1568 // to rescan the marked objects on the dirty cards in the mod 1569 // union table and the card table proper. It invokes 1570 // ScanMarkedObjectsAgainClosure above to accomplish much of its work. 1571 // In the parallel case, the bit map is shared and requires 1572 // synchronized access. 1573 class MarkFromDirtyCardsClosure: public MemRegionClosure { 1574 CompactibleFreeListSpace* _space; 1575 ScanMarkedObjectsAgainClosure _scan_cl; 1576 size_t _num_dirty_cards; 1577 1578 public: 1579 MarkFromDirtyCardsClosure(CMSCollector* collector, 1580 MemRegion span, 1581 CompactibleFreeListSpace* space, 1582 CMSBitMap* bit_map, 1583 CMSMarkStack* mark_stack, 1584 CMSMarkStack* revisit_stack, 1585 MarkRefsIntoAndScanClosure* cl): 1586 _space(space), 1587 _num_dirty_cards(0), 1588 _scan_cl(collector, span, collector->ref_processor(), bit_map, 1589 mark_stack, revisit_stack, cl) { } 1590 1591 MarkFromDirtyCardsClosure(CMSCollector* collector, 1592 MemRegion span, 1593 CompactibleFreeListSpace* space, 1594 CMSBitMap* bit_map, 1595 OopTaskQueue* work_queue, 1596 CMSMarkStack* revisit_stack, 1597 Par_MarkRefsIntoAndScanClosure* cl): 1598 _space(space), 1599 _num_dirty_cards(0), 1600 _scan_cl(collector, span, collector->ref_processor(), bit_map, 1601 work_queue, revisit_stack, cl) { } 1602 1603 void do_MemRegion(MemRegion mr); 1604 void set_space(CompactibleFreeListSpace* space) { _space = space; } 1605 size_t num_dirty_cards() { return _num_dirty_cards; } 1606 }; 1607 1608 // This closure is used in the non-product build to check 1609 // that there are no MemRegions with a certain property. 1610 class FalseMemRegionClosure: public MemRegionClosure { 1611 void do_MemRegion(MemRegion mr) { 1612 guarantee(!mr.is_empty(), "Shouldn't be empty"); 1613 guarantee(false, "Should never be here"); 1614 } 1615 }; 1616 1617 // This closure is used during the precleaning phase 1618 // to "carefully" rescan marked objects on dirty cards. 1619 // It uses MarkRefsIntoAndScanClosure declared in genOopClosures.hpp 1620 // to accomplish some of its work. 1621 class ScanMarkedObjectsAgainCarefullyClosure: public ObjectClosureCareful { 1622 CMSCollector* _collector; 1623 MemRegion _span; 1624 bool _yield; 1625 Mutex* _freelistLock; 1626 CMSBitMap* _bitMap; 1627 CMSMarkStack* _markStack; 1628 MarkRefsIntoAndScanClosure* _scanningClosure; 1629 1630 public: 1631 ScanMarkedObjectsAgainCarefullyClosure(CMSCollector* collector, 1632 MemRegion span, 1633 CMSBitMap* bitMap, 1634 CMSMarkStack* markStack, 1635 CMSMarkStack* revisitStack, 1636 MarkRefsIntoAndScanClosure* cl, 1637 bool should_yield): 1638 _collector(collector), 1639 _span(span), 1640 _yield(should_yield), 1641 _bitMap(bitMap), 1642 _markStack(markStack), 1643 _scanningClosure(cl) { 1644 } 1645 1646 void do_object(oop p) { 1647 guarantee(false, "call do_object_careful instead"); 1648 } 1649 1650 size_t do_object_careful(oop p) { 1651 guarantee(false, "Unexpected caller"); 1652 return 0; 1653 } 1654 1655 size_t do_object_careful_m(oop p, MemRegion mr); 1656 1657 void setFreelistLock(Mutex* m) { 1658 _freelistLock = m; 1659 _scanningClosure->set_freelistLock(m); 1660 } 1661 1662 private: 1663 inline bool do_yield_check(); 1664 1665 void do_yield_work(); 1666 }; 1667 1668 class SurvivorSpacePrecleanClosure: public ObjectClosureCareful { 1669 CMSCollector* _collector; 1670 MemRegion _span; 1671 bool _yield; 1672 CMSBitMap* _bit_map; 1673 CMSMarkStack* _mark_stack; 1674 PushAndMarkClosure* _scanning_closure; 1675 unsigned int _before_count; 1676 1677 public: 1678 SurvivorSpacePrecleanClosure(CMSCollector* collector, 1679 MemRegion span, 1680 CMSBitMap* bit_map, 1681 CMSMarkStack* mark_stack, 1682 PushAndMarkClosure* cl, 1683 unsigned int before_count, 1684 bool should_yield): 1685 _collector(collector), 1686 _span(span), 1687 _yield(should_yield), 1688 _bit_map(bit_map), 1689 _mark_stack(mark_stack), 1690 _scanning_closure(cl), 1691 _before_count(before_count) 1692 { } 1693 1694 void do_object(oop p) { 1695 guarantee(false, "call do_object_careful instead"); 1696 } 1697 1698 size_t do_object_careful(oop p); 1699 1700 size_t do_object_careful_m(oop p, MemRegion mr) { 1701 guarantee(false, "Unexpected caller"); 1702 return 0; 1703 } 1704 1705 private: 1706 inline void do_yield_check(); 1707 void do_yield_work(); 1708 }; 1709 1710 // This closure is used to accomplish the sweeping work 1711 // after the second checkpoint but before the concurrent reset 1712 // phase. 1713 // 1714 // Terminology 1715 // left hand chunk (LHC) - block of one or more chunks currently being 1716 // coalesced. The LHC is available for coalescing with a new chunk. 1717 // right hand chunk (RHC) - block that is currently being swept that is 1718 // free or garbage that can be coalesced with the LHC. 1719 // _inFreeRange is true if there is currently a LHC 1720 // _lastFreeRangeCoalesced is true if the LHC consists of more than one chunk. 1721 // _freeRangeInFreeLists is true if the LHC is in the free lists. 1722 // _freeFinger is the address of the current LHC 1723 class SweepClosure: public BlkClosureCareful { 1724 CMSCollector* _collector; // collector doing the work 1725 ConcurrentMarkSweepGeneration* _g; // Generation being swept 1726 CompactibleFreeListSpace* _sp; // Space being swept 1727 HeapWord* _limit;// the address at or above which the sweep should stop 1728 // because we do not expect newly garbage blocks 1729 // eligible for sweeping past that address. 1730 Mutex* _freelistLock; // Free list lock (in space) 1731 CMSBitMap* _bitMap; // Marking bit map (in 1732 // generation) 1733 bool _inFreeRange; // Indicates if we are in the 1734 // midst of a free run 1735 bool _freeRangeInFreeLists; 1736 // Often, we have just found 1737 // a free chunk and started 1738 // a new free range; we do not 1739 // eagerly remove this chunk from 1740 // the free lists unless there is 1741 // a possibility of coalescing. 1742 // When true, this flag indicates 1743 // that the _freeFinger below 1744 // points to a potentially free chunk 1745 // that may still be in the free lists 1746 bool _lastFreeRangeCoalesced; 1747 // free range contains chunks 1748 // coalesced 1749 bool _yield; 1750 // Whether sweeping should be 1751 // done with yields. For instance 1752 // when done by the foreground 1753 // collector we shouldn't yield. 1754 HeapWord* _freeFinger; // When _inFreeRange is set, the 1755 // pointer to the "left hand 1756 // chunk" 1757 size_t _freeRangeSize; 1758 // When _inFreeRange is set, this 1759 // indicates the accumulated size 1760 // of the "left hand chunk" 1761 NOT_PRODUCT( 1762 size_t _numObjectsFreed; 1763 size_t _numWordsFreed; 1764 size_t _numObjectsLive; 1765 size_t _numWordsLive; 1766 size_t _numObjectsAlreadyFree; 1767 size_t _numWordsAlreadyFree; 1768 FreeChunk* _last_fc; 1769 ) 1770 private: 1771 // Code that is common to a free chunk or garbage when 1772 // encountered during sweeping. 1773 void do_post_free_or_garbage_chunk(FreeChunk *fc, size_t chunkSize); 1774 // Process a free chunk during sweeping. 1775 void do_already_free_chunk(FreeChunk *fc); 1776 // Work method called when processing an already free or a 1777 // freshly garbage chunk to do a lookahead and possibly a 1778 // premptive flush if crossing over _limit. 1779 void lookahead_and_flush(FreeChunk* fc, size_t chunkSize); 1780 // Process a garbage chunk during sweeping. 1781 size_t do_garbage_chunk(FreeChunk *fc); 1782 // Process a live chunk during sweeping. 1783 size_t do_live_chunk(FreeChunk* fc); 1784 1785 // Accessors. 1786 HeapWord* freeFinger() const { return _freeFinger; } 1787 void set_freeFinger(HeapWord* v) { _freeFinger = v; } 1788 bool inFreeRange() const { return _inFreeRange; } 1789 void set_inFreeRange(bool v) { _inFreeRange = v; } 1790 bool lastFreeRangeCoalesced() const { return _lastFreeRangeCoalesced; } 1791 void set_lastFreeRangeCoalesced(bool v) { _lastFreeRangeCoalesced = v; } 1792 bool freeRangeInFreeLists() const { return _freeRangeInFreeLists; } 1793 void set_freeRangeInFreeLists(bool v) { _freeRangeInFreeLists = v; } 1794 1795 // Initialize a free range. 1796 void initialize_free_range(HeapWord* freeFinger, bool freeRangeInFreeLists); 1797 // Return this chunk to the free lists. 1798 void flush_cur_free_chunk(HeapWord* chunk, size_t size); 1799 1800 // Check if we should yield and do so when necessary. 1801 inline void do_yield_check(HeapWord* addr); 1802 1803 // Yield 1804 void do_yield_work(HeapWord* addr); 1805 1806 // Debugging/Printing 1807 void print_free_block_coalesced(FreeChunk* fc) const; 1808 1809 public: 1810 SweepClosure(CMSCollector* collector, ConcurrentMarkSweepGeneration* g, 1811 CMSBitMap* bitMap, bool should_yield); 1812 ~SweepClosure() PRODUCT_RETURN; 1813 1814 size_t do_blk_careful(HeapWord* addr); 1815 void print() const { print_on(tty); } 1816 void print_on(outputStream *st) const; 1817 }; 1818 1819 // Closures related to weak references processing 1820 1821 // During CMS' weak reference processing, this is a 1822 // work-routine/closure used to complete transitive 1823 // marking of objects as live after a certain point 1824 // in which an initial set has been completely accumulated. 1825 // This closure is currently used both during the final 1826 // remark stop-world phase, as well as during the concurrent 1827 // precleaning of the discovered reference lists. 1828 class CMSDrainMarkingStackClosure: public VoidClosure { 1829 CMSCollector* _collector; 1830 MemRegion _span; 1831 CMSMarkStack* _mark_stack; 1832 CMSBitMap* _bit_map; 1833 CMSKeepAliveClosure* _keep_alive; 1834 bool _concurrent_precleaning; 1835 public: 1836 CMSDrainMarkingStackClosure(CMSCollector* collector, MemRegion span, 1837 CMSBitMap* bit_map, CMSMarkStack* mark_stack, 1838 CMSKeepAliveClosure* keep_alive, 1839 bool cpc): 1840 _collector(collector), 1841 _span(span), 1842 _bit_map(bit_map), 1843 _mark_stack(mark_stack), 1844 _keep_alive(keep_alive), 1845 _concurrent_precleaning(cpc) { 1846 assert(_concurrent_precleaning == _keep_alive->concurrent_precleaning(), 1847 "Mismatch"); 1848 } 1849 1850 void do_void(); 1851 }; 1852 1853 // A parallel version of CMSDrainMarkingStackClosure above. 1854 class CMSParDrainMarkingStackClosure: public VoidClosure { 1855 CMSCollector* _collector; 1856 MemRegion _span; 1857 OopTaskQueue* _work_queue; 1858 CMSBitMap* _bit_map; 1859 CMSInnerParMarkAndPushClosure _mark_and_push; 1860 1861 public: 1862 CMSParDrainMarkingStackClosure(CMSCollector* collector, 1863 MemRegion span, CMSBitMap* bit_map, 1864 CMSMarkStack* revisit_stack, 1865 OopTaskQueue* work_queue): 1866 _collector(collector), 1867 _span(span), 1868 _bit_map(bit_map), 1869 _work_queue(work_queue), 1870 _mark_and_push(collector, span, bit_map, revisit_stack, work_queue) { } 1871 1872 public: 1873 void trim_queue(uint max); 1874 void do_void(); 1875 }; 1876 1877 // Allow yielding or short-circuiting of reference list 1878 // prelceaning work. 1879 class CMSPrecleanRefsYieldClosure: public YieldClosure { 1880 CMSCollector* _collector; 1881 void do_yield_work(); 1882 public: 1883 CMSPrecleanRefsYieldClosure(CMSCollector* collector): 1884 _collector(collector) {} 1885 virtual bool should_return(); 1886 }; 1887 1888 1889 // Convenience class that locks free list locks for given CMS collector 1890 class FreelistLocker: public StackObj { 1891 private: 1892 CMSCollector* _collector; 1893 public: 1894 FreelistLocker(CMSCollector* collector): 1895 _collector(collector) { 1896 _collector->getFreelistLocks(); 1897 } 1898 1899 ~FreelistLocker() { 1900 _collector->releaseFreelistLocks(); 1901 } 1902 }; 1903 1904 // Mark all dead objects in a given space. 1905 class MarkDeadObjectsClosure: public BlkClosure { 1906 const CMSCollector* _collector; 1907 const CompactibleFreeListSpace* _sp; 1908 CMSBitMap* _live_bit_map; 1909 CMSBitMap* _dead_bit_map; 1910 public: 1911 MarkDeadObjectsClosure(const CMSCollector* collector, 1912 const CompactibleFreeListSpace* sp, 1913 CMSBitMap *live_bit_map, 1914 CMSBitMap *dead_bit_map) : 1915 _collector(collector), 1916 _sp(sp), 1917 _live_bit_map(live_bit_map), 1918 _dead_bit_map(dead_bit_map) {} 1919 size_t do_blk(HeapWord* addr); 1920 }; 1921 1922 class TraceCMSMemoryManagerStats : public TraceMemoryManagerStats { 1923 1924 public: 1925 TraceCMSMemoryManagerStats(CMSCollector::CollectorState phase, GCCause::Cause cause); 1926 }; 1927 1928 1929 #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CONCURRENTMARKSWEEPGENERATION_HPP