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

changeset 1061
87fa6e083d82
parent 1055
bcedf688d882
child 1063
7bb995fbd3c0
child 1071
6c4cea9bfa11
     1.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Mon Mar 09 11:32:57 2009 -0400
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Tue Mar 10 00:47:05 2009 -0700
     1.3 @@ -820,6 +820,40 @@
     1.4    }
     1.5  };
     1.6  
     1.7 +class RebuildRSOutOfRegionClosure: public HeapRegionClosure {
     1.8 +  G1CollectedHeap*   _g1h;
     1.9 +  UpdateRSOopClosure _cl;
    1.10 +  int                _worker_i;
    1.11 +public:
    1.12 +  RebuildRSOutOfRegionClosure(G1CollectedHeap* g1, int worker_i = 0) :
    1.13 +    _cl(g1->g1_rem_set()->as_HRInto_G1RemSet(), worker_i),
    1.14 +    _worker_i(worker_i),
    1.15 +    _g1h(g1)
    1.16 +  { }
    1.17 +  bool doHeapRegion(HeapRegion* r) {
    1.18 +    if (!r->continuesHumongous()) {
    1.19 +      _cl.set_from(r);
    1.20 +      r->oop_iterate(&_cl);
    1.21 +    }
    1.22 +    return false;
    1.23 +  }
    1.24 +};
    1.25 +
    1.26 +class ParRebuildRSTask: public AbstractGangTask {
    1.27 +  G1CollectedHeap* _g1;
    1.28 +public:
    1.29 +  ParRebuildRSTask(G1CollectedHeap* g1)
    1.30 +    : AbstractGangTask("ParRebuildRSTask"),
    1.31 +      _g1(g1)
    1.32 +  { }
    1.33 +
    1.34 +  void work(int i) {
    1.35 +    RebuildRSOutOfRegionClosure rebuild_rs(_g1, i);
    1.36 +    _g1->heap_region_par_iterate_chunked(&rebuild_rs, i,
    1.37 +                                         HeapRegion::RebuildRSClaimValue);
    1.38 +  }
    1.39 +};
    1.40 +
    1.41  void G1CollectedHeap::do_collection(bool full, bool clear_all_soft_refs,
    1.42                                      size_t word_size) {
    1.43    ResourceMark rm;
    1.44 @@ -926,24 +960,35 @@
    1.45  
    1.46      reset_gc_time_stamp();
    1.47      // Since everything potentially moved, we will clear all remembered
    1.48 -    // sets, and clear all cards.  Later we will also cards in the used
    1.49 -    // portion of the heap after the resizing (which could be a shrinking.)
    1.50 -    // We will also reset the GC time stamps of the regions.
    1.51 +    // sets, and clear all cards.  Later we will rebuild remebered
    1.52 +    // sets. We will also reset the GC time stamps of the regions.
    1.53      PostMCRemSetClearClosure rs_clear(mr_bs());
    1.54      heap_region_iterate(&rs_clear);
    1.55  
    1.56      // Resize the heap if necessary.
    1.57      resize_if_necessary_after_full_collection(full ? 0 : word_size);
    1.58  
    1.59 -    // Since everything potentially moved, we will clear all remembered
    1.60 -    // sets, but also dirty all cards corresponding to used regions.
    1.61 -    PostMCRemSetInvalidateClosure rs_invalidate(mr_bs());
    1.62 -    heap_region_iterate(&rs_invalidate);
    1.63      if (_cg1r->use_cache()) {
    1.64        _cg1r->clear_and_record_card_counts();
    1.65        _cg1r->clear_hot_cache();
    1.66      }
    1.67  
    1.68 +    // Rebuild remembered sets of all regions.
    1.69 +    if (ParallelGCThreads > 0) {
    1.70 +      ParRebuildRSTask rebuild_rs_task(this);
    1.71 +      assert(check_heap_region_claim_values(
    1.72 +             HeapRegion::InitialClaimValue), "sanity check");
    1.73 +      set_par_threads(workers()->total_workers());
    1.74 +      workers()->run_task(&rebuild_rs_task);
    1.75 +      set_par_threads(0);
    1.76 +      assert(check_heap_region_claim_values(
    1.77 +             HeapRegion::RebuildRSClaimValue), "sanity check");
    1.78 +      reset_heap_region_claim_values();
    1.79 +    } else {
    1.80 +      RebuildRSOutOfRegionClosure rebuild_rs(this);
    1.81 +      heap_region_iterate(&rebuild_rs);
    1.82 +    }
    1.83 +
    1.84      if (PrintGC) {
    1.85        print_size_transition(gclog_or_tty, g1h_prev_used, used(), capacity());
    1.86      }

mercurial