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

changeset 7131
d35872270666
parent 7009
3f2894c5052e
child 7535
7ae4e26cb1e0
child 7659
38d6febe66af
     1.1 --- a/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Mon Sep 08 14:13:01 2014 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1MarkSweep.cpp	Tue Sep 09 00:05:25 2014 +0200
     1.3 @@ -194,76 +194,6 @@
     1.4    gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
     1.5  }
     1.6  
     1.7 -class G1PrepareCompactClosure: public HeapRegionClosure {
     1.8 -  G1CollectedHeap* _g1h;
     1.9 -  ModRefBarrierSet* _mrbs;
    1.10 -  CompactPoint _cp;
    1.11 -  HeapRegionSetCount _humongous_regions_removed;
    1.12 -
    1.13 -  bool is_cp_initialized() const {
    1.14 -    return _cp.space != NULL;
    1.15 -  }
    1.16 -
    1.17 -  void prepare_for_compaction(HeapRegion* hr, HeapWord* end) {
    1.18 -    // If this is the first live region that we came across which we can compact,
    1.19 -    // initialize the CompactPoint.
    1.20 -    if (!is_cp_initialized()) {
    1.21 -      _cp.space = hr;
    1.22 -      _cp.threshold = hr->initialize_threshold();
    1.23 -    }
    1.24 -    hr->prepare_for_compaction(&_cp);
    1.25 -    // Also clear the part of the card table that will be unused after
    1.26 -    // compaction.
    1.27 -    _mrbs->clear(MemRegion(hr->compaction_top(), end));
    1.28 -  }
    1.29 -
    1.30 -  void free_humongous_region(HeapRegion* hr) {
    1.31 -    HeapWord* end = hr->end();
    1.32 -    FreeRegionList dummy_free_list("Dummy Free List for G1MarkSweep");
    1.33 -
    1.34 -    assert(hr->startsHumongous(),
    1.35 -           "Only the start of a humongous region should be freed.");
    1.36 -
    1.37 -    hr->set_containing_set(NULL);
    1.38 -    _humongous_regions_removed.increment(1u, hr->capacity());
    1.39 -
    1.40 -    _g1h->free_humongous_region(hr, &dummy_free_list, false /* par */);
    1.41 -    prepare_for_compaction(hr, end);
    1.42 -    dummy_free_list.remove_all();
    1.43 -  }
    1.44 -
    1.45 -public:
    1.46 -  G1PrepareCompactClosure()
    1.47 -  : _g1h(G1CollectedHeap::heap()),
    1.48 -    _mrbs(_g1h->g1_barrier_set()),
    1.49 -    _cp(NULL),
    1.50 -    _humongous_regions_removed() { }
    1.51 -
    1.52 -  void update_sets() {
    1.53 -    // We'll recalculate total used bytes and recreate the free list
    1.54 -    // at the end of the GC, so no point in updating those values here.
    1.55 -    HeapRegionSetCount empty_set;
    1.56 -    _g1h->remove_from_old_sets(empty_set, _humongous_regions_removed);
    1.57 -  }
    1.58 -
    1.59 -  bool doHeapRegion(HeapRegion* hr) {
    1.60 -    if (hr->isHumongous()) {
    1.61 -      if (hr->startsHumongous()) {
    1.62 -        oop obj = oop(hr->bottom());
    1.63 -        if (obj->is_gc_marked()) {
    1.64 -          obj->forward_to(obj);
    1.65 -        } else  {
    1.66 -          free_humongous_region(hr);
    1.67 -        }
    1.68 -      } else {
    1.69 -        assert(hr->continuesHumongous(), "Invalid humongous.");
    1.70 -      }
    1.71 -    } else {
    1.72 -      prepare_for_compaction(hr, hr->end());
    1.73 -    }
    1.74 -    return false;
    1.75 -  }
    1.76 -};
    1.77  
    1.78  void G1MarkSweep::mark_sweep_phase2() {
    1.79    // Now all live objects are marked, compute the new object addresses.
    1.80 @@ -272,14 +202,10 @@
    1.81    // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
    1.82    // tracking expects us to do so. See comment under phase4.
    1.83  
    1.84 -  G1CollectedHeap* g1h = G1CollectedHeap::heap();
    1.85 -
    1.86    GCTraceTime tm("phase 2", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
    1.87    GenMarkSweep::trace("2");
    1.88  
    1.89 -  G1PrepareCompactClosure blk;
    1.90 -  g1h->heap_region_iterate(&blk);
    1.91 -  blk.update_sets();
    1.92 +  prepare_compaction();
    1.93  }
    1.94  
    1.95  class G1AdjustPointersClosure: public HeapRegionClosure {
    1.96 @@ -374,3 +300,68 @@
    1.97    g1h->heap_region_iterate(&blk);
    1.98  
    1.99  }
   1.100 +
   1.101 +void G1MarkSweep::prepare_compaction_work(G1PrepareCompactClosure* blk) {
   1.102 +  G1CollectedHeap* g1h = G1CollectedHeap::heap();
   1.103 +  g1h->heap_region_iterate(blk);
   1.104 +  blk->update_sets();
   1.105 +}
   1.106 +
   1.107 +void G1PrepareCompactClosure::free_humongous_region(HeapRegion* hr) {
   1.108 +  HeapWord* end = hr->end();
   1.109 +  FreeRegionList dummy_free_list("Dummy Free List for G1MarkSweep");
   1.110 +
   1.111 +  assert(hr->startsHumongous(),
   1.112 +         "Only the start of a humongous region should be freed.");
   1.113 +
   1.114 +  hr->set_containing_set(NULL);
   1.115 +  _humongous_regions_removed.increment(1u, hr->capacity());
   1.116 +
   1.117 +  _g1h->free_humongous_region(hr, &dummy_free_list, false /* par */);
   1.118 +  prepare_for_compaction(hr, end);
   1.119 +  dummy_free_list.remove_all();
   1.120 +}
   1.121 +
   1.122 +void G1PrepareCompactClosure::prepare_for_compaction(HeapRegion* hr, HeapWord* end) {
   1.123 +  // If this is the first live region that we came across which we can compact,
   1.124 +  // initialize the CompactPoint.
   1.125 +  if (!is_cp_initialized()) {
   1.126 +    _cp.space = hr;
   1.127 +    _cp.threshold = hr->initialize_threshold();
   1.128 +  }
   1.129 +  prepare_for_compaction_work(&_cp, hr, end);
   1.130 +}
   1.131 +
   1.132 +void G1PrepareCompactClosure::prepare_for_compaction_work(CompactPoint* cp,
   1.133 +                                                          HeapRegion* hr,
   1.134 +                                                          HeapWord* end) {
   1.135 +  hr->prepare_for_compaction(cp);
   1.136 +  // Also clear the part of the card table that will be unused after
   1.137 +  // compaction.
   1.138 +  _mrbs->clear(MemRegion(hr->compaction_top(), end));
   1.139 +}
   1.140 +
   1.141 +void G1PrepareCompactClosure::update_sets() {
   1.142 +  // We'll recalculate total used bytes and recreate the free list
   1.143 +  // at the end of the GC, so no point in updating those values here.
   1.144 +  HeapRegionSetCount empty_set;
   1.145 +  _g1h->remove_from_old_sets(empty_set, _humongous_regions_removed);
   1.146 +}
   1.147 +
   1.148 +bool G1PrepareCompactClosure::doHeapRegion(HeapRegion* hr) {
   1.149 +  if (hr->isHumongous()) {
   1.150 +    if (hr->startsHumongous()) {
   1.151 +      oop obj = oop(hr->bottom());
   1.152 +      if (obj->is_gc_marked()) {
   1.153 +        obj->forward_to(obj);
   1.154 +      } else  {
   1.155 +        free_humongous_region(hr);
   1.156 +      }
   1.157 +    } else {
   1.158 +      assert(hr->continuesHumongous(), "Invalid humongous.");
   1.159 +    }
   1.160 +  } else {
   1.161 +    prepare_for_compaction(hr, hr->end());
   1.162 +  }
   1.163 +  return false;
   1.164 +}

mercurial