comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 4090:a88de71c4e3a

7097002: G1: remove a lot of unused / redundant code from the G1CollectorPolicy class Summary: Major cleanup of the G1CollectorPolicy class. It removes a lot of unused fields and methods and also consolidates replicated information (mainly various ways of counting the number of CSet regions) into one copy. Reviewed-by: johnc, brutisso
author tonyp
date Fri, 18 Nov 2011 12:52:27 -0500
parents 53074c2c4600
children bca17e38de00
comparison
equal deleted inserted replaced
4077:b1754f3fbbd8 4090:a88de71c4e3a
174 assert(hr->get_next_young_region() == NULL, "cause it should!"); 174 assert(hr->get_next_young_region() == NULL, "cause it should!");
175 175
176 hr->set_next_young_region(_head); 176 hr->set_next_young_region(_head);
177 _head = hr; 177 _head = hr;
178 178
179 hr->set_young(); 179 _g1h->g1_policy()->set_region_eden(hr, (int) _length);
180 double yg_surv_rate = _g1h->g1_policy()->predict_yg_surv_rate((int)_length);
181 ++_length; 180 ++_length;
182 } 181 }
183 182
184 void YoungList::add_survivor_region(HeapRegion* hr) { 183 void YoungList::add_survivor_region(HeapRegion* hr) {
185 assert(hr->is_survivor(), "should be flagged as survivor region"); 184 assert(hr->is_survivor(), "should be flagged as survivor region");
188 hr->set_next_young_region(_survivor_head); 187 hr->set_next_young_region(_survivor_head);
189 if (_survivor_head == NULL) { 188 if (_survivor_head == NULL) {
190 _survivor_tail = hr; 189 _survivor_tail = hr;
191 } 190 }
192 _survivor_head = hr; 191 _survivor_head = hr;
193
194 ++_survivor_length; 192 ++_survivor_length;
195 } 193 }
196 194
197 void YoungList::empty_list(HeapRegion* list) { 195 void YoungList::empty_list(HeapRegion* list) {
198 while (list != NULL) { 196 while (list != NULL) {
313 311
314 // Add survivor regions to SurvRateGroup. 312 // Add survivor regions to SurvRateGroup.
315 _g1h->g1_policy()->note_start_adding_survivor_regions(); 313 _g1h->g1_policy()->note_start_adding_survivor_regions();
316 _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */); 314 _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
317 315
316 int young_index_in_cset = 0;
318 for (HeapRegion* curr = _survivor_head; 317 for (HeapRegion* curr = _survivor_head;
319 curr != NULL; 318 curr != NULL;
320 curr = curr->get_next_young_region()) { 319 curr = curr->get_next_young_region()) {
321 _g1h->g1_policy()->set_region_survivors(curr); 320 _g1h->g1_policy()->set_region_survivor(curr, young_index_in_cset);
322 321
323 // The region is a non-empty survivor so let's add it to 322 // The region is a non-empty survivor so let's add it to
324 // the incremental collection set for the next evacuation 323 // the incremental collection set for the next evacuation
325 // pause. 324 // pause.
326 _g1h->g1_policy()->add_region_to_incremental_cset_rhs(curr); 325 _g1h->g1_policy()->add_region_to_incremental_cset_rhs(curr);
327 } 326 young_index_in_cset += 1;
327 }
328 assert((size_t) young_index_in_cset == _survivor_length,
329 "post-condition");
328 _g1h->g1_policy()->note_stop_adding_survivor_regions(); 330 _g1h->g1_policy()->note_stop_adding_survivor_regions();
329 331
330 _head = _survivor_head; 332 _head = _survivor_head;
331 _length = _survivor_length; 333 _length = _survivor_length;
332 if (_survivor_head != NULL) { 334 if (_survivor_head != NULL) {
3208 _cmThread->set_started(); 3210 _cmThread->set_started();
3209 CGC_lock->notify(); 3211 CGC_lock->notify();
3210 } 3212 }
3211 } 3213 }
3212 3214
3213 // <NEW PREDICTION>
3214
3215 double G1CollectedHeap::predict_region_elapsed_time_ms(HeapRegion *hr, 3215 double G1CollectedHeap::predict_region_elapsed_time_ms(HeapRegion *hr,
3216 bool young) { 3216 bool young) {
3217 return _g1_policy->predict_region_elapsed_time_ms(hr, young); 3217 return _g1_policy->predict_region_elapsed_time_ms(hr, young);
3218 } 3218 }
3219 3219
3249 } 3249 }
3250 3250
3251 void 3251 void
3252 G1CollectedHeap::setup_surviving_young_words() { 3252 G1CollectedHeap::setup_surviving_young_words() {
3253 guarantee( _surviving_young_words == NULL, "pre-condition" ); 3253 guarantee( _surviving_young_words == NULL, "pre-condition" );
3254 size_t array_length = g1_policy()->young_cset_length(); 3254 size_t array_length = g1_policy()->young_cset_region_length();
3255 _surviving_young_words = NEW_C_HEAP_ARRAY(size_t, array_length); 3255 _surviving_young_words = NEW_C_HEAP_ARRAY(size_t, array_length);
3256 if (_surviving_young_words == NULL) { 3256 if (_surviving_young_words == NULL) {
3257 vm_exit_out_of_memory(sizeof(size_t) * array_length, 3257 vm_exit_out_of_memory(sizeof(size_t) * array_length,
3258 "Not enough space for young surv words summary."); 3258 "Not enough space for young surv words summary.");
3259 } 3259 }
3266 } 3266 }
3267 3267
3268 void 3268 void
3269 G1CollectedHeap::update_surviving_young_words(size_t* surv_young_words) { 3269 G1CollectedHeap::update_surviving_young_words(size_t* surv_young_words) {
3270 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag); 3270 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
3271 size_t array_length = g1_policy()->young_cset_length(); 3271 size_t array_length = g1_policy()->young_cset_region_length();
3272 for (size_t i = 0; i < array_length; ++i) 3272 for (size_t i = 0; i < array_length; ++i)
3273 _surviving_young_words[i] += surv_young_words[i]; 3273 _surviving_young_words[i] += surv_young_words[i];
3274 } 3274 }
3275 3275
3276 void 3276 void
3277 G1CollectedHeap::cleanup_surviving_young_words() { 3277 G1CollectedHeap::cleanup_surviving_young_words() {
3278 guarantee( _surviving_young_words != NULL, "pre-condition" ); 3278 guarantee( _surviving_young_words != NULL, "pre-condition" );
3279 FREE_C_HEAP_ARRAY(size_t, _surviving_young_words); 3279 FREE_C_HEAP_ARRAY(size_t, _surviving_young_words);
3280 _surviving_young_words = NULL; 3280 _surviving_young_words = NULL;
3281 } 3281 }
3282
3283 // </NEW PREDICTION>
3284 3282
3285 #ifdef ASSERT 3283 #ifdef ASSERT
3286 class VerifyCSetClosure: public HeapRegionClosure { 3284 class VerifyCSetClosure: public HeapRegionClosure {
3287 public: 3285 public:
3288 bool doHeapRegion(HeapRegion* hr) { 3286 bool doHeapRegion(HeapRegion* hr) {
4156 // we allocate G1YoungSurvRateNumRegions plus one entries, since 4154 // we allocate G1YoungSurvRateNumRegions plus one entries, since
4157 // we "sacrifice" entry 0 to keep track of surviving bytes for 4155 // we "sacrifice" entry 0 to keep track of surviving bytes for
4158 // non-young regions (where the age is -1) 4156 // non-young regions (where the age is -1)
4159 // We also add a few elements at the beginning and at the end in 4157 // We also add a few elements at the beginning and at the end in
4160 // an attempt to eliminate cache contention 4158 // an attempt to eliminate cache contention
4161 size_t real_length = 1 + _g1h->g1_policy()->young_cset_length(); 4159 size_t real_length = 1 + _g1h->g1_policy()->young_cset_region_length();
4162 size_t array_length = PADDING_ELEM_NUM + 4160 size_t array_length = PADDING_ELEM_NUM +
4163 real_length + 4161 real_length +
4164 PADDING_ELEM_NUM; 4162 PADDING_ELEM_NUM;
4165 _surviving_young_words_base = NEW_C_HEAP_ARRAY(size_t, array_length); 4163 _surviving_young_words_base = NEW_C_HEAP_ARRAY(size_t, array_length);
4166 if (_surviving_young_words_base == NULL) 4164 if (_surviving_young_words_base == NULL)
5593 cur->set_next_in_collection_set(NULL); 5591 cur->set_next_in_collection_set(NULL);
5594 cur->set_in_collection_set(false); 5592 cur->set_in_collection_set(false);
5595 5593
5596 if (cur->is_young()) { 5594 if (cur->is_young()) {
5597 int index = cur->young_index_in_cset(); 5595 int index = cur->young_index_in_cset();
5598 guarantee( index != -1, "invariant" ); 5596 assert(index != -1, "invariant");
5599 guarantee( (size_t)index < policy->young_cset_length(), "invariant" ); 5597 assert((size_t) index < policy->young_cset_region_length(), "invariant");
5600 size_t words_survived = _surviving_young_words[index]; 5598 size_t words_survived = _surviving_young_words[index];
5601 cur->record_surv_words_in_group(words_survived); 5599 cur->record_surv_words_in_group(words_survived);
5602 5600
5603 // At this point the we have 'popped' cur from the collection set 5601 // At this point the we have 'popped' cur from the collection set
5604 // (linked via next_in_collection_set()) but it is still in the 5602 // (linked via next_in_collection_set()) but it is still in the
5605 // young list (linked via next_young_region()). Clear the 5603 // young list (linked via next_young_region()). Clear the
5606 // _next_young_region field. 5604 // _next_young_region field.
5607 cur->set_next_young_region(NULL); 5605 cur->set_next_young_region(NULL);
5608 } else { 5606 } else {
5609 int index = cur->young_index_in_cset(); 5607 int index = cur->young_index_in_cset();
5610 guarantee( index == -1, "invariant" ); 5608 assert(index == -1, "invariant");
5611 } 5609 }
5612 5610
5613 assert( (cur->is_young() && cur->young_index_in_cset() > -1) || 5611 assert( (cur->is_young() && cur->young_index_in_cset() > -1) ||
5614 (!cur->is_young() && cur->young_index_in_cset() == -1), 5612 (!cur->is_young() && cur->young_index_in_cset() == -1),
5615 "invariant" ); 5613 "invariant" );
5618 // And the region is empty. 5616 // And the region is empty.
5619 assert(!cur->is_empty(), "Should not have empty regions in a CS."); 5617 assert(!cur->is_empty(), "Should not have empty regions in a CS.");
5620 free_region(cur, &pre_used, &local_free_list, false /* par */); 5618 free_region(cur, &pre_used, &local_free_list, false /* par */);
5621 } else { 5619 } else {
5622 cur->uninstall_surv_rate_group(); 5620 cur->uninstall_surv_rate_group();
5623 if (cur->is_young()) 5621 if (cur->is_young()) {
5624 cur->set_young_index_in_cset(-1); 5622 cur->set_young_index_in_cset(-1);
5623 }
5625 cur->set_not_young(); 5624 cur->set_not_young();
5626 cur->set_evacuation_failed(false); 5625 cur->set_evacuation_failed(false);
5627 // The region is now considered to be old. 5626 // The region is now considered to be old.
5628 _old_set.add(cur); 5627 _old_set.add(cur);
5629 } 5628 }
5720 5719
5721 void G1CollectedHeap::set_region_short_lived_locked(HeapRegion* hr) { 5720 void G1CollectedHeap::set_region_short_lived_locked(HeapRegion* hr) {
5722 assert(heap_lock_held_for_gc(), 5721 assert(heap_lock_held_for_gc(),
5723 "the heap lock should already be held by or for this thread"); 5722 "the heap lock should already be held by or for this thread");
5724 _young_list->push_region(hr); 5723 _young_list->push_region(hr);
5725 g1_policy()->set_region_short_lived(hr);
5726 } 5724 }
5727 5725
5728 class NoYoungRegionsClosure: public HeapRegionClosure { 5726 class NoYoungRegionsClosure: public HeapRegionClosure {
5729 private: 5727 private:
5730 bool _success; 5728 bool _success;
5878 bool young_list_full = g1_policy()->is_young_list_full(); 5876 bool young_list_full = g1_policy()->is_young_list_full();
5879 if (force || !young_list_full) { 5877 if (force || !young_list_full) {
5880 HeapRegion* new_alloc_region = new_region(word_size, 5878 HeapRegion* new_alloc_region = new_region(word_size,
5881 false /* do_expand */); 5879 false /* do_expand */);
5882 if (new_alloc_region != NULL) { 5880 if (new_alloc_region != NULL) {
5883 g1_policy()->update_region_num(true /* next_is_young */);
5884 set_region_short_lived_locked(new_alloc_region); 5881 set_region_short_lived_locked(new_alloc_region);
5885 _hr_printer.alloc(new_alloc_region, G1HRPrinter::Eden, young_list_full); 5882 _hr_printer.alloc(new_alloc_region, G1HRPrinter::Eden, young_list_full);
5886 return new_alloc_region; 5883 return new_alloc_region;
5887 } 5884 }
5888 } 5885 }