419 CardTableModRefBS::card_shift,
420 false /* in_resource_area*/),
421
422 _prevMarkBitMap(&_markBitMap1),
423 _nextMarkBitMap(&_markBitMap2),
424
425 _markStack(this),
426 // _finger set in set_non_marking_state
427
428 _max_worker_id(ParallelGCThreads),
429 // _active_tasks set in set_non_marking_state
430 // _tasks set inside the constructor
431 _task_queues(new CMTaskQueueSet((int) _max_worker_id)),
432 _terminator(ParallelTaskTerminator((int) _max_worker_id, _task_queues)),
433
434 _has_overflown(false),
435 _concurrent(false),
436 _has_aborted(false),
437 _restart_for_overflow(false),
438 _concurrent_marking_in_progress(false),
439 _concurrent_marking_from_roots(false),
440
441 // _verbose_level set below
442
443 _init_times(),
444 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(),
445 _cleanup_times(),
446 _total_counting_time(0.0),
447 _total_rs_scrub_time(0.0),
448
449 _parallel_workers(NULL),
450
451 _count_card_bitmaps(NULL),
452 _count_marked_bytes(NULL),
453 _completed_initialization(false) {
454
455 _markBitMap1.initialize(g1h->reserved_region(), prev_bitmap_storage);
456 _markBitMap2.initialize(g1h->reserved_region(), next_bitmap_storage);
457
458 // Create & start a ConcurrentMark thread.
459 _cmThread = new ConcurrentMarkThread(this);
987 // should not attempt to do any further work.
988 if (root_regions()->scan_in_progress()) {
989 GCTraceConcTime(Info, gc) tt("Concurrent Root Region Scan");
990
991 _parallel_marking_threads = calc_parallel_marking_threads();
992 assert(parallel_marking_threads() <= max_parallel_marking_threads(),
993 "Maximum number of marking threads exceeded");
994 uint active_workers = MAX2(1U, parallel_marking_threads());
995
996 CMRootRegionScanTask task(this);
997 _parallel_workers->set_active_workers(active_workers);
998 _parallel_workers->run_task(&task);
999
1000 // It's possible that has_aborted() is true here without actually
1001 // aborting the survivor scan earlier. This is OK as it's
1002 // mainly used for sanity checking.
1003 root_regions()->scan_finished();
1004 }
1005 }
1006
1007 void ConcurrentMark::register_mark_from_roots_phase_start() {
1008 _concurrent_marking_from_roots = true;
1009 _g1h->gc_timer_cm()->register_gc_concurrent_start("Concurrent Mark");
1010 }
1011
1012 void ConcurrentMark::register_mark_from_roots_phase_end() {
1013 _concurrent_marking_from_roots = false;
1014 if (!has_aborted()) {
1015 _g1h->gc_timer_cm()->register_gc_concurrent_end();
1016 }
1017 }
1018
1019 void ConcurrentMark::markFromRoots() {
1020 // we might be tempted to assert that:
1021 // assert(asynch == !SafepointSynchronize::is_at_safepoint(),
1022 // "inconsistent argument?");
1023 // However that wouldn't be right, because it's possible that
1024 // a safepoint is indeed in progress as a younger generation
1025 // stop-the-world GC happens even as we mark in this generation.
1026
1027 register_mark_from_roots_phase_start();
1028
1029 _restart_for_overflow = false;
1030
1031 // _g1h has _n_par_threads
1032 _parallel_marking_threads = calc_parallel_marking_threads();
1033 assert(parallel_marking_threads() <= max_parallel_marking_threads(),
1034 "Maximum number of marking threads exceeded");
1035
1036 uint active_workers = MAX2(1U, parallel_marking_threads());
1037 assert(active_workers > 0, "Should have been set");
1038
1039 // Parallel task terminator is set in "set_concurrency_and_phase()"
1040 set_concurrency_and_phase(active_workers, true /* concurrent */);
1041
1042 CMConcurrentMarkingTask markingTask(this, cmThread());
1043 _parallel_workers->set_active_workers(active_workers);
1044 _parallel_workers->run_task(&markingTask);
1045
1046 register_mark_from_roots_phase_end();
1047
1048 print_stats();
1049 }
1050
1051 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) {
1052 // world is stopped at this checkpoint
1053 assert(SafepointSynchronize::is_at_safepoint(),
1054 "world should be stopped");
1055
1056 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1057
1058 // If a full collection has happened, we shouldn't do this.
1059 if (has_aborted()) {
1060 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1061 return;
1062 }
1063
1064 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1065
1066 if (VerifyDuringGC) {
1067 HandleMark hm; // handle scope
2610 // Clear the liveness counting data
2611 clear_all_count_data();
2612 // Empty mark stack
2613 reset_marking_state();
2614 for (uint i = 0; i < _max_worker_id; ++i) {
2615 _tasks[i]->clear_region_fields();
2616 }
2617 _first_overflow_barrier_sync.abort();
2618 _second_overflow_barrier_sync.abort();
2619 _has_aborted = true;
2620
2621 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
2622 satb_mq_set.abandon_partial_marking();
2623 // This can be called either during or outside marking, we'll read
2624 // the expected_active value from the SATB queue set.
2625 satb_mq_set.set_active_all_threads(
2626 false, /* new active value */
2627 satb_mq_set.is_active() /* expected_active */);
2628
2629 _g1h->trace_heap_after_concurrent_cycle();
2630 _g1h->register_concurrent_cycle_end();
2631 }
2632
2633 static void print_ms_time_info(const char* prefix, const char* name,
2634 NumberSeq& ns) {
2635 log_trace(gc, marking)("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).",
2636 prefix, ns.num(), name, ns.sum()/1000.0, ns.avg());
2637 if (ns.num() > 0) {
2638 log_trace(gc, marking)("%s [std. dev = %8.2f ms, max = %8.2f ms]",
2639 prefix, ns.sd(), ns.maximum());
2640 }
2641 }
2642
2643 void ConcurrentMark::print_summary_info() {
2644 LogHandle(gc, marking) log;
2645 if (!log.is_trace()) {
2646 return;
2647 }
2648
2649 log.trace(" Concurrent marking:");
|
419 CardTableModRefBS::card_shift,
420 false /* in_resource_area*/),
421
422 _prevMarkBitMap(&_markBitMap1),
423 _nextMarkBitMap(&_markBitMap2),
424
425 _markStack(this),
426 // _finger set in set_non_marking_state
427
428 _max_worker_id(ParallelGCThreads),
429 // _active_tasks set in set_non_marking_state
430 // _tasks set inside the constructor
431 _task_queues(new CMTaskQueueSet((int) _max_worker_id)),
432 _terminator(ParallelTaskTerminator((int) _max_worker_id, _task_queues)),
433
434 _has_overflown(false),
435 _concurrent(false),
436 _has_aborted(false),
437 _restart_for_overflow(false),
438 _concurrent_marking_in_progress(false),
439 _concurrent_phase_started(false),
440
441 // _verbose_level set below
442
443 _init_times(),
444 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(),
445 _cleanup_times(),
446 _total_counting_time(0.0),
447 _total_rs_scrub_time(0.0),
448
449 _parallel_workers(NULL),
450
451 _count_card_bitmaps(NULL),
452 _count_marked_bytes(NULL),
453 _completed_initialization(false) {
454
455 _markBitMap1.initialize(g1h->reserved_region(), prev_bitmap_storage);
456 _markBitMap2.initialize(g1h->reserved_region(), next_bitmap_storage);
457
458 // Create & start a ConcurrentMark thread.
459 _cmThread = new ConcurrentMarkThread(this);
987 // should not attempt to do any further work.
988 if (root_regions()->scan_in_progress()) {
989 GCTraceConcTime(Info, gc) tt("Concurrent Root Region Scan");
990
991 _parallel_marking_threads = calc_parallel_marking_threads();
992 assert(parallel_marking_threads() <= max_parallel_marking_threads(),
993 "Maximum number of marking threads exceeded");
994 uint active_workers = MAX2(1U, parallel_marking_threads());
995
996 CMRootRegionScanTask task(this);
997 _parallel_workers->set_active_workers(active_workers);
998 _parallel_workers->run_task(&task);
999
1000 // It's possible that has_aborted() is true here without actually
1001 // aborting the survivor scan earlier. This is OK as it's
1002 // mainly used for sanity checking.
1003 root_regions()->scan_finished();
1004 }
1005 }
1006
1007 void ConcurrentMark::register_concurrent_phase_start(const char* title) {
1008 assert(!_concurrent_phase_started, "Sanity");
1009 _concurrent_phase_started = true;
1010 _g1h->gc_timer_cm()->register_gc_concurrent_start(title);
1011 }
1012
1013 void ConcurrentMark::register_concurrent_phase_end() {
1014 if (_concurrent_phase_started) {
1015 _concurrent_phase_started = false;
1016 _g1h->gc_timer_cm()->register_gc_concurrent_end();
1017 }
1018 }
1019
1020 void ConcurrentMark::markFromRoots() {
1021 // we might be tempted to assert that:
1022 // assert(asynch == !SafepointSynchronize::is_at_safepoint(),
1023 // "inconsistent argument?");
1024 // However that wouldn't be right, because it's possible that
1025 // a safepoint is indeed in progress as a younger generation
1026 // stop-the-world GC happens even as we mark in this generation.
1027
1028 _restart_for_overflow = false;
1029
1030 // _g1h has _n_par_threads
1031 _parallel_marking_threads = calc_parallel_marking_threads();
1032 assert(parallel_marking_threads() <= max_parallel_marking_threads(),
1033 "Maximum number of marking threads exceeded");
1034
1035 uint active_workers = MAX2(1U, parallel_marking_threads());
1036 assert(active_workers > 0, "Should have been set");
1037
1038 // Parallel task terminator is set in "set_concurrency_and_phase()"
1039 set_concurrency_and_phase(active_workers, true /* concurrent */);
1040
1041 CMConcurrentMarkingTask markingTask(this, cmThread());
1042 _parallel_workers->set_active_workers(active_workers);
1043 _parallel_workers->run_task(&markingTask);
1044
1045 print_stats();
1046 }
1047
1048 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) {
1049 // world is stopped at this checkpoint
1050 assert(SafepointSynchronize::is_at_safepoint(),
1051 "world should be stopped");
1052
1053 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1054
1055 // If a full collection has happened, we shouldn't do this.
1056 if (has_aborted()) {
1057 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1058 return;
1059 }
1060
1061 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1062
1063 if (VerifyDuringGC) {
1064 HandleMark hm; // handle scope
2607 // Clear the liveness counting data
2608 clear_all_count_data();
2609 // Empty mark stack
2610 reset_marking_state();
2611 for (uint i = 0; i < _max_worker_id; ++i) {
2612 _tasks[i]->clear_region_fields();
2613 }
2614 _first_overflow_barrier_sync.abort();
2615 _second_overflow_barrier_sync.abort();
2616 _has_aborted = true;
2617
2618 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
2619 satb_mq_set.abandon_partial_marking();
2620 // This can be called either during or outside marking, we'll read
2621 // the expected_active value from the SATB queue set.
2622 satb_mq_set.set_active_all_threads(
2623 false, /* new active value */
2624 satb_mq_set.is_active() /* expected_active */);
2625
2626 _g1h->trace_heap_after_concurrent_cycle();
2627
2628 // Close any open concurrent phase timing
2629 register_concurrent_phase_end();
2630
2631 _g1h->register_concurrent_cycle_end();
2632 }
2633
2634 static void print_ms_time_info(const char* prefix, const char* name,
2635 NumberSeq& ns) {
2636 log_trace(gc, marking)("%s%5d %12s: total time = %8.2f s (avg = %8.2f ms).",
2637 prefix, ns.num(), name, ns.sum()/1000.0, ns.avg());
2638 if (ns.num() > 0) {
2639 log_trace(gc, marking)("%s [std. dev = %8.2f ms, max = %8.2f ms]",
2640 prefix, ns.sd(), ns.maximum());
2641 }
2642 }
2643
2644 void ConcurrentMark::print_summary_info() {
2645 LogHandle(gc, marking) log;
2646 if (!log.is_trace()) {
2647 return;
2648 }
2649
2650 log.trace(" Concurrent marking:");
|