comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 3777:e8b0b0392037

7046182: G1: remove unnecessary iterations over the collection set Summary: Remove two unnecessary iterations over the collection set which are supposed to prepare the RSet's of the CSet regions for parallel iterations (we'll make sure this is done incrementally). I'll piggyback on this CR the removal of the G1_REM_SET_LOGGING code. Reviewed-by: brutisso, johnc
author tonyp
date Tue, 21 Jun 2011 15:23:07 -0400
parents c9ca3f51cf41
children 5f6f2615433a
comparison
equal deleted inserted replaced
3776:23d434c6290d 3777:e8b0b0392037
3013 } 3013 }
3014 g1_policy()->print_yg_surv_rate_info(); 3014 g1_policy()->print_yg_surv_rate_info();
3015 SpecializationStats::print(); 3015 SpecializationStats::print();
3016 } 3016 }
3017 3017
3018 #ifndef PRODUCT
3019 // Helpful for debugging RSet issues.
3020
3021 class PrintRSetsClosure : public HeapRegionClosure {
3022 private:
3023 const char* _msg;
3024 size_t _occupied_sum;
3025
3026 public:
3027 bool doHeapRegion(HeapRegion* r) {
3028 HeapRegionRemSet* hrrs = r->rem_set();
3029 size_t occupied = hrrs->occupied();
3030 _occupied_sum += occupied;
3031
3032 gclog_or_tty->print_cr("Printing RSet for region "HR_FORMAT,
3033 HR_FORMAT_PARAMS(r));
3034 if (occupied == 0) {
3035 gclog_or_tty->print_cr(" RSet is empty");
3036 } else {
3037 hrrs->print();
3038 }
3039 gclog_or_tty->print_cr("----------");
3040 return false;
3041 }
3042
3043 PrintRSetsClosure(const char* msg) : _msg(msg), _occupied_sum(0) {
3044 gclog_or_tty->cr();
3045 gclog_or_tty->print_cr("========================================");
3046 gclog_or_tty->print_cr(msg);
3047 gclog_or_tty->cr();
3048 }
3049
3050 ~PrintRSetsClosure() {
3051 gclog_or_tty->print_cr("Occupied Sum: "SIZE_FORMAT, _occupied_sum);
3052 gclog_or_tty->print_cr("========================================");
3053 gclog_or_tty->cr();
3054 }
3055 };
3056
3057 void G1CollectedHeap::print_cset_rsets() {
3058 PrintRSetsClosure cl("Printing CSet RSets");
3059 collection_set_iterate(&cl);
3060 }
3061
3062 void G1CollectedHeap::print_all_rsets() {
3063 PrintRSetsClosure cl("Printing All RSets");;
3064 heap_region_iterate(&cl);
3065 }
3066 #endif // PRODUCT
3067
3018 G1CollectedHeap* G1CollectedHeap::heap() { 3068 G1CollectedHeap* G1CollectedHeap::heap() {
3019 assert(_sh->kind() == CollectedHeap::G1CollectedHeap, 3069 assert(_sh->kind() == CollectedHeap::G1CollectedHeap,
3020 "not a garbage-first heap"); 3070 "not a garbage-first heap");
3021 return _g1h; 3071 return _g1h;
3022 } 3072 }
3146 _surviving_young_words = NULL; 3196 _surviving_young_words = NULL;
3147 } 3197 }
3148 3198
3149 // </NEW PREDICTION> 3199 // </NEW PREDICTION>
3150 3200
3151 struct PrepareForRSScanningClosure : public HeapRegionClosure { 3201 #ifdef ASSERT
3152 bool doHeapRegion(HeapRegion *r) { 3202 class VerifyCSetClosure: public HeapRegionClosure {
3153 r->rem_set()->set_iter_claimed(0); 3203 public:
3204 bool doHeapRegion(HeapRegion* hr) {
3205 // Here we check that the CSet region's RSet is ready for parallel
3206 // iteration. The fields that we'll verify are only manipulated
3207 // when the region is part of a CSet and is collected. Afterwards,
3208 // we reset these fields when we clear the region's RSet (when the
3209 // region is freed) so they are ready when the region is
3210 // re-allocated. The only exception to this is if there's an
3211 // evacuation failure and instead of freeing the region we leave
3212 // it in the heap. In that case, we reset these fields during
3213 // evacuation failure handling.
3214 guarantee(hr->rem_set()->verify_ready_for_par_iteration(), "verification");
3215
3216 // Here's a good place to add any other checks we'd like to
3217 // perform on CSet regions.
3154 return false; 3218 return false;
3155 } 3219 }
3156 }; 3220 };
3221 #endif // ASSERT
3157 3222
3158 #if TASKQUEUE_STATS 3223 #if TASKQUEUE_STATS
3159 void G1CollectedHeap::print_taskqueue_stats_hdr(outputStream* const st) { 3224 void G1CollectedHeap::print_taskqueue_stats_hdr(outputStream* const st) {
3160 st->print_raw_cr("GC Task Stats"); 3225 st->print_raw_cr("GC Task Stats");
3161 st->print_raw("thr "); TaskQueueStats::print_header(1, st); st->cr(); 3226 st->print_raw("thr "); TaskQueueStats::print_header(1, st); st->cr();
3255 IsGCActiveMark x; 3320 IsGCActiveMark x;
3256 3321
3257 gc_prologue(false); 3322 gc_prologue(false);
3258 increment_total_collections(false /* full gc */); 3323 increment_total_collections(false /* full gc */);
3259 3324
3260 #if G1_REM_SET_LOGGING
3261 gclog_or_tty->print_cr("\nJust chose CS, heap:");
3262 print();
3263 #endif
3264
3265 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) { 3325 if (VerifyBeforeGC && total_collections() >= VerifyGCStartAt) {
3266 HandleMark hm; // Discard invalid handles created during verification 3326 HandleMark hm; // Discard invalid handles created during verification
3267 gclog_or_tty->print(" VerifyBeforeGC:"); 3327 gclog_or_tty->print(" VerifyBeforeGC:");
3268 prepare_for_verify(); 3328 prepare_for_verify();
3269 Universe::verify(/* allow dirty */ false, 3329 Universe::verify(/* allow dirty */ false,
3345 // when marking restarts. 3405 // when marking restarts.
3346 if (mark_in_progress()) { 3406 if (mark_in_progress()) {
3347 concurrent_mark()->reset_active_task_region_fields_in_cset(); 3407 concurrent_mark()->reset_active_task_region_fields_in_cset();
3348 } 3408 }
3349 3409
3350 // Nothing to do if we were unable to choose a collection set. 3410 #ifdef ASSERT
3351 #if G1_REM_SET_LOGGING 3411 VerifyCSetClosure cl;
3352 gclog_or_tty->print_cr("\nAfter pause, heap:"); 3412 collection_set_iterate(&cl);
3353 print(); 3413 #endif // ASSERT
3354 #endif
3355 PrepareForRSScanningClosure prepare_for_rs_scan;
3356 collection_set_iterate(&prepare_for_rs_scan);
3357 3414
3358 setup_surviving_young_words(); 3415 setup_surviving_young_words();
3359 3416
3360 // Set up the gc allocation regions. 3417 // Set up the gc allocation regions.
3361 get_gc_alloc_regions(); 3418 get_gc_alloc_regions();
3953 4010
3954 if (cur->evacuation_failed()) { 4011 if (cur->evacuation_failed()) {
3955 assert(cur->in_collection_set(), "bad CS"); 4012 assert(cur->in_collection_set(), "bad CS");
3956 RemoveSelfPointerClosure rspc(_g1h, cur, cl); 4013 RemoveSelfPointerClosure rspc(_g1h, cur, cl);
3957 4014
4015 // In the common case we make sure that this is done when the
4016 // region is freed so that it is "ready-to-go" when it's
4017 // re-allocated. However, when evacuation failure happens, a
4018 // region will remain in the heap and might ultimately be added
4019 // to a CSet in the future. So we have to be careful here and
4020 // make sure the region's RSet is ready for parallel iteration
4021 // whenever this might be required in the future.
4022 cur->rem_set()->reset_for_par_iteration();
3958 cur->reset_bot(); 4023 cur->reset_bot();
3959 cl->set_region(cur); 4024 cl->set_region(cur);
3960 cur->object_iterate(&rspc); 4025 cur->object_iterate(&rspc);
3961 4026
3962 // A number of manipulations to make the TAMS be the current top, 4027 // A number of manipulations to make the TAMS be the current top,
4472 assert(barrier != G1BarrierRS || obj != NULL, 4537 assert(barrier != G1BarrierRS || obj != NULL,
4473 "Precondition: G1BarrierRS implies obj is nonNull"); 4538 "Precondition: G1BarrierRS implies obj is nonNull");
4474 4539
4475 // here the null check is implicit in the cset_fast_test() test 4540 // here the null check is implicit in the cset_fast_test() test
4476 if (_g1->in_cset_fast_test(obj)) { 4541 if (_g1->in_cset_fast_test(obj)) {
4477 #if G1_REM_SET_LOGGING
4478 gclog_or_tty->print_cr("Loc "PTR_FORMAT" contains pointer "PTR_FORMAT" "
4479 "into CS.", p, (void*) obj);
4480 #endif
4481 if (obj->is_forwarded()) { 4542 if (obj->is_forwarded()) {
4482 oopDesc::encode_store_heap_oop(p, obj->forwardee()); 4543 oopDesc::encode_store_heap_oop(p, obj->forwardee());
4483 } else { 4544 } else {
4484 oop copy_oop = copy_to_survivor_space(obj); 4545 oop copy_oop = copy_to_survivor_space(obj);
4485 oopDesc::encode_store_heap_oop(p, copy_oop); 4546 oopDesc::encode_store_heap_oop(p, copy_oop);