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

Print this page
rev 3463 : 7114678: G1: various small fixes, code cleanup, and refactoring
Summary: Various cleanups as a prelude to introducing iterators for HeapRegions.
Reviewed-by: johnc
Contributed-by: tonyp


  27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  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 size_t HeapRegion::GrainBytes        = 0;
  39 size_t HeapRegion::GrainWords        = 0;
  40 size_t 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) :
  69     _g1h(g1h), _bs(NULL), _containing_obj(NULL),
  70     _failures(false), _n_failures(0), _vo(vo)
  71   {
  72     BarrierSet* bs = _g1h->barrier_set();
  73     if (bs->is_a(BarrierSet::CardTableModRef))
  74       _bs = (CardTableModRefBS*)bs;


 495     _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
 496 #ifdef ASSERT
 497     _containing_set(NULL),
 498 #endif // ASSERT
 499      _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
 500     _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
 501     _predicted_bytes_to_copy(0)
 502 {
 503   _orig_end = mr.end();
 504   // Note that initialize() will set the start of the unmarked area of the
 505   // region.
 506   this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
 507   set_top(bottom());
 508   set_saved_mark();
 509 
 510   _rem_set =  new HeapRegionRemSet(sharedOffsetArray, this);
 511 
 512   assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
 513 }
 514 
 515 class NextCompactionHeapRegionClosure: public HeapRegionClosure {
 516   const HeapRegion* _target;
 517   bool _target_seen;
 518   HeapRegion* _last;
 519   CompactibleSpace* _res;
 520 public:
 521   NextCompactionHeapRegionClosure(const HeapRegion* target) :
 522     _target(target), _target_seen(false), _res(NULL) {}
 523   bool doHeapRegion(HeapRegion* cur) {
 524     if (_target_seen) {
 525       if (!cur->isHumongous()) {
 526         _res = cur;
 527         return true;
 528       }
 529     } else if (cur == _target) {
 530       _target_seen = true;
 531     }
 532     return false;
 533   }
 534   CompactibleSpace* result() { return _res; }
 535 };
 536 
 537 CompactibleSpace* HeapRegion::next_compaction_space() const {


 538   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 539   // cast away const-ness
 540   HeapRegion* r = (HeapRegion*) this;
 541   NextCompactionHeapRegionClosure blk(r);
 542   g1h->heap_region_iterate_from(r, &blk);
 543   return blk.result();




 544 }
 545 
 546 void HeapRegion::save_marks() {
 547   set_saved_mark();
 548 }
 549 
 550 void HeapRegion::oops_in_mr_iterate(MemRegion mr, OopClosure* cl) {
 551   HeapWord* p = mr.start();
 552   HeapWord* e = mr.end();
 553   oop obj;
 554   while (p < e) {
 555     obj = oop(p);
 556     p += obj->oop_iterate(cl);
 557   }
 558   assert(p == e, "bad memregion: doesn't end on obj boundary");
 559 }
 560 
 561 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \
 562 void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \
 563   ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl);              \




  27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  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 size_t HeapRegion::GrainBytes        = 0;
  39 size_t HeapRegion::GrainWords        = 0;
  40 size_t 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 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  50                                                    OopClosure* oc) :
  51   _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }


  52 
  53 class VerifyLiveClosure: public OopClosure {
  54 private:
  55   G1CollectedHeap* _g1h;
  56   CardTableModRefBS* _bs;
  57   oop _containing_obj;
  58   bool _failures;
  59   int _n_failures;
  60   VerifyOption _vo;
  61 public:
  62   // _vo == UsePrevMarking -> use "prev" marking information,
  63   // _vo == UseNextMarking -> use "next" marking information,
  64   // _vo == UseMarkWord    -> use mark word from object header.
  65   VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :
  66     _g1h(g1h), _bs(NULL), _containing_obj(NULL),
  67     _failures(false), _n_failures(0), _vo(vo)
  68   {
  69     BarrierSet* bs = _g1h->barrier_set();
  70     if (bs->is_a(BarrierSet::CardTableModRef))
  71       _bs = (CardTableModRefBS*)bs;


 492     _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
 493 #ifdef ASSERT
 494     _containing_set(NULL),
 495 #endif // ASSERT
 496      _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
 497     _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
 498     _predicted_bytes_to_copy(0)
 499 {
 500   _orig_end = mr.end();
 501   // Note that initialize() will set the start of the unmarked area of the
 502   // region.
 503   this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
 504   set_top(bottom());
 505   set_saved_mark();
 506 
 507   _rem_set =  new HeapRegionRemSet(sharedOffsetArray, this);
 508 
 509   assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
 510 }
 511 






















 512 CompactibleSpace* HeapRegion::next_compaction_space() const {
 513   // We're not using an iterator given that it will wrap around when
 514   // it reaches the last region and this is not what we want here.
 515   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 516   uint index = hrs_index() + 1;
 517   while (index < g1h->n_regions()) {
 518     HeapRegion* hr = g1h->region_at(index);
 519     if (!hr->isHumongous()) {
 520       return hr;
 521     }
 522     index += 1;
 523   }
 524   return NULL;
 525 }
 526 
 527 void HeapRegion::save_marks() {
 528   set_saved_mark();
 529 }
 530 
 531 void HeapRegion::oops_in_mr_iterate(MemRegion mr, OopClosure* cl) {
 532   HeapWord* p = mr.start();
 533   HeapWord* e = mr.end();
 534   oop obj;
 535   while (p < e) {
 536     obj = oop(p);
 537     p += obj->oop_iterate(cl);
 538   }
 539   assert(p == e, "bad memregion: doesn't end on obj boundary");
 540 }
 541 
 542 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \
 543 void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \
 544   ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl);              \