< prev index next >

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

Print this page

 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/classLoaderDataGraph.hpp"
 27 #include "gc/g1/g1CollectedHeap.hpp"
 28 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 29 #include "gc/g1/g1FullCollector.inline.hpp"
 30 #include "gc/g1/g1FullGCAdjustTask.hpp"
 31 #include "gc/g1/g1FullGCCompactionPoint.hpp"
 32 #include "gc/g1/g1FullGCMarker.hpp"
 33 #include "gc/g1/g1FullGCOopClosures.inline.hpp"
 34 #include "gc/g1/heapRegion.inline.hpp"
 35 #include "gc/shared/gcTraceTime.inline.hpp"
 36 #include "gc/shared/referenceProcessor.hpp"
 37 #include "gc/shared/weakProcessor.inline.hpp"
 38 #include "logging/log.hpp"
 39 #include "memory/iterator.inline.hpp"
 40 #include "runtime/atomic.hpp"
 41 

 42 class G1AdjustLiveClosure : public StackObj {
 43   G1AdjustClosure* _adjust_closure;
 44 public:
 45   G1AdjustLiveClosure(G1AdjustClosure* cl) :
 46     _adjust_closure(cl) { }
 47 
 48   size_t apply(oop object) {
 49     return object->oop_iterate_size(_adjust_closure);
 50   }
 51 };
 52 
 53 class G1AdjustRegionClosure : public HeapRegionClosure {
 54   G1FullCollector* _collector;
 55   G1CMBitMap* _bitmap;
 56   uint _worker_id;
 57  public:
 58   G1AdjustRegionClosure(G1FullCollector* collector, uint worker_id) :
 59     _collector(collector),
 60     _bitmap(collector->mark_bitmap()),
 61     _worker_id(worker_id) { }
 62 
 63   bool do_heap_region(HeapRegion* r) {
 64     G1AdjustClosure cl(_collector);










 65     if (r->is_humongous()) {
 66       // Special handling for humongous regions to get somewhat better
 67       // work distribution.
 68       oop obj = cast_to_oop(r->humongous_start_region()->bottom());
 69       obj->oop_iterate(&cl, MemRegion(r->bottom(), r->top()));
 70     } else if (!r->is_closed_archive() && !r->is_free()) {
 71       // Closed archive regions never change references and only contain
 72       // references into other closed regions and are always live. Free
 73       // regions do not contain objects to iterate. So skip both.
 74       G1AdjustLiveClosure adjust(&cl);
 75       r->apply_to_marked_objects(_bitmap, &adjust);
 76     }
 77     return false;
 78   }
 79 };
 80 
 81 G1FullGCAdjustTask::G1FullGCAdjustTask(G1FullCollector* collector) :
 82     G1FullGCTask("G1 Adjust", collector),
 83     _root_processor(G1CollectedHeap::heap(), collector->workers()),
 84     _references_done(false),
 85     _weak_proc_task(collector->workers()),
 86     _hrclaimer(collector->workers()),
 87     _adjust(collector) {
 88   // Need cleared claim bits for the roots processing
 89   ClassLoaderDataGraph::clear_claimed_marks();
 90 }
 91 
 92 void G1FullGCAdjustTask::work(uint worker_id) {

 93   Ticks start = Ticks::now();
 94   ResourceMark rm;
 95 
 96   // Adjust preserved marks first since they are not balanced.
 97   G1FullGCMarker* marker = collector()->marker(worker_id);
 98   marker->preserved_stack()->adjust_during_full_gc();
 99 

100   // Adjust the weak roots.
101   if (!Atomic::cmpxchg(&_references_done, false, true)) {
102     G1CollectedHeap::heap()->ref_processor_stw()->weak_oops_do(&_adjust);
103   }
104 
105   AlwaysTrueClosure always_alive;
106   _weak_proc_task.work(worker_id, &always_alive, &_adjust);
107 
108   CLDToOopClosure adjust_cld(&_adjust, ClassLoaderData::_claim_strong);
109   CodeBlobToOopClosure adjust_code(&_adjust, CodeBlobToOopClosure::FixRelocations);
110   _root_processor.process_all_roots(&_adjust, &adjust_cld, &adjust_code);
111 
112   // Now adjust pointers region by region
113   G1AdjustRegionClosure blk(collector(), worker_id);
114   G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
115   log_task("Adjust task", worker_id, start);
116 }









 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/classLoaderDataGraph.hpp"
 27 #include "gc/g1/g1CollectedHeap.hpp"
 28 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 29 #include "gc/g1/g1FullCollector.inline.hpp"
 30 #include "gc/g1/g1FullGCAdjustTask.hpp"
 31 #include "gc/g1/g1FullGCCompactionPoint.hpp"
 32 #include "gc/g1/g1FullGCMarker.hpp"
 33 #include "gc/g1/g1FullGCOopClosures.inline.hpp"
 34 #include "gc/g1/heapRegion.inline.hpp"
 35 #include "gc/shared/gcTraceTime.inline.hpp"
 36 #include "gc/shared/referenceProcessor.hpp"
 37 #include "gc/shared/weakProcessor.inline.hpp"
 38 #include "logging/log.hpp"
 39 #include "memory/iterator.inline.hpp"
 40 #include "runtime/atomic.hpp"
 41 
 42 template <bool ALT_FWD>
 43 class G1AdjustLiveClosure : public StackObj {
 44   G1AdjustClosure<ALT_FWD>* _adjust_closure;
 45 public:
 46   G1AdjustLiveClosure(G1AdjustClosure<ALT_FWD>* cl) :
 47     _adjust_closure(cl) { }
 48 
 49   size_t apply(oop object) {
 50     return object->oop_iterate_size(_adjust_closure);
 51   }
 52 };
 53 
 54 class G1AdjustRegionClosure : public HeapRegionClosure {
 55   G1FullCollector* _collector;
 56   G1CMBitMap* _bitmap;
 57   uint _worker_id;
 58  public:
 59   G1AdjustRegionClosure(G1FullCollector* collector, uint worker_id) :
 60     _collector(collector),
 61     _bitmap(collector->mark_bitmap()),
 62     _worker_id(worker_id) { }
 63 
 64   bool do_heap_region(HeapRegion* r) {
 65     if (UseAltGCForwarding) {
 66       return do_heap_region_impl<true>(r);
 67     } else {
 68       return do_heap_region_impl<false>(r);
 69     }
 70   }
 71 
 72  private:
 73   template <bool ALT_FWD>
 74   bool do_heap_region_impl(HeapRegion* r) {
 75     G1AdjustClosure<ALT_FWD> cl(_collector);
 76     if (r->is_humongous()) {
 77       // Special handling for humongous regions to get somewhat better
 78       // work distribution.
 79       oop obj = cast_to_oop(r->humongous_start_region()->bottom());
 80       obj->oop_iterate(&cl, MemRegion(r->bottom(), r->top()));
 81     } else if (!r->is_closed_archive() && !r->is_free()) {
 82       // Closed archive regions never change references and only contain
 83       // references into other closed regions and are always live. Free
 84       // regions do not contain objects to iterate. So skip both.
 85       G1AdjustLiveClosure<ALT_FWD> adjust(&cl);
 86       r->apply_to_marked_objects(_bitmap, &adjust);
 87     }
 88     return false;
 89   }
 90 };
 91 
 92 G1FullGCAdjustTask::G1FullGCAdjustTask(G1FullCollector* collector) :
 93     G1FullGCTask("G1 Adjust", collector),
 94     _root_processor(G1CollectedHeap::heap(), collector->workers()),
 95     _references_done(false),
 96     _weak_proc_task(collector->workers()),
 97     _hrclaimer(collector->workers()) {

 98   // Need cleared claim bits for the roots processing
 99   ClassLoaderDataGraph::clear_claimed_marks();
100 }
101 
102 template <bool ALT_FWD>
103 void G1FullGCAdjustTask::work_impl(uint worker_id) {
104   Ticks start = Ticks::now();
105   ResourceMark rm;
106 
107   // Adjust preserved marks first since they are not balanced.
108   G1FullGCMarker* marker = collector()->marker(worker_id);
109   marker->preserved_stack()->adjust_during_full_gc();
110 
111   G1AdjustClosure<ALT_FWD> adjust(collector());
112   // Adjust the weak roots.
113   if (!Atomic::cmpxchg(&_references_done, false, true)) {
114     G1CollectedHeap::heap()->ref_processor_stw()->weak_oops_do(&adjust);
115   }
116 
117   AlwaysTrueClosure always_alive;
118   _weak_proc_task.work(worker_id, &always_alive, &adjust);
119 
120   CLDToOopClosure adjust_cld(&adjust, ClassLoaderData::_claim_strong);
121   CodeBlobToOopClosure adjust_code(&adjust, CodeBlobToOopClosure::FixRelocations);
122   _root_processor.process_all_roots(&adjust, &adjust_cld, &adjust_code);
123 
124   // Now adjust pointers region by region
125   G1AdjustRegionClosure blk(collector(), worker_id);
126   G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&blk, &_hrclaimer, worker_id);
127   log_task("Adjust task", worker_id, start);
128 }
129 
130 void G1FullGCAdjustTask::work(uint worker_id) {
131   if (UseAltGCForwarding) {
132     work_impl<true>(worker_id);
133   } else {
134     work_impl<false>(worker_id);
135   }
136 }
< prev index next >