src/share/vm/gc_implementation/g1/heapRegion.cpp

Print this page
rev 2691 : [mq]: g1-reference-processing


  28 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
  29 #include "gc_implementation/g1/heapRegion.inline.hpp"
  30 #include "gc_implementation/g1/heapRegionRemSet.hpp"
  31 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
  32 #include "memory/genOopClosures.inline.hpp"
  33 #include "memory/iterator.hpp"
  34 #include "oops/oop.inline.hpp"
  35 
  36 int HeapRegion::LogOfHRGrainBytes = 0;
  37 int HeapRegion::LogOfHRGrainWords = 0;
  38 int HeapRegion::GrainBytes        = 0;
  39 int HeapRegion::GrainWords        = 0;
  40 int HeapRegion::CardsPerRegion    = 0;
  41 
  42 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  43                                  HeapRegion* hr, OopClosure* cl,
  44                                  CardTableModRefBS::PrecisionStyle precision,
  45                                  FilterKind fk) :
  46   ContiguousSpaceDCTOC(hr, cl, precision, NULL),
  47   _hr(hr), _fk(fk), _g1(g1)
  48 {}
  49 
  50 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  51                                                    OopClosure* oc) :
  52   _r_bottom(r->bottom()), _r_end(r->end()),
  53   _oc(oc), _out_of_region(0)
  54 {}
  55 
  56 class VerifyLiveClosure: public OopClosure {
  57 private:
  58   G1CollectedHeap* _g1h;
  59   CardTableModRefBS* _bs;
  60   oop _containing_obj;
  61   bool _failures;
  62   int _n_failures;
  63   VerifyOption _vo;
  64 public:
  65   // _vo == UsePrevMarking -> use "prev" marking information,
  66   // _vo == UseNextMarking -> use "next" marking information,
  67   // _vo == UseMarkWord    -> use mark word from object header.
  68   VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :


 197       // non-memRegion version of oop_iterate below.
 198       cur_oop->oop_iterate(cl);
 199     }
 200     cur = next_obj;
 201     cur_oop = oop(cur);
 202     oop_size = cur_oop->size();
 203     next_obj = cur + oop_size;
 204   }
 205   return cur;
 206 }
 207 
 208 void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr,
 209                                               HeapWord* bottom,
 210                                               HeapWord* top,
 211                                               OopClosure* cl) {
 212   G1CollectedHeap* g1h = _g1;
 213 
 214   int oop_size;
 215 
 216   OopClosure* cl2 = cl;
 217   FilterIntoCSClosure intoCSFilt(this, g1h, cl);




























 218   FilterOutOfRegionClosure outOfRegionFilt(_hr, cl);

 219   switch (_fk) {
 220   case IntoCSFilterKind:      cl2 = &intoCSFilt; break;
 221   case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break;
 222   }
 223 
 224   // Start filtering what we add to the remembered set. If the object is
 225   // not considered dead, either because it is marked (in the mark bitmap)
 226   // or it was allocated after marking finished, then we add it. Otherwise
 227   // we can safely ignore the object.
 228   if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 229     oop_size = oop(bottom)->oop_iterate(cl2, mr);
 230   } else {
 231     oop_size = oop(bottom)->size();
 232   }
 233 
 234   bottom += oop_size;
 235 
 236   if (bottom < top) {
 237     // We replicate the loop below for several kinds of possible filters.
 238     switch (_fk) {
 239     case NoFilterKind:
 240       bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top);
 241       break;

 242     case IntoCSFilterKind: {
 243       FilterIntoCSClosure filt(this, g1h, cl);
 244       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 245       break;
 246     }

 247     case OutOfRegionFilterKind: {
 248       FilterOutOfRegionClosure filt(_hr, cl);
 249       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 250       break;
 251     }

 252     default:
 253       ShouldNotReachHere();
 254     }
 255 
 256     // Last object. Need to do dead-obj filtering here too.
 257     if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 258       oop(bottom)->oop_iterate(cl2, mr);
 259     }
 260   }
 261 }
 262 
 263 // Minimum region size; we won't go lower than that.
 264 // We might want to decrease this in the future, to deal with small
 265 // heaps a bit more efficiently.
 266 #define MIN_REGION_SIZE  (      1024 * 1024 )
 267 
 268 // Maximum region size; we don't go higher than that. There's a good
 269 // reason for having an upper bound. We don't want regions to get too
 270 // large, otherwise cleanup's effectiveness would decrease as there
 271 // will be fewer opportunities to find totally empty regions after


 466       high = mid_bs;
 467     }
 468   }
 469   assert(low == high && low >= addr, "Didn't work.");
 470   return low;
 471 }
 472 
 473 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
 474   G1OffsetTableContigSpace::initialize(mr, false, mangle_space);
 475   hr_clear(false/*par*/, clear_space);
 476 }
 477 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
 478 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
 479 #endif // _MSC_VER
 480 
 481 
 482 HeapRegion::
 483 HeapRegion(size_t hrs_index, G1BlockOffsetSharedArray* sharedOffsetArray,
 484            MemRegion mr, bool is_zeroed)
 485   : G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed),
 486     _next_fk(HeapRegionDCTOC::NoFilterKind), _hrs_index(hrs_index),
 487     _humongous_type(NotHumongous), _humongous_start_region(NULL),
 488     _in_collection_set(false),
 489     _next_in_special_set(NULL), _orig_end(NULL),
 490     _claimed(InitialClaimValue), _evacuation_failed(false),
 491     _prev_marked_bytes(0), _next_marked_bytes(0), _sort_index(-1),
 492     _young_type(NotYoung), _next_young_region(NULL),
 493     _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
 494 #ifdef ASSERT
 495     _containing_set(NULL),
 496 #endif // ASSERT
 497      _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
 498     _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
 499     _predicted_bytes_to_copy(0)
 500 {
 501   _orig_end = mr.end();
 502   // Note that initialize() will set the start of the unmarked area of the
 503   // region.
 504   this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
 505   set_top(bottom());
 506   set_saved_mark();




  28 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
  29 #include "gc_implementation/g1/heapRegion.inline.hpp"
  30 #include "gc_implementation/g1/heapRegionRemSet.hpp"
  31 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
  32 #include "memory/genOopClosures.inline.hpp"
  33 #include "memory/iterator.hpp"
  34 #include "oops/oop.inline.hpp"
  35 
  36 int HeapRegion::LogOfHRGrainBytes = 0;
  37 int HeapRegion::LogOfHRGrainWords = 0;
  38 int HeapRegion::GrainBytes        = 0;
  39 int HeapRegion::GrainWords        = 0;
  40 int HeapRegion::CardsPerRegion    = 0;
  41 
  42 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  43                                  HeapRegion* hr, OopClosure* cl,
  44                                  CardTableModRefBS::PrecisionStyle precision,
  45                                  FilterKind fk) :
  46   ContiguousSpaceDCTOC(hr, cl, precision, NULL),
  47   _hr(hr), _fk(fk), _g1(g1)
  48 { }
  49 
  50 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  51                                                    OopClosure* oc) :
  52   _r_bottom(r->bottom()), _r_end(r->end()),
  53   _oc(oc), _out_of_region(0)
  54 {}
  55 
  56 class VerifyLiveClosure: public OopClosure {
  57 private:
  58   G1CollectedHeap* _g1h;
  59   CardTableModRefBS* _bs;
  60   oop _containing_obj;
  61   bool _failures;
  62   int _n_failures;
  63   VerifyOption _vo;
  64 public:
  65   // _vo == UsePrevMarking -> use "prev" marking information,
  66   // _vo == UseNextMarking -> use "next" marking information,
  67   // _vo == UseMarkWord    -> use mark word from object header.
  68   VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :


 197       // non-memRegion version of oop_iterate below.
 198       cur_oop->oop_iterate(cl);
 199     }
 200     cur = next_obj;
 201     cur_oop = oop(cur);
 202     oop_size = cur_oop->size();
 203     next_obj = cur + oop_size;
 204   }
 205   return cur;
 206 }
 207 
 208 void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr,
 209                                               HeapWord* bottom,
 210                                               HeapWord* top,
 211                                               OopClosure* cl) {
 212   G1CollectedHeap* g1h = _g1;
 213 
 214   int oop_size;
 215 
 216   OopClosure* cl2 = cl;
 217 
 218   // If we are scanning the remembered sets looking for refs
 219   // into the collection set during an evacuation pause then
 220   // we will want to 'discover' reference objects that point
 221   // to referents in the collection set.
 222   //
 223   // Unfortunately it is an instance of FilterIntoCSClosure
 224   // that is iterated over the reference fields of oops in
 225   // mr (and not the G1ParPushHeapRSClosure - which is the
 226   // cl parameter).
 227   // If we set the _ref_processor field in the FilterIntoCSClosure
 228   // instance, all the reference objects that are walked
 229   // (regardless of whether their referent object's are in
 230   // the cset) will be 'discovered'.
 231   //
 232   // The G1STWIsAlive closure considers a referent object that
 233   // is outside the cset as alive. The G1CopyingKeepAliveClosure
 234   // skips referents that are not in the cset.
 235   //
 236   // Therefore reference objects in mr with a referent that is
 237   // outside the cset should be OK.
 238 
 239   ReferenceProcessor* rp = _cl->_ref_processor;
 240   if (rp != NULL) {
 241     assert(rp == _g1->ref_processor_stw(), "should be stw");
 242     assert(_fk == IntoCSFilterKind, "should be looking for refs into CS");
 243   }
 244 
 245   FilterIntoCSClosure intoCSFilt(this, g1h, cl, rp);
 246   FilterOutOfRegionClosure outOfRegionFilt(_hr, cl);
 247 
 248   switch (_fk) {
 249   case IntoCSFilterKind:      cl2 = &intoCSFilt; break;
 250   case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break;
 251   }
 252 
 253   // Start filtering what we add to the remembered set. If the object is
 254   // not considered dead, either because it is marked (in the mark bitmap)
 255   // or it was allocated after marking finished, then we add it. Otherwise
 256   // we can safely ignore the object.
 257   if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 258     oop_size = oop(bottom)->oop_iterate(cl2, mr);
 259   } else {
 260     oop_size = oop(bottom)->size();
 261   }
 262 
 263   bottom += oop_size;
 264 
 265   if (bottom < top) {
 266     // We replicate the loop below for several kinds of possible filters.
 267     switch (_fk) {
 268     case NoFilterKind:
 269       bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top);
 270       break;
 271 
 272     case IntoCSFilterKind: {
 273       FilterIntoCSClosure filt(this, g1h, cl, rp);
 274       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 275       break;
 276     }
 277 
 278     case OutOfRegionFilterKind: {
 279       FilterOutOfRegionClosure filt(_hr, cl);
 280       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 281       break;
 282     }
 283 
 284     default:
 285       ShouldNotReachHere();
 286     }
 287 
 288     // Last object. Need to do dead-obj filtering here too.
 289     if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 290       oop(bottom)->oop_iterate(cl2, mr);
 291     }
 292   }
 293 }
 294 
 295 // Minimum region size; we won't go lower than that.
 296 // We might want to decrease this in the future, to deal with small
 297 // heaps a bit more efficiently.
 298 #define MIN_REGION_SIZE  (      1024 * 1024 )
 299 
 300 // Maximum region size; we don't go higher than that. There's a good
 301 // reason for having an upper bound. We don't want regions to get too
 302 // large, otherwise cleanup's effectiveness would decrease as there
 303 // will be fewer opportunities to find totally empty regions after


 498       high = mid_bs;
 499     }
 500   }
 501   assert(low == high && low >= addr, "Didn't work.");
 502   return low;
 503 }
 504 
 505 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
 506   G1OffsetTableContigSpace::initialize(mr, false, mangle_space);
 507   hr_clear(false/*par*/, clear_space);
 508 }
 509 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
 510 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
 511 #endif // _MSC_VER
 512 
 513 
 514 HeapRegion::
 515 HeapRegion(size_t hrs_index, G1BlockOffsetSharedArray* sharedOffsetArray,
 516            MemRegion mr, bool is_zeroed)
 517   : G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed),
 518     _hrs_index(hrs_index),
 519     _humongous_type(NotHumongous), _humongous_start_region(NULL),
 520     _in_collection_set(false),
 521     _next_in_special_set(NULL), _orig_end(NULL),
 522     _claimed(InitialClaimValue), _evacuation_failed(false),
 523     _prev_marked_bytes(0), _next_marked_bytes(0), _sort_index(-1),
 524     _young_type(NotYoung), _next_young_region(NULL),
 525     _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
 526 #ifdef ASSERT
 527     _containing_set(NULL),
 528 #endif // ASSERT
 529      _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
 530     _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
 531     _predicted_bytes_to_copy(0)
 532 {
 533   _orig_end = mr.end();
 534   // Note that initialize() will set the start of the unmarked area of the
 535   // region.
 536   this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
 537   set_top(bottom());
 538   set_saved_mark();