comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 6628:bb3f6194fedb

7178363: G1: Remove the serial code for PrintGCDetails and make it a special case of the parallel code Summary: Also reviewed by vitalyd@gmail.com. Introduced the WorkerDataArray class. Fixed some minor logging bugs. Reviewed-by: johnc, mgerdin
author brutisso
date Thu, 23 Aug 2012 10:21:12 +0200
parents 7383557659bd
children c9814fadeb38
comparison
equal deleted inserted replaced
6625:153776c4cb6f 6628:bb3f6194fedb
1244 void G1CollectedHeap::print_hrs_post_compaction() { 1244 void G1CollectedHeap::print_hrs_post_compaction() {
1245 PostCompactionPrinterClosure cl(hr_printer()); 1245 PostCompactionPrinterClosure cl(hr_printer());
1246 heap_region_iterate(&cl); 1246 heap_region_iterate(&cl);
1247 } 1247 }
1248 1248
1249 double G1CollectedHeap::verify(bool guard, const char* msg) {
1250 double verify_time_ms = 0.0;
1251
1252 if (guard && total_collections() >= VerifyGCStartAt) {
1253 double verify_start = os::elapsedTime();
1254 HandleMark hm; // Discard invalid handles created during verification
1255 gclog_or_tty->print(msg);
1256 prepare_for_verify();
1257 Universe::verify(false /* silent */, VerifyOption_G1UsePrevMarking);
1258 verify_time_ms = (os::elapsedTime() - verify_start) * 1000;
1259 }
1260
1261 return verify_time_ms;
1262 }
1263
1264 void G1CollectedHeap::verify_before_gc() {
1265 double verify_time_ms = verify(VerifyBeforeGC, " VerifyBeforeGC:");
1266 g1_policy()->phase_times()->record_verify_before_time_ms(verify_time_ms);
1267 }
1268
1269 void G1CollectedHeap::verify_after_gc() {
1270 double verify_time_ms = verify(VerifyAfterGC, " VerifyAfterGC:");
1271 g1_policy()->phase_times()->record_verify_after_time_ms(verify_time_ms);
1272 }
1273
1249 bool G1CollectedHeap::do_collection(bool explicit_gc, 1274 bool G1CollectedHeap::do_collection(bool explicit_gc,
1250 bool clear_all_soft_refs, 1275 bool clear_all_soft_refs,
1251 size_t word_size) { 1276 size_t word_size) {
1252 assert_at_safepoint(true /* should_be_vm_thread */); 1277 assert_at_safepoint(true /* should_be_vm_thread */);
1253 1278
1302 increment_old_marking_cycles_started(); 1327 increment_old_marking_cycles_started();
1303 1328
1304 size_t g1h_prev_used = used(); 1329 size_t g1h_prev_used = used();
1305 assert(used() == recalculate_used(), "Should be equal"); 1330 assert(used() == recalculate_used(), "Should be equal");
1306 1331
1307 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { 1332 verify_before_gc();
1308 HandleMark hm; // Discard invalid handles created during verification 1333
1309 gclog_or_tty->print(" VerifyBeforeGC:");
1310 prepare_for_verify();
1311 Universe::verify(/* silent */ false,
1312 /* option */ VerifyOption_G1UsePrevMarking);
1313
1314 }
1315 pre_full_gc_dump(); 1334 pre_full_gc_dump();
1316 1335
1317 COMPILER2_PRESENT(DerivedPointerTable::clear()); 1336 COMPILER2_PRESENT(DerivedPointerTable::clear());
1318 1337
1319 // Disable discovery and empty the discovered lists 1338 // Disable discovery and empty the discovered lists
1376 1395
1377 COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); 1396 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
1378 1397
1379 MemoryService::track_memory_usage(); 1398 MemoryService::track_memory_usage();
1380 1399
1381 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) { 1400 verify_after_gc();
1382 HandleMark hm; // Discard invalid handles created during verification
1383 gclog_or_tty->print(" VerifyAfterGC:");
1384 prepare_for_verify();
1385 Universe::verify(/* silent */ false,
1386 /* option */ VerifyOption_G1UsePrevMarking);
1387
1388 }
1389 1401
1390 assert(!ref_processor_stw()->discovery_enabled(), "Postcondition"); 1402 assert(!ref_processor_stw()->discovery_enabled(), "Postcondition");
1391 ref_processor_stw()->verify_no_references_recorded(); 1403 ref_processor_stw()->verify_no_references_recorded();
1392 1404
1393 // Note: since we've just done a full GC, concurrent 1405 // Note: since we've just done a full GC, concurrent
2325 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 2337 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
2326 int n_completed_buffers = 0; 2338 int n_completed_buffers = 0;
2327 while (dcqs.apply_closure_to_completed_buffer(cl, worker_i, 0, true)) { 2339 while (dcqs.apply_closure_to_completed_buffer(cl, worker_i, 0, true)) {
2328 n_completed_buffers++; 2340 n_completed_buffers++;
2329 } 2341 }
2330 g1_policy()->phase_times()->record_update_rs_processed_buffers(worker_i, 2342 g1_policy()->phase_times()->record_update_rs_processed_buffers(worker_i, n_completed_buffers);
2331 (double) n_completed_buffers);
2332 dcqs.clear_n_completed_buffers(); 2343 dcqs.clear_n_completed_buffers();
2333 assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!"); 2344 assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!");
2334 } 2345 }
2335 2346
2336 2347
3733 gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps); 3744 gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps);
3734 TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty); 3745 TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty);
3735 3746
3736 int active_workers = (G1CollectedHeap::use_parallel_gc_threads() ? 3747 int active_workers = (G1CollectedHeap::use_parallel_gc_threads() ?
3737 workers()->active_workers() : 1); 3748 workers()->active_workers() : 1);
3738 g1_policy()->phase_times()->note_gc_start(os::elapsedTime(), active_workers, 3749 double pause_start_sec = os::elapsedTime();
3739 g1_policy()->gcs_are_young(), g1_policy()->during_initial_mark_pause(), gc_cause()); 3750 g1_policy()->phase_times()->note_gc_start(active_workers);
3751 bool initial_mark_gc = g1_policy()->during_initial_mark_pause();
3740 3752
3741 TraceCollectorStats tcs(g1mm()->incremental_collection_counters()); 3753 TraceCollectorStats tcs(g1mm()->incremental_collection_counters());
3742 TraceMemoryManagerStats tms(false /* fullGC */, gc_cause()); 3754 TraceMemoryManagerStats tms(false /* fullGC */, gc_cause());
3743 3755
3744 // If the secondary_free_list is not empty, append it to the 3756 // If the secondary_free_list is not empty, append it to the
3763 3775
3764 gc_prologue(false); 3776 gc_prologue(false);
3765 increment_total_collections(false /* full gc */); 3777 increment_total_collections(false /* full gc */);
3766 increment_gc_time_stamp(); 3778 increment_gc_time_stamp();
3767 3779
3768 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { 3780 verify_before_gc();
3769 HandleMark hm; // Discard invalid handles created during verification
3770 gclog_or_tty->print(" VerifyBeforeGC:");
3771 prepare_for_verify();
3772 Universe::verify(/* silent */ false,
3773 /* option */ VerifyOption_G1UsePrevMarking);
3774 }
3775 3781
3776 COMPILER2_PRESENT(DerivedPointerTable::clear()); 3782 COMPILER2_PRESENT(DerivedPointerTable::clear());
3777 3783
3778 // Please see comment in g1CollectedHeap.hpp and 3784 // Please see comment in g1CollectedHeap.hpp and
3779 // G1CollectedHeap::ref_processing_init() to see how 3785 // G1CollectedHeap::ref_processing_init() to see how
3981 _cm->verify_no_cset_oops(true /* verify_stacks */, 3987 _cm->verify_no_cset_oops(true /* verify_stacks */,
3982 true /* verify_enqueued_buffers */, 3988 true /* verify_enqueued_buffers */,
3983 true /* verify_thread_buffers */, 3989 true /* verify_thread_buffers */,
3984 true /* verify_fingers */); 3990 true /* verify_fingers */);
3985 _cm->note_end_of_gc(); 3991 _cm->note_end_of_gc();
3986
3987 // Collect thread local data to allow the ergonomics to use
3988 // the collected information
3989 g1_policy()->phase_times()->collapse_par_times();
3990 3992
3991 // This timing is only used by the ergonomics to handle our pause target. 3993 // This timing is only used by the ergonomics to handle our pause target.
3992 // It is unclear why this should not include the full pause. We will 3994 // It is unclear why this should not include the full pause. We will
3993 // investigate this in CR 7178365. 3995 // investigate this in CR 7178365.
3994 double sample_end_time_sec = os::elapsedTime(); 3996 double sample_end_time_sec = os::elapsedTime();
4018 // during concurrent refinement. So we don't need the 4020 // during concurrent refinement. So we don't need the
4019 // is_gc_active() check to decided which top to use when 4021 // is_gc_active() check to decided which top to use when
4020 // scanning cards (see CR 7039627). 4022 // scanning cards (see CR 7039627).
4021 increment_gc_time_stamp(); 4023 increment_gc_time_stamp();
4022 4024
4023 if (VerifyAfterGC && total_collections() >= VerifyGCStartAt) { 4025 verify_after_gc();
4024 HandleMark hm; // Discard invalid handles created during verification
4025 gclog_or_tty->print(" VerifyAfterGC:");
4026 prepare_for_verify();
4027 Universe::verify(/* silent */ false,
4028 /* option */ VerifyOption_G1UsePrevMarking);
4029 }
4030 4026
4031 assert(!ref_processor_stw()->discovery_enabled(), "Postcondition"); 4027 assert(!ref_processor_stw()->discovery_enabled(), "Postcondition");
4032 ref_processor_stw()->verify_no_references_recorded(); 4028 ref_processor_stw()->verify_no_references_recorded();
4033 4029
4034 // CM reference discovery will be re-enabled if necessary. 4030 // CM reference discovery will be re-enabled if necessary.
4048 ParallelTaskTerminator::print_termination_counts(); 4044 ParallelTaskTerminator::print_termination_counts();
4049 #endif 4045 #endif
4050 4046
4051 gc_epilogue(false); 4047 gc_epilogue(false);
4052 4048
4053 g1_policy()->phase_times()->note_gc_end(os::elapsedTime()); 4049 if (G1Log::fine()) {
4054 4050 if (PrintGCTimeStamps) {
4055 // We have to do this after we decide whether to expand the heap or not. 4051 gclog_or_tty->stamp();
4052 gclog_or_tty->print(": ");
4053 }
4054
4055 GCCauseString gc_cause_str = GCCauseString("GC pause", gc_cause())
4056 .append(g1_policy()->gcs_are_young() ? " (young)" : " (mixed)")
4057 .append(initial_mark_gc ? " (initial-mark)" : "");
4058
4059 double pause_time_sec = os::elapsedTime() - pause_start_sec;
4060
4061 if (G1Log::finer()) {
4062 if (evacuation_failed()) {
4063 gc_cause_str.append(" (to-space exhausted)");
4064 }
4065 gclog_or_tty->print_cr("[%s, %3.7f secs]", (const char*)gc_cause_str, pause_time_sec);
4066 g1_policy()->phase_times()->note_gc_end();
4067 g1_policy()->phase_times()->print(pause_time_sec);
4068 g1_policy()->print_detailed_heap_transition();
4069 } else {
4070 if (evacuation_failed()) {
4071 gc_cause_str.append("--");
4072 }
4073 gclog_or_tty->print("[%s", (const char*)gc_cause_str);
4056 g1_policy()->print_heap_transition(); 4074 g1_policy()->print_heap_transition();
4075 gclog_or_tty->print_cr(", %3.7f secs]", pause_time_sec);
4076 }
4077 }
4057 } 4078 }
4058 4079
4059 // It is not yet to safe to tell the concurrent mark to 4080 // It is not yet to safe to tell the concurrent mark to
4060 // start as we have some optional output below. We don't want the 4081 // start as we have some optional output below. We don't want the
4061 // output from the concurrent mark thread interfering with this 4082 // output from the concurrent mark thread interfering with this
4861 double start = os::elapsedTime(); 4882 double start = os::elapsedTime();
4862 G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator); 4883 G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator);
4863 evac.do_void(); 4884 evac.do_void();
4864 double elapsed_ms = (os::elapsedTime()-start)*1000.0; 4885 double elapsed_ms = (os::elapsedTime()-start)*1000.0;
4865 double term_ms = pss.term_time()*1000.0; 4886 double term_ms = pss.term_time()*1000.0;
4866 _g1h->g1_policy()->phase_times()->record_obj_copy_time(worker_id, elapsed_ms-term_ms); 4887 _g1h->g1_policy()->phase_times()->add_obj_copy_time(worker_id, elapsed_ms-term_ms);
4867 _g1h->g1_policy()->phase_times()->record_termination(worker_id, term_ms, pss.term_attempts()); 4888 _g1h->g1_policy()->phase_times()->record_termination(worker_id, term_ms, pss.term_attempts());
4868 } 4889 }
4869 _g1h->g1_policy()->record_thread_age_table(pss.age_table()); 4890 _g1h->g1_policy()->record_thread_age_table(pss.age_table());
4870 _g1h->update_surviving_young_words(pss.surviving_young_words()+1); 4891 _g1h->update_surviving_young_words(pss.surviving_young_words()+1);
4871 4892
4989 5010
4990 // Finish up any enqueued closure apps (attributed as object copy time). 5011 // Finish up any enqueued closure apps (attributed as object copy time).
4991 buf_scan_non_heap_roots.done(); 5012 buf_scan_non_heap_roots.done();
4992 buf_scan_perm.done(); 5013 buf_scan_perm.done();
4993 5014
4994 double ext_roots_end = os::elapsedTime();
4995
4996 g1_policy()->phase_times()->reset_obj_copy_time(worker_i);
4997 double obj_copy_time_sec = buf_scan_perm.closure_app_seconds() + 5015 double obj_copy_time_sec = buf_scan_perm.closure_app_seconds() +
4998 buf_scan_non_heap_roots.closure_app_seconds(); 5016 buf_scan_non_heap_roots.closure_app_seconds();
4999 g1_policy()->phase_times()->record_obj_copy_time(worker_i, obj_copy_time_sec * 1000.0); 5017 g1_policy()->phase_times()->record_obj_copy_time(worker_i, obj_copy_time_sec * 1000.0);
5000 5018
5001 double ext_root_time_ms = 5019 double ext_root_time_ms =
5002 ((ext_roots_end - ext_roots_start) - obj_copy_time_sec) * 1000.0; 5020 ((os::elapsedTime() - ext_roots_start) - obj_copy_time_sec) * 1000.0;
5003 5021
5004 g1_policy()->phase_times()->record_ext_root_scan_time(worker_i, ext_root_time_ms); 5022 g1_policy()->phase_times()->record_ext_root_scan_time(worker_i, ext_root_time_ms);
5005 5023
5006 // During conc marking we have to filter the per-thread SATB buffers 5024 // During conc marking we have to filter the per-thread SATB buffers
5007 // to make sure we remove any oops into the CSet (which will show up 5025 // to make sure we remove any oops into the CSet (which will show up
5008 // as implicitly live). 5026 // as implicitly live).
5027 double satb_filtering_ms = 0.0;
5009 if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers)) { 5028 if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers)) {
5010 if (mark_in_progress()) { 5029 if (mark_in_progress()) {
5030 double satb_filter_start = os::elapsedTime();
5031
5011 JavaThread::satb_mark_queue_set().filter_thread_buffers(); 5032 JavaThread::satb_mark_queue_set().filter_thread_buffers();
5012 } 5033
5013 } 5034 satb_filtering_ms = (os::elapsedTime() - satb_filter_start) * 1000.0;
5014 double satb_filtering_ms = (os::elapsedTime() - ext_roots_end) * 1000.0; 5035 }
5036 }
5015 g1_policy()->phase_times()->record_satb_filtering_time(worker_i, satb_filtering_ms); 5037 g1_policy()->phase_times()->record_satb_filtering_time(worker_i, satb_filtering_ms);
5016 5038
5017 // Now scan the complement of the collection set. 5039 // Now scan the complement of the collection set.
5018 if (scan_rs != NULL) { 5040 if (scan_rs != NULL) {
5019 g1_rem_set()->oops_into_collection_set_do(scan_rs, worker_i); 5041 g1_rem_set()->oops_into_collection_set_do(scan_rs, worker_i);
5645 5667
5646 finalize_for_evac_failure(); 5668 finalize_for_evac_failure();
5647 5669
5648 if (evacuation_failed()) { 5670 if (evacuation_failed()) {
5649 remove_self_forwarding_pointers(); 5671 remove_self_forwarding_pointers();
5650 if (G1Log::finer()) {
5651 gclog_or_tty->print(" (to-space exhausted)");
5652 } else if (G1Log::fine()) {
5653 gclog_or_tty->print("--");
5654 }
5655 } 5672 }
5656 5673
5657 // Enqueue any remaining references remaining on the STW 5674 // Enqueue any remaining references remaining on the STW
5658 // reference processor's discovered lists. We need to do 5675 // reference processor's discovered lists. We need to do
5659 // this after the card table is cleaned (and verified) as 5676 // this after the card table is cleaned (and verified) as