comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 940:8624da129f0b

6841313: G1: dirty cards of survivor regions in parallel Reviewed-by: tonyp, iveresov
author apetrusenko
date Mon, 31 Aug 2009 05:27:29 -0700
parents e1fdf4fd34dc
children 8b46c4d82093
comparison
equal deleted inserted replaced
939:9eebd3ac74cf 940:8624da129f0b
2736 FREE_C_HEAP_ARRAY(bool, _in_cset_fast_test_base); 2736 FREE_C_HEAP_ARRAY(bool, _in_cset_fast_test_base);
2737 // this is more for peace of mind; we're nulling them here and 2737 // this is more for peace of mind; we're nulling them here and
2738 // we're expecting them to be null at the beginning of the next GC 2738 // we're expecting them to be null at the beginning of the next GC
2739 _in_cset_fast_test = NULL; 2739 _in_cset_fast_test = NULL;
2740 _in_cset_fast_test_base = NULL; 2740 _in_cset_fast_test_base = NULL;
2741
2742 release_gc_alloc_regions(false /* totally */);
2743 2741
2744 cleanup_surviving_young_words(); 2742 cleanup_surviving_young_words();
2745 2743
2746 if (g1_policy()->in_young_gc_mode()) { 2744 if (g1_policy()->in_young_gc_mode()) {
2747 _young_list->reset_sampled_info(); 2745 _young_list->reset_sampled_info();
4130 { 4128 {
4131 G1IsAliveClosure is_alive(this); 4129 G1IsAliveClosure is_alive(this);
4132 G1KeepAliveClosure keep_alive(this); 4130 G1KeepAliveClosure keep_alive(this);
4133 JNIHandles::weak_oops_do(&is_alive, &keep_alive); 4131 JNIHandles::weak_oops_do(&is_alive, &keep_alive);
4134 } 4132 }
4133 release_gc_alloc_regions(false /* totally */);
4135 g1_rem_set()->cleanup_after_oops_into_collection_set_do(); 4134 g1_rem_set()->cleanup_after_oops_into_collection_set_do();
4136 4135
4137 concurrent_g1_refine()->clear_hot_cache(); 4136 concurrent_g1_refine()->clear_hot_cache();
4138 concurrent_g1_refine()->set_use_cache(true); 4137 concurrent_g1_refine()->set_use_cache(true);
4139 4138
4263 4262
4264 4263
4265 class G1ParCleanupCTTask : public AbstractGangTask { 4264 class G1ParCleanupCTTask : public AbstractGangTask {
4266 CardTableModRefBS* _ct_bs; 4265 CardTableModRefBS* _ct_bs;
4267 G1CollectedHeap* _g1h; 4266 G1CollectedHeap* _g1h;
4267 HeapRegion* volatile _so_head;
4268 HeapRegion* volatile _su_head;
4268 public: 4269 public:
4269 G1ParCleanupCTTask(CardTableModRefBS* ct_bs, 4270 G1ParCleanupCTTask(CardTableModRefBS* ct_bs,
4270 G1CollectedHeap* g1h) : 4271 G1CollectedHeap* g1h,
4272 HeapRegion* scan_only_list,
4273 HeapRegion* survivor_list) :
4271 AbstractGangTask("G1 Par Cleanup CT Task"), 4274 AbstractGangTask("G1 Par Cleanup CT Task"),
4272 _ct_bs(ct_bs), 4275 _ct_bs(ct_bs),
4273 _g1h(g1h) 4276 _g1h(g1h),
4277 _so_head(scan_only_list),
4278 _su_head(survivor_list)
4274 { } 4279 { }
4275 4280
4276 void work(int i) { 4281 void work(int i) {
4277 HeapRegion* r; 4282 HeapRegion* r;
4278 while (r = _g1h->pop_dirty_cards_region()) { 4283 while (r = _g1h->pop_dirty_cards_region()) {
4279 clear_cards(r); 4284 clear_cards(r);
4280 } 4285 }
4281 } 4286 // Redirty the cards of the scan-only and survivor regions.
4287 dirty_list(&this->_so_head);
4288 dirty_list(&this->_su_head);
4289 }
4290
4282 void clear_cards(HeapRegion* r) { 4291 void clear_cards(HeapRegion* r) {
4283 // Cards for Survivor and Scan-Only regions will be dirtied later. 4292 // Cards for Survivor and Scan-Only regions will be dirtied later.
4284 if (!r->is_scan_only() && !r->is_survivor()) { 4293 if (!r->is_scan_only() && !r->is_survivor()) {
4285 _ct_bs->clear(MemRegion(r->bottom(), r->end())); 4294 _ct_bs->clear(MemRegion(r->bottom(), r->end()));
4286 } 4295 }
4287 } 4296 }
4297
4298 void dirty_list(HeapRegion* volatile * head_ptr) {
4299 HeapRegion* head;
4300 do {
4301 // Pop region off the list.
4302 head = *head_ptr;
4303 if (head != NULL) {
4304 HeapRegion* r = (HeapRegion*)
4305 Atomic::cmpxchg_ptr(head->get_next_young_region(), head_ptr, head);
4306 if (r == head) {
4307 assert(!r->isHumongous(), "Humongous regions shouldn't be on survivor list");
4308 _ct_bs->dirty(MemRegion(r->bottom(), r->end()));
4309 }
4310 }
4311 } while (*head_ptr != NULL);
4312 }
4288 }; 4313 };
4289 4314
4315
4316 #ifndef PRODUCT
4317 class G1VerifyCardTableCleanup: public HeapRegionClosure {
4318 CardTableModRefBS* _ct_bs;
4319 public:
4320 G1VerifyCardTableCleanup(CardTableModRefBS* ct_bs)
4321 : _ct_bs(ct_bs)
4322 { }
4323 virtual bool doHeapRegion(HeapRegion* r)
4324 {
4325 MemRegion mr(r->bottom(), r->end());
4326 if (r->is_scan_only() || r->is_survivor()) {
4327 _ct_bs->verify_dirty_region(mr);
4328 } else {
4329 _ct_bs->verify_clean_region(mr);
4330 }
4331 return false;
4332 }
4333 };
4334 #endif
4290 4335
4291 void G1CollectedHeap::cleanUpCardTable() { 4336 void G1CollectedHeap::cleanUpCardTable() {
4292 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set()); 4337 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (barrier_set());
4293 double start = os::elapsedTime(); 4338 double start = os::elapsedTime();
4294 4339
4295 // Iterate over the dirty cards region list. 4340 // Iterate over the dirty cards region list.
4296 G1ParCleanupCTTask cleanup_task(ct_bs, this); 4341 G1ParCleanupCTTask cleanup_task(ct_bs, this,
4342 _young_list->first_scan_only_region(),
4343 _young_list->first_survivor_region());
4297 if (ParallelGCThreads > 0) { 4344 if (ParallelGCThreads > 0) {
4298 set_par_threads(workers()->total_workers()); 4345 set_par_threads(workers()->total_workers());
4299 workers()->run_task(&cleanup_task); 4346 workers()->run_task(&cleanup_task);
4300 set_par_threads(0); 4347 set_par_threads(0);
4301 } else { 4348 } else {
4307 // The last region. 4354 // The last region.
4308 _dirty_cards_region_list = NULL; 4355 _dirty_cards_region_list = NULL;
4309 } 4356 }
4310 r->set_next_dirty_cards_region(NULL); 4357 r->set_next_dirty_cards_region(NULL);
4311 } 4358 }
4312 } 4359 // now, redirty the cards of the scan-only and survivor regions
4313 // now, redirty the cards of the scan-only and survivor regions 4360 // (it seemed faster to do it this way, instead of iterating over
4314 // (it seemed faster to do it this way, instead of iterating over 4361 // all regions and then clearing / dirtying as appropriate)
4315 // all regions and then clearing / dirtying as appropriate) 4362 dirtyCardsForYoungRegions(ct_bs, _young_list->first_scan_only_region());
4316 dirtyCardsForYoungRegions(ct_bs, _young_list->first_scan_only_region()); 4363 dirtyCardsForYoungRegions(ct_bs, _young_list->first_survivor_region());
4317 dirtyCardsForYoungRegions(ct_bs, _young_list->first_survivor_region()); 4364 }
4318
4319 double elapsed = os::elapsedTime() - start; 4365 double elapsed = os::elapsedTime() - start;
4320 g1_policy()->record_clear_ct_time( elapsed * 1000.0); 4366 g1_policy()->record_clear_ct_time( elapsed * 1000.0);
4321 } 4367 #ifndef PRODUCT
4322 4368 if (G1VerifyCTCleanup || VerifyAfterGC) {
4369 G1VerifyCardTableCleanup cleanup_verifier(ct_bs);
4370 heap_region_iterate(&cleanup_verifier);
4371 }
4372 #endif
4373 }
4323 4374
4324 void G1CollectedHeap::do_collection_pause_if_appropriate(size_t word_size) { 4375 void G1CollectedHeap::do_collection_pause_if_appropriate(size_t word_size) {
4325 if (g1_policy()->should_do_collection_pause(word_size)) { 4376 if (g1_policy()->should_do_collection_pause(word_size)) {
4326 do_collection_pause(); 4377 do_collection_pause();
4327 } 4378 }