--- old/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp 2011-08-19 09:33:34.858989400 +0200 +++ new/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp 2011-08-19 09:33:34.437788600 +0200 @@ -170,7 +170,6 @@ _cur_aux_times_ms(new double[_aux_num]), _cur_aux_times_set(new bool[_aux_num]), - _concurrent_mark_init_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), _concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), _concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), @@ -201,7 +200,6 @@ // - _in_young_gc_mode(false), _full_young_gcs(true), _full_young_pause_num(0), _partial_young_pause_num(0), @@ -400,7 +398,6 @@ _sigma = (double) G1ConfidencePercent / 100.0; // start conservatively (around 50ms is about right) - _concurrent_mark_init_times_ms->add(0.05); _concurrent_mark_remark_times_ms->add(0.05); _concurrent_mark_cleanup_times_ms->add(0.20); _tenuring_threshold = MaxTenuringThreshold; @@ -468,27 +465,20 @@ initialize_gc_policy_counters(); - if (G1Gen) { - _in_young_gc_mode = true; + G1YoungGenSizer sizer; + size_t initial_region_num = sizer.initial_young_region_num(); - G1YoungGenSizer sizer; - size_t initial_region_num = sizer.initial_young_region_num(); - - if (UseAdaptiveSizePolicy) { - set_adaptive_young_list_length(true); - _young_list_fixed_length = 0; - } else { - set_adaptive_young_list_length(false); - _young_list_fixed_length = initial_region_num; - } - _free_regions_at_end_of_collection = _g1->free_regions(); - calculate_young_list_min_length(); - guarantee( _young_list_min_length == 0, "invariant, not enough info" ); - calculate_young_list_target_length(); + if (UseAdaptiveSizePolicy) { + set_adaptive_young_list_length(true); + _young_list_fixed_length = 0; } else { - _young_list_fixed_length = 0; - _in_young_gc_mode = false; + set_adaptive_young_list_length(false); + _young_list_fixed_length = initial_region_num; } + _free_regions_at_end_of_collection = _g1->free_regions(); + calculate_young_list_min_length(); + guarantee( _young_list_min_length == 0, "invariant, not enough info" ); + calculate_young_list_target_length(); // We may immediately start allocating regions and placing them on the // collection set list. Initialize the per-collection set info @@ -498,7 +488,7 @@ // Create the jstat counters for the policy. void G1CollectorPolicy::initialize_gc_policy_counters() { - _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 2 + G1Gen); + _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3); } void G1CollectorPolicy::calculate_young_list_min_length() { @@ -868,8 +858,7 @@ if (PrintGCDetails) { gclog_or_tty->stamp(PrintGCTimeStamps); gclog_or_tty->print("[GC pause"); - if (in_young_gc_mode()) - gclog_or_tty->print(" (%s)", full_young_gcs() ? "young" : "partial"); + gclog_or_tty->print(" (%s)", full_young_gcs() ? "young" : "partial"); } assert(_g1->used() == _g1->recalculate_used(), @@ -921,8 +910,7 @@ _satb_drain_time_set = false; _last_satb_drain_processed_buffers = -1; - if (in_young_gc_mode()) - _last_young_gc_full = false; + _last_young_gc_full = false; // do that for any other surv rate groups _short_lived_surv_rate_group->stop_adding_regions(); @@ -935,12 +923,7 @@ _mark_closure_time_ms = mark_closure_time_ms; } -void G1CollectorPolicy::record_concurrent_mark_init_start() { - _mark_init_start_sec = os::elapsedTime(); - guarantee(!in_young_gc_mode(), "should not do be here in young GC mode"); -} - -void G1CollectorPolicy::record_concurrent_mark_init_end_pre(double +void G1CollectorPolicy::record_concurrent_mark_init_end(double mark_init_elapsed_time_ms) { _during_marking = true; assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now"); @@ -948,15 +931,6 @@ _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms; } -void G1CollectorPolicy::record_concurrent_mark_init_end() { - double end_time_sec = os::elapsedTime(); - double elapsed_time_ms = (end_time_sec - _mark_init_start_sec) * 1000.0; - _concurrent_mark_init_times_ms->add(elapsed_time_ms); - record_concurrent_mark_init_end_pre(elapsed_time_ms); - - _mmu_tracker->add_pause(_mark_init_start_sec, end_time_sec, true); -} - void G1CollectorPolicy::record_concurrent_mark_remark_start() { _mark_remark_start_sec = os::elapsedTime(); _during_marking = false; @@ -1019,13 +993,11 @@ void G1CollectorPolicy::record_concurrent_mark_cleanup_completed() { - if (in_young_gc_mode()) { - _should_revert_to_full_young_gcs = false; - _last_full_young_gc = true; - _in_marking_window = false; - if (adaptive_young_list_length()) - calculate_young_list_target_length(); - } + _should_revert_to_full_young_gcs = false; + _last_full_young_gc = true; + _in_marking_window = false; + if (adaptive_young_list_length()) + calculate_young_list_target_length(); } void G1CollectorPolicy::record_concurrent_pause() { @@ -1174,31 +1146,29 @@ } #endif // PRODUCT - if (in_young_gc_mode()) { - last_pause_included_initial_mark = during_initial_mark_pause(); - if (last_pause_included_initial_mark) - record_concurrent_mark_init_end_pre(0.0); - - size_t min_used_targ = - (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent; + last_pause_included_initial_mark = during_initial_mark_pause(); + if (last_pause_included_initial_mark) + record_concurrent_mark_init_end(0.0); + + size_t min_used_targ = + (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent; - if (!_g1->mark_in_progress() && !_last_full_young_gc) { - assert(!last_pause_included_initial_mark, "invariant"); - if (cur_used_bytes > min_used_targ && - cur_used_bytes > _prev_collection_pause_used_at_end_bytes) { + if (!_g1->mark_in_progress() && !_last_full_young_gc) { + assert(!last_pause_included_initial_mark, "invariant"); + if (cur_used_bytes > min_used_targ && + cur_used_bytes > _prev_collection_pause_used_at_end_bytes) { assert(!during_initial_mark_pause(), "we should not see this here"); // Note: this might have already been set, if during the last // pause we decided to start a cycle but at the beginning of // this pause we decided to postpone it. That's OK. set_initiate_conc_mark_if_possible(); - } } - - _prev_collection_pause_used_at_end_bytes = cur_used_bytes; } + _prev_collection_pause_used_at_end_bytes = cur_used_bytes; + _mmu_tracker->add_pause(end_time_sec - elapsed_ms/1000.0, end_time_sec, false); @@ -1468,24 +1438,23 @@ new_in_marking_window_im = true; } - if (in_young_gc_mode()) { - if (_last_full_young_gc) { - set_full_young_gcs(false); - _last_full_young_gc = false; - } + if (_last_full_young_gc) { + set_full_young_gcs(false); + _last_full_young_gc = false; + } - if ( !_last_young_gc_full ) { - if ( _should_revert_to_full_young_gcs || - _known_garbage_ratio < 0.05 || - (adaptive_young_list_length() && - (get_gc_eff_factor() * cur_efficiency < predict_young_gc_eff())) ) { + if ( !_last_young_gc_full ) { + if ( _should_revert_to_full_young_gcs || + _known_garbage_ratio < 0.05 || + (adaptive_young_list_length() && + (get_gc_eff_factor() * cur_efficiency < predict_young_gc_eff())) ) { set_full_young_gcs(true); - } } - _should_revert_to_full_young_gcs = false; + } + _should_revert_to_full_young_gcs = false; - if (_last_young_gc_full && !_during_marking) - _young_gc_eff_seq->add(cur_efficiency); + if (_last_young_gc_full && !_during_marking) { + _young_gc_eff_seq->add(cur_efficiency); } _short_lived_surv_rate_group->start_adding_regions(); @@ -1910,18 +1879,8 @@ // I don't think we need to do this when in young GC mode since // marking will be initiated next time we hit the soft limit anyway... if (predicted_time_ms > _expensive_region_limit_ms) { - if (!in_young_gc_mode()) { - set_full_young_gcs(true); - // We might want to do something different here. However, - // right now we don't support the non-generational G1 mode - // (and in fact we are planning to remove the associated code, - // see CR 6814390). So, let's leave it as is and this will be - // removed some time in the future - ShouldNotReachHere(); - set_during_initial_mark_pause(); - } else - // no point in doing another partial one - _should_revert_to_full_young_gcs = true; + // no point in doing another partial one + _should_revert_to_full_young_gcs = true; } } @@ -2617,9 +2576,7 @@ _inc_cset_size = 0; _inc_cset_bytes_used_before = 0; - if (in_young_gc_mode()) { - _inc_cset_young_index = 0; - } + _inc_cset_young_index = 0; _inc_cset_max_finger = 0; _inc_cset_recorded_young_bytes = 0; @@ -2848,86 +2805,77 @@ max_live_bytes = max_live_bytes + expansion_bytes; HeapRegion* hr; - if (in_young_gc_mode()) { - double young_start_time_sec = os::elapsedTime(); + double young_start_time_sec = os::elapsedTime(); - if (G1PolicyVerbose > 0) { - gclog_or_tty->print_cr("Adding %d young regions to the CSet", - _g1->young_list()->length()); - } + if (G1PolicyVerbose > 0) { + gclog_or_tty->print_cr("Adding %d young regions to the CSet", + _g1->young_list()->length()); + } - _young_cset_length = 0; - _last_young_gc_full = full_young_gcs() ? true : false; + _young_cset_length = 0; + _last_young_gc_full = full_young_gcs() ? true : false; - if (_last_young_gc_full) - ++_full_young_pause_num; - else - ++_partial_young_pause_num; + if (_last_young_gc_full) + ++_full_young_pause_num; + else + ++_partial_young_pause_num; + + // The young list is laid with the survivor regions from the previous + // pause are appended to the RHS of the young list, i.e. + // [Newly Young Regions ++ Survivors from last pause]. + + hr = _g1->young_list()->first_survivor_region(); + while (hr != NULL) { + assert(hr->is_survivor(), "badly formed young list"); + hr->set_young(); + hr = hr->get_next_young_region(); + } + + // Clear the fields that point to the survivor list - they are + // all young now. + _g1->young_list()->clear_survivors(); - // The young list is laid with the survivor regions from the previous - // pause are appended to the RHS of the young list, i.e. - // [Newly Young Regions ++ Survivors from last pause]. - - hr = _g1->young_list()->first_survivor_region(); - while (hr != NULL) { - assert(hr->is_survivor(), "badly formed young list"); - hr->set_young(); - hr = hr->get_next_young_region(); - } - - // Clear the fields that point to the survivor list - they are - // all young now. - _g1->young_list()->clear_survivors(); - - if (_g1->mark_in_progress()) - _g1->concurrent_mark()->register_collection_set_finger(_inc_cset_max_finger); - - _young_cset_length = _inc_cset_young_index; - _collection_set = _inc_cset_head; - _collection_set_size = _inc_cset_size; - _collection_set_bytes_used_before = _inc_cset_bytes_used_before; - - // For young regions in the collection set, we assume the worst - // case of complete survival - max_live_bytes -= _inc_cset_size * HeapRegion::GrainBytes; - - time_remaining_ms -= _inc_cset_predicted_elapsed_time_ms; - predicted_pause_time_ms += _inc_cset_predicted_elapsed_time_ms; - - // The number of recorded young regions is the incremental - // collection set's current size - set_recorded_young_regions(_inc_cset_size); - set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths); - set_recorded_young_bytes(_inc_cset_recorded_young_bytes); + if (_g1->mark_in_progress()) + _g1->concurrent_mark()->register_collection_set_finger(_inc_cset_max_finger); + + _young_cset_length = _inc_cset_young_index; + _collection_set = _inc_cset_head; + _collection_set_size = _inc_cset_size; + _collection_set_bytes_used_before = _inc_cset_bytes_used_before; + + // For young regions in the collection set, we assume the worst + // case of complete survival + max_live_bytes -= _inc_cset_size * HeapRegion::GrainBytes; + + time_remaining_ms -= _inc_cset_predicted_elapsed_time_ms; + predicted_pause_time_ms += _inc_cset_predicted_elapsed_time_ms; + + // The number of recorded young regions is the incremental + // collection set's current size + set_recorded_young_regions(_inc_cset_size); + set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths); + set_recorded_young_bytes(_inc_cset_recorded_young_bytes); #if PREDICTIONS_VERBOSE - set_predicted_bytes_to_copy(_inc_cset_predicted_bytes_to_copy); + set_predicted_bytes_to_copy(_inc_cset_predicted_bytes_to_copy); #endif // PREDICTIONS_VERBOSE - if (G1PolicyVerbose > 0) { - gclog_or_tty->print_cr(" Added " PTR_FORMAT " Young Regions to CS.", - _inc_cset_size); - gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)", - max_live_bytes/K); - } - - assert(_inc_cset_size == _g1->young_list()->length(), "Invariant"); + if (G1PolicyVerbose > 0) { + gclog_or_tty->print_cr(" Added " PTR_FORMAT " Young Regions to CS.", + _inc_cset_size); + gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)", + max_live_bytes/K); + } - double young_end_time_sec = os::elapsedTime(); - _recorded_young_cset_choice_time_ms = - (young_end_time_sec - young_start_time_sec) * 1000.0; + assert(_inc_cset_size == _g1->young_list()->length(), "Invariant"); - // We are doing young collections so reset this. - non_young_start_time_sec = young_end_time_sec; + double young_end_time_sec = os::elapsedTime(); + _recorded_young_cset_choice_time_ms = + (young_end_time_sec - young_start_time_sec) * 1000.0; - // Note we can use either _collection_set_size or - // _young_cset_length here - if (_collection_set_size > 0 && _last_young_gc_full) { - // don't bother adding more regions... - goto choose_collection_set_end; - } - } + // We are doing young collections so reset this. + non_young_start_time_sec = young_end_time_sec; - if (!in_young_gc_mode() || !full_young_gcs()) { + if (!full_young_gcs()) { bool should_continue = true; NumberSeq seq; double avg_prediction = 100000000000000000.0; // something very large @@ -2960,7 +2908,6 @@ _should_revert_to_full_young_gcs = true; } -choose_collection_set_end: stop_incremental_cset_building(); count_CS_bytes_used();