521 -1 /* lock-free */, "No_lock" /* dummy */),
522 _modUnionClosure(&_modUnionTable),
523 _modUnionClosurePar(&_modUnionTable),
524 // Adjust my span to cover old (cms) gen and perm gen
525 _span(cmsGen->reserved()._union(permGen->reserved())),
526 // Construct the is_alive_closure with _span & markBitMap
527 _is_alive_closure(_span, &_markBitMap),
528 _restart_addr(NULL),
529 _overflow_list(NULL),
530 _preserved_oop_stack(NULL),
531 _preserved_mark_stack(NULL),
532 _stats(cmsGen),
533 _eden_chunk_array(NULL), // may be set in ctor body
534 _eden_chunk_capacity(0), // -- ditto --
535 _eden_chunk_index(0), // -- ditto --
536 _survivor_plab_array(NULL), // -- ditto --
537 _survivor_chunk_array(NULL), // -- ditto --
538 _survivor_chunk_capacity(0), // -- ditto --
539 _survivor_chunk_index(0), // -- ditto --
540 _ser_pmc_preclean_ovflw(0),
541 _ser_pmc_remark_ovflw(0),
542 _par_pmc_remark_ovflw(0),
543 _ser_kac_ovflw(0),
544 _par_kac_ovflw(0),
545 #ifndef PRODUCT
546 _num_par_pushes(0),
547 #endif
548 _collection_count_start(0),
549 _verifying(false),
550 _icms_start_limit(NULL),
551 _icms_stop_limit(NULL),
552 _verification_mark_bm(0, Mutex::leaf + 1, "CMS_verification_mark_bm_lock"),
553 _completed_initialization(false),
554 _collector_policy(cp),
555 _should_unload_classes(false),
556 _concurrent_cycles_since_last_unload(0),
557 _sweep_estimate(CMS_SweepWeight, CMS_SweepPadding)
558 {
559 if (ExplicitGCInvokesConcurrentAndUnloadsClasses) {
560 ExplicitGCInvokesConcurrent = true;
4371 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) {
4372 _abort_preclean = true;
4373 }
4374 }
4375 }
4376
4377
4378 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) {
4379 assert(_collectorState == Precleaning ||
4380 _collectorState == AbortablePreclean, "incorrect state");
4381 ResourceMark rm;
4382 HandleMark hm;
4383 // Do one pass of scrubbing the discovered reference lists
4384 // to remove any reference objects with strongly-reachable
4385 // referents.
4386 if (clean_refs) {
4387 ReferenceProcessor* rp = ref_processor();
4388 CMSPrecleanRefsYieldClosure yield_cl(this);
4389 assert(rp->span().equals(_span), "Spans should be equal");
4390 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap,
4391 &_markStack);
4392 CMSDrainMarkingStackClosure complete_trace(this,
4393 _span, &_markBitMap, &_markStack,
4394 &keep_alive);
4395
4396 // We don't want this step to interfere with a young
4397 // collection because we don't want to take CPU
4398 // or memory bandwidth away from the young GC threads
4399 // (which may be as many as there are CPUs).
4400 // Note that we don't need to protect ourselves from
4401 // interference with mutators because they can't
4402 // manipulate the discovered reference lists nor affect
4403 // the computed reachability of the referents, the
4404 // only properties manipulated by the precleaning
4405 // of these reference lists.
4406 stopTimer();
4407 CMSTokenSyncWithLocks x(true /* is cms thread */,
4408 bitMapLock());
4409 startTimer();
4410 sample_eden();
4411 // The following will yield to allow foreground
4412 // collection to proceed promptly. XXX YSR:
4413 // The code in this method may need further
4414 // tweaking for better performance and some restructuring
4835 verify_work_stacks_empty();
4836 verify_overflow_empty();
4837
4838 {
4839 NOT_PRODUCT(TraceTime ts("refProcessingWork", PrintGCDetails, false, gclog_or_tty);)
4840 refProcessingWork(asynch, clear_all_soft_refs);
4841 }
4842 verify_work_stacks_empty();
4843 verify_overflow_empty();
4844
4845 if (should_unload_classes()) {
4846 CodeCache::gc_epilogue();
4847 }
4848
4849 // If we encountered any (marking stack / work queue) overflow
4850 // events during the current CMS cycle, take appropriate
4851 // remedial measures, where possible, so as to try and avoid
4852 // recurrence of that condition.
4853 assert(_markStack.isEmpty(), "No grey objects");
4854 size_t ser_ovflw = _ser_pmc_remark_ovflw + _ser_pmc_preclean_ovflw +
4855 _ser_kac_ovflw;
4856 if (ser_ovflw > 0) {
4857 if (PrintCMSStatistics != 0) {
4858 gclog_or_tty->print_cr("Marking stack overflow (benign) "
4859 "(pmc_pc="SIZE_FORMAT", pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")",
4860 _ser_pmc_preclean_ovflw, _ser_pmc_remark_ovflw,
4861 _ser_kac_ovflw);
4862 }
4863 _markStack.expand();
4864 _ser_pmc_remark_ovflw = 0;
4865 _ser_pmc_preclean_ovflw = 0;
4866 _ser_kac_ovflw = 0;
4867 }
4868 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) {
4869 if (PrintCMSStatistics != 0) {
4870 gclog_or_tty->print_cr("Work queue overflow (benign) "
4871 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")",
4872 _par_pmc_remark_ovflw, _par_kac_ovflw);
4873 }
4874 _par_pmc_remark_ovflw = 0;
4875 _par_kac_ovflw = 0;
4876 }
4877 if (PrintCMSStatistics != 0) {
4878 if (_markStack._hit_limit > 0) {
4879 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")",
4880 _markStack._hit_limit);
4881 }
4882 if (_markStack._failed_double > 0) {
4883 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT"),"
4884 " current capacity "SIZE_FORMAT,
4885 _markStack._failed_double,
5676 ResourceMark rm;
5677 HandleMark hm;
5678 ReferencePolicy* soft_ref_policy;
5679
5680 assert(!ref_processor()->enqueuing_is_done(), "Enqueuing should not be complete");
5681 // Process weak references.
5682 if (clear_all_soft_refs) {
5683 soft_ref_policy = new AlwaysClearPolicy();
5684 } else {
5685 #ifdef COMPILER2
5686 soft_ref_policy = new LRUMaxHeapPolicy();
5687 #else
5688 soft_ref_policy = new LRUCurrentHeapPolicy();
5689 #endif // COMPILER2
5690 }
5691 verify_work_stacks_empty();
5692
5693 ReferenceProcessor* rp = ref_processor();
5694 assert(rp->span().equals(_span), "Spans should be equal");
5695 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap,
5696 &_markStack);
5697 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this,
5698 _span, &_markBitMap, &_markStack,
5699 &cmsKeepAliveClosure);
5700 {
5701 TraceTime t("weak refs processing", PrintGCDetails, false, gclog_or_tty);
5702 if (rp->processing_is_mt()) {
5703 CMSRefProcTaskExecutor task_executor(*this);
5704 rp->process_discovered_references(soft_ref_policy,
5705 &_is_alive_closure,
5706 &cmsKeepAliveClosure,
5707 &cmsDrainMarkingStackClosure,
5708 &task_executor);
5709 } else {
5710 rp->process_discovered_references(soft_ref_policy,
5711 &_is_alive_closure,
5712 &cmsKeepAliveClosure,
5713 &cmsDrainMarkingStackClosure,
5714 NULL);
5715 }
5716 verify_work_stacks_empty();
5717 }
5718
5719 if (should_unload_classes()) {
8285 HeapWord* addr = (HeapWord*)obj;
8286 return addr != NULL &&
8287 (!_span.contains(addr) || _bit_map->isMarked(addr));
8288 }
8289
8290 // CMSKeepAliveClosure: the serial version
8291 void CMSKeepAliveClosure::do_oop(oop obj) {
8292 HeapWord* addr = (HeapWord*)obj;
8293 if (_span.contains(addr) &&
8294 !_bit_map->isMarked(addr)) {
8295 _bit_map->mark(addr);
8296 bool simulate_overflow = false;
8297 NOT_PRODUCT(
8298 if (CMSMarkStackOverflowALot &&
8299 _collector->simulate_overflow()) {
8300 // simulate a stack overflow
8301 simulate_overflow = true;
8302 }
8303 )
8304 if (simulate_overflow || !_mark_stack->push(obj)) {
8305 _collector->push_on_overflow_list(obj);
8306 _collector->_ser_kac_ovflw++;
8307 }
8308 }
8309 }
8310
8311 void CMSKeepAliveClosure::do_oop(oop* p) { CMSKeepAliveClosure::do_oop_work(p); }
8312 void CMSKeepAliveClosure::do_oop(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); }
8313
8314 // CMSParKeepAliveClosure: a parallel version of the above.
8315 // The work queues are private to each closure (thread),
8316 // but (may be) available for stealing by other threads.
8317 void CMSParKeepAliveClosure::do_oop(oop obj) {
8318 HeapWord* addr = (HeapWord*)obj;
8319 if (_span.contains(addr) &&
8320 !_bit_map->isMarked(addr)) {
8321 // In general, during recursive tracing, several threads
8322 // may be concurrently getting here; the first one to
8323 // "tag" it, claims it.
8324 if (_bit_map->par_mark(addr)) {
8325 bool res = _work_queue->push(obj);
8326 assert(res, "Low water mark should be much less than capacity");
8327 // Do a recursive trim in the hope that this will keep
8328 // stack usage lower, but leave some oops for potential stealers
8383 case _satisfy_free_ratio:
8384 return "Free ratio";
8385 case _satisfy_promotion:
8386 return "Satisfy promotion";
8387 case _satisfy_allocation:
8388 return "allocation";
8389 case _allocate_par_lab:
8390 return "Par LAB";
8391 case _allocate_par_spooling_space:
8392 return "Par Spooling Space";
8393 case _adaptive_size_policy:
8394 return "Ergonomics";
8395 default:
8396 return "unknown";
8397 }
8398 }
8399
8400 void CMSDrainMarkingStackClosure::do_void() {
8401 // the max number to take from overflow list at a time
8402 const size_t num = _mark_stack->capacity()/4;
8403 while (!_mark_stack->isEmpty() ||
8404 // if stack is empty, check the overflow list
8405 _collector->take_from_overflow_list(num, _mark_stack)) {
8406 oop obj = _mark_stack->pop();
8407 HeapWord* addr = (HeapWord*)obj;
8408 assert(_span.contains(addr), "Should be within span");
8409 assert(_bit_map->isMarked(addr), "Should be marked");
8410 assert(obj->is_oop(), "Should be an oop");
8411 obj->oop_iterate(_keep_alive);
8412 }
8413 }
8414
8415 void CMSParDrainMarkingStackClosure::do_void() {
8416 // drain queue
8417 trim_queue(0);
8418 }
8419
8420 // Trim our work_queue so its length is below max at return
8421 void CMSParDrainMarkingStackClosure::trim_queue(uint max) {
8422 while (_work_queue->size() > max) {
|
521 -1 /* lock-free */, "No_lock" /* dummy */),
522 _modUnionClosure(&_modUnionTable),
523 _modUnionClosurePar(&_modUnionTable),
524 // Adjust my span to cover old (cms) gen and perm gen
525 _span(cmsGen->reserved()._union(permGen->reserved())),
526 // Construct the is_alive_closure with _span & markBitMap
527 _is_alive_closure(_span, &_markBitMap),
528 _restart_addr(NULL),
529 _overflow_list(NULL),
530 _preserved_oop_stack(NULL),
531 _preserved_mark_stack(NULL),
532 _stats(cmsGen),
533 _eden_chunk_array(NULL), // may be set in ctor body
534 _eden_chunk_capacity(0), // -- ditto --
535 _eden_chunk_index(0), // -- ditto --
536 _survivor_plab_array(NULL), // -- ditto --
537 _survivor_chunk_array(NULL), // -- ditto --
538 _survivor_chunk_capacity(0), // -- ditto --
539 _survivor_chunk_index(0), // -- ditto --
540 _ser_pmc_preclean_ovflw(0),
541 _ser_kac_preclean_ovflw(0),
542 _ser_pmc_remark_ovflw(0),
543 _par_pmc_remark_ovflw(0),
544 _ser_kac_ovflw(0),
545 _par_kac_ovflw(0),
546 #ifndef PRODUCT
547 _num_par_pushes(0),
548 #endif
549 _collection_count_start(0),
550 _verifying(false),
551 _icms_start_limit(NULL),
552 _icms_stop_limit(NULL),
553 _verification_mark_bm(0, Mutex::leaf + 1, "CMS_verification_mark_bm_lock"),
554 _completed_initialization(false),
555 _collector_policy(cp),
556 _should_unload_classes(false),
557 _concurrent_cycles_since_last_unload(0),
558 _sweep_estimate(CMS_SweepWeight, CMS_SweepPadding)
559 {
560 if (ExplicitGCInvokesConcurrentAndUnloadsClasses) {
561 ExplicitGCInvokesConcurrent = true;
4372 if (used > (capacity/100 * CMSScheduleRemarkEdenPenetration)) {
4373 _abort_preclean = true;
4374 }
4375 }
4376 }
4377
4378
4379 size_t CMSCollector::preclean_work(bool clean_refs, bool clean_survivor) {
4380 assert(_collectorState == Precleaning ||
4381 _collectorState == AbortablePreclean, "incorrect state");
4382 ResourceMark rm;
4383 HandleMark hm;
4384 // Do one pass of scrubbing the discovered reference lists
4385 // to remove any reference objects with strongly-reachable
4386 // referents.
4387 if (clean_refs) {
4388 ReferenceProcessor* rp = ref_processor();
4389 CMSPrecleanRefsYieldClosure yield_cl(this);
4390 assert(rp->span().equals(_span), "Spans should be equal");
4391 CMSKeepAliveClosure keep_alive(this, _span, &_markBitMap,
4392 &_markStack, true /* preclean */);
4393 CMSDrainMarkingStackClosure complete_trace(this,
4394 _span, &_markBitMap, &_markStack,
4395 &keep_alive, true /* preclean */);
4396
4397 // We don't want this step to interfere with a young
4398 // collection because we don't want to take CPU
4399 // or memory bandwidth away from the young GC threads
4400 // (which may be as many as there are CPUs).
4401 // Note that we don't need to protect ourselves from
4402 // interference with mutators because they can't
4403 // manipulate the discovered reference lists nor affect
4404 // the computed reachability of the referents, the
4405 // only properties manipulated by the precleaning
4406 // of these reference lists.
4407 stopTimer();
4408 CMSTokenSyncWithLocks x(true /* is cms thread */,
4409 bitMapLock());
4410 startTimer();
4411 sample_eden();
4412 // The following will yield to allow foreground
4413 // collection to proceed promptly. XXX YSR:
4414 // The code in this method may need further
4415 // tweaking for better performance and some restructuring
4836 verify_work_stacks_empty();
4837 verify_overflow_empty();
4838
4839 {
4840 NOT_PRODUCT(TraceTime ts("refProcessingWork", PrintGCDetails, false, gclog_or_tty);)
4841 refProcessingWork(asynch, clear_all_soft_refs);
4842 }
4843 verify_work_stacks_empty();
4844 verify_overflow_empty();
4845
4846 if (should_unload_classes()) {
4847 CodeCache::gc_epilogue();
4848 }
4849
4850 // If we encountered any (marking stack / work queue) overflow
4851 // events during the current CMS cycle, take appropriate
4852 // remedial measures, where possible, so as to try and avoid
4853 // recurrence of that condition.
4854 assert(_markStack.isEmpty(), "No grey objects");
4855 size_t ser_ovflw = _ser_pmc_remark_ovflw + _ser_pmc_preclean_ovflw +
4856 _ser_kac_ovflw + _ser_kac_preclean_ovflw;
4857 if (ser_ovflw > 0) {
4858 if (PrintCMSStatistics != 0) {
4859 gclog_or_tty->print_cr("Marking stack overflow (benign) "
4860 "(pmc_pc="SIZE_FORMAT", pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT
4861 ", kac_preclean="SIZE_FORMAT")",
4862 _ser_pmc_preclean_ovflw, _ser_pmc_remark_ovflw,
4863 _ser_kac_ovflw, _ser_kac_preclean_ovflw);
4864 }
4865 _markStack.expand();
4866 _ser_pmc_remark_ovflw = 0;
4867 _ser_pmc_preclean_ovflw = 0;
4868 _ser_kac_preclean_ovflw = 0;
4869 _ser_kac_ovflw = 0;
4870 }
4871 if (_par_pmc_remark_ovflw > 0 || _par_kac_ovflw > 0) {
4872 if (PrintCMSStatistics != 0) {
4873 gclog_or_tty->print_cr("Work queue overflow (benign) "
4874 "(pmc_rm="SIZE_FORMAT", kac="SIZE_FORMAT")",
4875 _par_pmc_remark_ovflw, _par_kac_ovflw);
4876 }
4877 _par_pmc_remark_ovflw = 0;
4878 _par_kac_ovflw = 0;
4879 }
4880 if (PrintCMSStatistics != 0) {
4881 if (_markStack._hit_limit > 0) {
4882 gclog_or_tty->print_cr(" (benign) Hit max stack size limit ("SIZE_FORMAT")",
4883 _markStack._hit_limit);
4884 }
4885 if (_markStack._failed_double > 0) {
4886 gclog_or_tty->print_cr(" (benign) Failed stack doubling ("SIZE_FORMAT"),"
4887 " current capacity "SIZE_FORMAT,
4888 _markStack._failed_double,
5679 ResourceMark rm;
5680 HandleMark hm;
5681 ReferencePolicy* soft_ref_policy;
5682
5683 assert(!ref_processor()->enqueuing_is_done(), "Enqueuing should not be complete");
5684 // Process weak references.
5685 if (clear_all_soft_refs) {
5686 soft_ref_policy = new AlwaysClearPolicy();
5687 } else {
5688 #ifdef COMPILER2
5689 soft_ref_policy = new LRUMaxHeapPolicy();
5690 #else
5691 soft_ref_policy = new LRUCurrentHeapPolicy();
5692 #endif // COMPILER2
5693 }
5694 verify_work_stacks_empty();
5695
5696 ReferenceProcessor* rp = ref_processor();
5697 assert(rp->span().equals(_span), "Spans should be equal");
5698 CMSKeepAliveClosure cmsKeepAliveClosure(this, _span, &_markBitMap,
5699 &_markStack, false /* !preclean */);
5700 CMSDrainMarkingStackClosure cmsDrainMarkingStackClosure(this,
5701 _span, &_markBitMap, &_markStack,
5702 &cmsKeepAliveClosure, false /* !preclean */);
5703 {
5704 TraceTime t("weak refs processing", PrintGCDetails, false, gclog_or_tty);
5705 if (rp->processing_is_mt()) {
5706 CMSRefProcTaskExecutor task_executor(*this);
5707 rp->process_discovered_references(soft_ref_policy,
5708 &_is_alive_closure,
5709 &cmsKeepAliveClosure,
5710 &cmsDrainMarkingStackClosure,
5711 &task_executor);
5712 } else {
5713 rp->process_discovered_references(soft_ref_policy,
5714 &_is_alive_closure,
5715 &cmsKeepAliveClosure,
5716 &cmsDrainMarkingStackClosure,
5717 NULL);
5718 }
5719 verify_work_stacks_empty();
5720 }
5721
5722 if (should_unload_classes()) {
8288 HeapWord* addr = (HeapWord*)obj;
8289 return addr != NULL &&
8290 (!_span.contains(addr) || _bit_map->isMarked(addr));
8291 }
8292
8293 // CMSKeepAliveClosure: the serial version
8294 void CMSKeepAliveClosure::do_oop(oop obj) {
8295 HeapWord* addr = (HeapWord*)obj;
8296 if (_span.contains(addr) &&
8297 !_bit_map->isMarked(addr)) {
8298 _bit_map->mark(addr);
8299 bool simulate_overflow = false;
8300 NOT_PRODUCT(
8301 if (CMSMarkStackOverflowALot &&
8302 _collector->simulate_overflow()) {
8303 // simulate a stack overflow
8304 simulate_overflow = true;
8305 }
8306 )
8307 if (simulate_overflow || !_mark_stack->push(obj)) {
8308 if (_concurrent_precleaning) {
8309 // We dirty the overflown object and let the remark
8310 // phase deal with it.
8311 assert(_collector->overflow_list_is_empty(), "Error");
8312 // In the case of object arrays, we need to dirty all of
8313 // the cards that the object spans. No locking or atomics
8314 // are needed since no one else can be mutating the mod union
8315 // table.
8316 if (obj->is_objArray()) {
8317 size_t sz = obj->size();
8318 HeapWord* end_card_addr =
8319 (HeapWord*)round_to((intptr_t)(addr+sz), CardTableModRefBS::card_size);
8320 MemRegion redirty_range = MemRegion(addr, end_card_addr);
8321 assert(!redirty_range.is_empty(), "Arithmetical tautology");
8322 _collector->_modUnionTable.mark_range(redirty_range);
8323 } else {
8324 _collector->_modUnionTable.mark(addr);
8325 }
8326 _collector->_ser_kac_preclean_ovflw++;
8327 } else {
8328 _collector->push_on_overflow_list(obj);
8329 _collector->_ser_kac_ovflw++;
8330 }
8331 }
8332 }
8333 }
8334
8335 void CMSKeepAliveClosure::do_oop(oop* p) { CMSKeepAliveClosure::do_oop_work(p); }
8336 void CMSKeepAliveClosure::do_oop(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); }
8337
8338 // CMSParKeepAliveClosure: a parallel version of the above.
8339 // The work queues are private to each closure (thread),
8340 // but (may be) available for stealing by other threads.
8341 void CMSParKeepAliveClosure::do_oop(oop obj) {
8342 HeapWord* addr = (HeapWord*)obj;
8343 if (_span.contains(addr) &&
8344 !_bit_map->isMarked(addr)) {
8345 // In general, during recursive tracing, several threads
8346 // may be concurrently getting here; the first one to
8347 // "tag" it, claims it.
8348 if (_bit_map->par_mark(addr)) {
8349 bool res = _work_queue->push(obj);
8350 assert(res, "Low water mark should be much less than capacity");
8351 // Do a recursive trim in the hope that this will keep
8352 // stack usage lower, but leave some oops for potential stealers
8407 case _satisfy_free_ratio:
8408 return "Free ratio";
8409 case _satisfy_promotion:
8410 return "Satisfy promotion";
8411 case _satisfy_allocation:
8412 return "allocation";
8413 case _allocate_par_lab:
8414 return "Par LAB";
8415 case _allocate_par_spooling_space:
8416 return "Par Spooling Space";
8417 case _adaptive_size_policy:
8418 return "Ergonomics";
8419 default:
8420 return "unknown";
8421 }
8422 }
8423
8424 void CMSDrainMarkingStackClosure::do_void() {
8425 // the max number to take from overflow list at a time
8426 const size_t num = _mark_stack->capacity()/4;
8427 assert(!_concurrent_precleaning || _collector->overflow_list_is_empty(),
8428 "Overflow list should be NULL during concurrent phases");
8429 while (!_mark_stack->isEmpty() ||
8430 // if stack is empty, check the overflow list
8431 _collector->take_from_overflow_list(num, _mark_stack)) {
8432 oop obj = _mark_stack->pop();
8433 HeapWord* addr = (HeapWord*)obj;
8434 assert(_span.contains(addr), "Should be within span");
8435 assert(_bit_map->isMarked(addr), "Should be marked");
8436 assert(obj->is_oop(), "Should be an oop");
8437 obj->oop_iterate(_keep_alive);
8438 }
8439 }
8440
8441 void CMSParDrainMarkingStackClosure::do_void() {
8442 // drain queue
8443 trim_queue(0);
8444 }
8445
8446 // Trim our work_queue so its length is below max at return
8447 void CMSParDrainMarkingStackClosure::trim_queue(uint max) {
8448 while (_work_queue->size() > max) {
|