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

Print this page
rev 6796 : [mq]: templateOopIterate
rev 6801 : imported patch defaultToTrue


  40 
  41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  42 
  43 int    HeapRegion::LogOfHRGrainBytes = 0;
  44 int    HeapRegion::LogOfHRGrainWords = 0;
  45 size_t HeapRegion::GrainBytes        = 0;
  46 size_t HeapRegion::GrainWords        = 0;
  47 size_t HeapRegion::CardsPerRegion    = 0;
  48 
  49 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  50                                  HeapRegion* hr, ExtendedOopClosure* cl,
  51                                  CardTableModRefBS::PrecisionStyle precision,
  52                                  FilterKind fk) :
  53   DirtyCardToOopClosure(hr, cl, precision, NULL),
  54   _hr(hr), _fk(fk), _g1(g1) { }
  55 
  56 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  57                                                    OopClosure* oc) :
  58   _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }
  59 
  60 template<class ClosureType>
  61 HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h,
  62                                HeapRegion* hr,
  63                                HeapWord* cur, HeapWord* top) {
  64   oop cur_oop = oop(cur);
  65   size_t oop_size = hr->block_size(cur);
  66   HeapWord* next_obj = cur + oop_size;
  67   while (next_obj < top) {
  68     // Keep filtering the remembered set.
  69     if (!g1h->is_obj_dead(cur_oop, hr)) {
  70       // Bottom lies entirely below top, so we can call the
  71       // non-memRegion version of oop_iterate below.
  72       cur_oop->oop_iterate(cl);
  73     }
  74     cur = next_obj;
  75     cur_oop = oop(cur);
  76     oop_size = hr->block_size(cur);
  77     next_obj = cur + oop_size;
  78   }
  79   return cur;
  80 }
  81 
  82 void HeapRegionDCTOC::walk_mem_region(MemRegion mr,
  83                                       HeapWord* bottom,
  84                                       HeapWord* top) {
  85   G1CollectedHeap* g1h = _g1;
  86   size_t oop_size;
  87   ExtendedOopClosure* cl2 = NULL;
  88 
  89   FilterIntoCSClosure intoCSFilt(this, g1h, _cl);
  90   FilterOutOfRegionClosure outOfRegionFilt(_hr, _cl);
  91 
  92   switch (_fk) {
  93   case NoFilterKind:          cl2 = _cl; break;
  94   case IntoCSFilterKind:      cl2 = &intoCSFilt; break;
  95   case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break;
  96   default:                    ShouldNotReachHere();
  97   }
  98 
  99   // Start filtering what we add to the remembered set. If the object is
 100   // not considered dead, either because it is marked (in the mark bitmap)
 101   // or it was allocated after marking finished, then we add it. Otherwise
 102   // we can safely ignore the object.
 103   if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 104     oop_size = oop(bottom)->oop_iterate(cl2, mr);
 105   } else {
 106     oop_size = _hr->block_size(bottom);
 107   }
 108 
 109   bottom += oop_size;
 110 
 111   if (bottom < top) {
 112     // We replicate the loop below for several kinds of possible filters.
 113     switch (_fk) {
 114     case NoFilterKind:
 115       bottom = walk_mem_region_loop(_cl, g1h, _hr, bottom, top);
 116       break;
 117 
 118     case IntoCSFilterKind: {
 119       FilterIntoCSClosure filt(this, g1h, _cl);
 120       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 121       break;
 122     }
 123 
 124     case OutOfRegionFilterKind: {
 125       FilterOutOfRegionClosure filt(_hr, _cl);
 126       bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
 127       break;
 128     }
 129 
 130     default:
 131       ShouldNotReachHere();
 132     }
 133 
 134     // Last object. Need to do dead-obj filtering here too.
 135     if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 136       oop(bottom)->oop_iterate(cl2, mr);
 137     }
 138   }
 139 }
 140 
 141 // Minimum region size; we won't go lower than that.
 142 // We might want to decrease this in the future, to deal with small
 143 // heaps a bit more efficiently.
 144 #define MIN_REGION_SIZE  (      1024 * 1024 )
 145 
 146 // Maximum region size; we don't go higher than that. There's a good
 147 // reason for having an upper bound. We don't want regions to get too
 148 // large, otherwise cleanup's effectiveness would decrease as there
 149 // will be fewer opportunities to find totally empty regions after
 150 // marking.
 151 #define MAX_REGION_SIZE  ( 32 * 1024 * 1024 )
 152 
 153 // The automatic region size calculation will try to have around this
 154 // many regions in the heap (based on the min heap size).
 155 #define TARGET_REGION_NUMBER          2048
 156 




  40 
  41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  42 
  43 int    HeapRegion::LogOfHRGrainBytes = 0;
  44 int    HeapRegion::LogOfHRGrainWords = 0;
  45 size_t HeapRegion::GrainBytes        = 0;
  46 size_t HeapRegion::GrainWords        = 0;
  47 size_t HeapRegion::CardsPerRegion    = 0;
  48 
  49 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  50                                  HeapRegion* hr, ExtendedOopClosure* cl,
  51                                  CardTableModRefBS::PrecisionStyle precision,
  52                                  FilterKind fk) :
  53   DirtyCardToOopClosure(hr, cl, precision, NULL),
  54   _hr(hr), _fk(fk), _g1(g1) { }
  55 
  56 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  57                                                    OopClosure* oc) :
  58   _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }
  59 
  60 template<bool nv, class ClosureType>
  61 HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h,
  62                                HeapRegion* hr,
  63                                HeapWord* cur, HeapWord* top) {
  64   oop cur_oop = oop(cur);
  65   size_t oop_size = hr->block_size(cur);
  66   HeapWord* next_obj = cur + oop_size;
  67   while (next_obj < top) {
  68     // Keep filtering the remembered set.
  69     if (!g1h->is_obj_dead(cur_oop, hr)) {
  70       // Bottom lies entirely below top, so we can call the
  71       // non-memRegion version of oop_iterate below.
  72       cur_oop->oop_iterate<nv>(cl);
  73     }
  74     cur = next_obj;
  75     cur_oop = oop(cur);
  76     oop_size = hr->block_size(cur);
  77     next_obj = cur + oop_size;
  78   }
  79   return cur;
  80 }
  81 
  82 void HeapRegionDCTOC::walk_mem_region(MemRegion mr,
  83                                       HeapWord* bottom,
  84                                       HeapWord* top) {
  85   G1CollectedHeap* g1h = _g1;
  86   size_t oop_size;
  87   ExtendedOopClosure* cl2 = NULL;
  88 
  89   FilterIntoCSClosure intoCSFilt(this, g1h, _cl);
  90   FilterOutOfRegionClosure outOfRegionFilt(_hr, _cl);
  91 
  92   switch (_fk) {
  93   case NoFilterKind:          cl2 = _cl; break;
  94   case IntoCSFilterKind:      cl2 = &intoCSFilt; break;
  95   case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break;
  96   default:                    ShouldNotReachHere();
  97   }
  98 
  99   // Start filtering what we add to the remembered set. If the object is
 100   // not considered dead, either because it is marked (in the mark bitmap)
 101   // or it was allocated after marking finished, then we add it. Otherwise
 102   // we can safely ignore the object.
 103   if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 104     oop_size = oop(bottom)->oop_iterate<false>(cl2, mr);
 105   } else {
 106     oop_size = _hr->block_size(bottom);
 107   }
 108 
 109   bottom += oop_size;
 110 
 111   if (bottom < top) {
 112     // We replicate the loop below for several kinds of possible filters.
 113     switch (_fk) {
 114     case NoFilterKind:
 115       bottom = walk_mem_region_loop<false>(_cl, g1h, _hr, bottom, top);
 116       break;
 117 
 118     case IntoCSFilterKind: {
 119       FilterIntoCSClosure filt(this, g1h, _cl);
 120       bottom = walk_mem_region_loop<true>(&filt, g1h, _hr, bottom, top);
 121       break;
 122     }
 123 
 124     case OutOfRegionFilterKind: {
 125       FilterOutOfRegionClosure filt(_hr, _cl);
 126       bottom = walk_mem_region_loop<true>(&filt, g1h, _hr, bottom, top);
 127       break;
 128     }
 129 
 130     default:
 131       ShouldNotReachHere();
 132     }
 133 
 134     // Last object. Need to do dead-obj filtering here too.
 135     if (!g1h->is_obj_dead(oop(bottom), _hr)) {
 136       oop(bottom)->oop_iterate<false>(cl2, mr);
 137     }
 138   }
 139 }
 140 
 141 // Minimum region size; we won't go lower than that.
 142 // We might want to decrease this in the future, to deal with small
 143 // heaps a bit more efficiently.
 144 #define MIN_REGION_SIZE  (      1024 * 1024 )
 145 
 146 // Maximum region size; we don't go higher than that. There's a good
 147 // reason for having an upper bound. We don't want regions to get too
 148 // large, otherwise cleanup's effectiveness would decrease as there
 149 // will be fewer opportunities to find totally empty regions after
 150 // marking.
 151 #define MAX_REGION_SIZE  ( 32 * 1024 * 1024 )
 152 
 153 // The automatic region size calculation will try to have around this
 154 // many regions in the heap (based on the min heap size).
 155 #define TARGET_REGION_NUMBER          2048
 156