< prev index next >

src/hotspot/share/gc/g1/g1FullGCAdjustTask.cpp

Print this page
*** 38,14 ***
  #include "gc/shared/weakProcessor.inline.hpp"
  #include "logging/log.hpp"
  #include "memory/iterator.inline.hpp"
  #include "runtime/atomic.hpp"
  
  class G1AdjustLiveClosure : public StackObj {
!   G1AdjustClosure* _adjust_closure;
  public:
!   G1AdjustLiveClosure(G1AdjustClosure* cl) :
      _adjust_closure(cl) { }
  
    size_t apply(oop object) {
      return object->oop_iterate_size(_adjust_closure);
    }
--- 38,15 ---
  #include "gc/shared/weakProcessor.inline.hpp"
  #include "logging/log.hpp"
  #include "memory/iterator.inline.hpp"
  #include "runtime/atomic.hpp"
  
+ template <bool ALT_FWD>
  class G1AdjustLiveClosure : public StackObj {
!   G1AdjustClosure<ALT_FWD>* _adjust_closure;
  public:
!   G1AdjustLiveClosure(G1AdjustClosure<ALT_FWD>* cl) :
      _adjust_closure(cl) { }
  
    size_t apply(oop object) {
      return object->oop_iterate_size(_adjust_closure);
    }

*** 60,52 ***
      _collector(collector),
      _bitmap(collector->mark_bitmap()),
      _worker_id(worker_id) { }
  
    bool do_heap_region(HeapRegion* r) {
!     G1AdjustClosure cl(_collector);
      if (r->is_humongous()) {
        // Special handling for humongous regions to get somewhat better
        // work distribution.
        oop obj = cast_to_oop(r->humongous_start_region()->bottom());
        obj->oop_iterate(&cl, MemRegion(r->bottom(), r->top()));
      } else if (!r->is_free()) {
        // Free regions do not contain objects to iterate. So skip them.
!       G1AdjustLiveClosure adjust(&cl);
        r->apply_to_marked_objects(_bitmap, &adjust);
      }
      return false;
    }
  };
  
  G1FullGCAdjustTask::G1FullGCAdjustTask(G1FullCollector* collector) :
      G1FullGCTask("G1 Adjust", collector),
      _root_processor(G1CollectedHeap::heap(), collector->workers()),
      _weak_proc_task(collector->workers()),
!     _hrclaimer(collector->workers()),
-     _adjust(collector) {
    ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
  }
  
! void G1FullGCAdjustTask::work(uint worker_id) {
    Ticks start = Ticks::now();
    ResourceMark rm;
  
    // Adjust preserved marks first since they are not balanced.
    G1FullGCMarker* marker = collector()->marker(worker_id);
    marker->preserved_stack()->adjust_during_full_gc();
  
    {
      // Adjust the weak roots.
      AlwaysTrueClosure always_alive;
!     _weak_proc_task.work(worker_id, &always_alive, &_adjust);
    }
  
!   CLDToOopClosure adjust_cld(&_adjust, ClassLoaderData::_claim_stw_fullgc_adjust);
!   CodeBlobToOopClosure adjust_code(&_adjust, CodeBlobToOopClosure::FixRelocations);
!   _root_processor.process_all_roots(&_adjust, &adjust_cld, &adjust_code);
  
    // Now adjust pointers region by region
    G1AdjustRegionClosure blk(collector(), worker_id);
    G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
    log_task("Adjust task", worker_id, start);
  }
--- 61,71 ---
      _collector(collector),
      _bitmap(collector->mark_bitmap()),
      _worker_id(worker_id) { }
  
    bool do_heap_region(HeapRegion* r) {
!     if (UseAltGCForwarding) {
+       return do_heap_region_impl<true>(r);
+     } else {
+       return do_heap_region_impl<false>(r);
+     }
+   }
+ 
+ private:
+   template <bool ALT_FWD>
+   bool do_heap_region_impl(HeapRegion* r) {
+     G1AdjustClosure<ALT_FWD> cl(_collector);
      if (r->is_humongous()) {
        // Special handling for humongous regions to get somewhat better
        // work distribution.
        oop obj = cast_to_oop(r->humongous_start_region()->bottom());
        obj->oop_iterate(&cl, MemRegion(r->bottom(), r->top()));
      } else if (!r->is_free()) {
        // Free regions do not contain objects to iterate. So skip them.
!       G1AdjustLiveClosure<ALT_FWD> adjust(&cl);
        r->apply_to_marked_objects(_bitmap, &adjust);
      }
      return false;
    }
  };
  
  G1FullGCAdjustTask::G1FullGCAdjustTask(G1FullCollector* collector) :
      G1FullGCTask("G1 Adjust", collector),
      _root_processor(G1CollectedHeap::heap(), collector->workers()),
      _weak_proc_task(collector->workers()),
!     _hrclaimer(collector->workers()) {
    ClassLoaderDataGraph::verify_claimed_marks_cleared(ClassLoaderData::_claim_stw_fullgc_adjust);
  }
  
! template <bool ALT_FWD>
+ void G1FullGCAdjustTask::work_impl(uint worker_id) {
    Ticks start = Ticks::now();
    ResourceMark rm;
  
    // Adjust preserved marks first since they are not balanced.
    G1FullGCMarker* marker = collector()->marker(worker_id);
    marker->preserved_stack()->adjust_during_full_gc();
  
+   G1AdjustClosure<ALT_FWD> adjust(collector());
    {
      // Adjust the weak roots.
      AlwaysTrueClosure always_alive;
!     _weak_proc_task.work(worker_id, &always_alive, &adjust);
    }
  
!   CLDToOopClosure adjust_cld(&adjust, ClassLoaderData::_claim_stw_fullgc_adjust);
!   CodeBlobToOopClosure adjust_code(&adjust, CodeBlobToOopClosure::FixRelocations);
!   _root_processor.process_all_roots(&adjust, &adjust_cld, &adjust_code);
  
    // Now adjust pointers region by region
    G1AdjustRegionClosure blk(collector(), worker_id);
    G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
    log_task("Adjust task", worker_id, start);
  }
+ 
+ void G1FullGCAdjustTask::work(uint worker_id) {
+   if (UseAltGCForwarding) {
+     work_impl<true>(worker_id);
+   } else {
+     work_impl<false>(worker_id);
+   }
+ }
< prev index next >