comparison src/share/vm/gc/g1/g1EvacFailure.cpp @ 8677:9690cc21ec74

8129558: Coalesce dead objects during removal of self-forwarded pointers Summary: To improve performance of self-forwarding fixup during evacuation failure, coalesce the work done for dead objects. Reviewed-by: mgerdin, tbenson, tonyp
author tschatzl
date Tue, 07 Jul 2015 14:20:08 +0200
parents 46850a050b8b
children dc9930a04ab0
comparison
equal deleted inserted replaced
2:dd97c0d87789 3:34efff129845
38 G1CollectedHeap* _g1; 38 G1CollectedHeap* _g1;
39 DirtyCardQueue *_dcq; 39 DirtyCardQueue *_dcq;
40 G1SATBCardTableModRefBS* _ct_bs; 40 G1SATBCardTableModRefBS* _ct_bs;
41 41
42 public: 42 public:
43 UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) : 43 UpdateRSetDeferred(DirtyCardQueue* dcq) :
44 _g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {} 44 _g1(G1CollectedHeap::heap()), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}
45 45
46 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 46 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
47 virtual void do_oop( oop* p) { do_oop_work(p); } 47 virtual void do_oop( oop* p) { do_oop_work(p); }
48 template <class T> void do_oop_work(T* p) { 48 template <class T> void do_oop_work(T* p) {
49 assert(_from->is_in_reserved(p), "paranoia"); 49 assert(_from->is_in_reserved(p), "paranoia");
63 ConcurrentMark* _cm; 63 ConcurrentMark* _cm;
64 HeapRegion* _hr; 64 HeapRegion* _hr;
65 size_t _marked_bytes; 65 size_t _marked_bytes;
66 OopsInHeapRegionClosure *_update_rset_cl; 66 OopsInHeapRegionClosure *_update_rset_cl;
67 bool _during_initial_mark; 67 bool _during_initial_mark;
68 bool _during_conc_mark;
69 uint _worker_id; 68 uint _worker_id;
70 HeapWord* _end_of_last_gap; 69 HeapWord* _last_forwarded_object_end;
71 HeapWord* _last_gap_threshold;
72 HeapWord* _last_obj_threshold;
73 70
74 public: 71 public:
75 RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm, 72 RemoveSelfForwardPtrObjClosure(HeapRegion* hr,
76 HeapRegion* hr,
77 OopsInHeapRegionClosure* update_rset_cl, 73 OopsInHeapRegionClosure* update_rset_cl,
78 bool during_initial_mark, 74 bool during_initial_mark,
79 bool during_conc_mark,
80 uint worker_id) : 75 uint worker_id) :
81 _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0), 76 _g1(G1CollectedHeap::heap()),
77 _cm(_g1->concurrent_mark()),
78 _hr(hr),
79 _marked_bytes(0),
82 _update_rset_cl(update_rset_cl), 80 _update_rset_cl(update_rset_cl),
83 _during_initial_mark(during_initial_mark), 81 _during_initial_mark(during_initial_mark),
84 _during_conc_mark(during_conc_mark),
85 _worker_id(worker_id), 82 _worker_id(worker_id),
86 _end_of_last_gap(hr->bottom()), 83 _last_forwarded_object_end(hr->bottom()) { }
87 _last_gap_threshold(hr->bottom()),
88 _last_obj_threshold(hr->bottom()) { }
89 84
90 size_t marked_bytes() { return _marked_bytes; } 85 size_t marked_bytes() { return _marked_bytes; }
91 86
92 // <original comment> 87 // Iterate over the live objects in the region to find self-forwarded objects
93 // The original idea here was to coalesce evacuated and dead objects. 88 // that need to be kept live. We need to update the remembered sets of these
94 // However that caused complications with the block offset table (BOT). 89 // objects. Further update the BOT and marks.
95 // In particular if there were two TLABs, one of them partially refined. 90 // We can coalesce and overwrite the remaining heap contents with dummy objects
96 // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~| 91 // as they have either been dead or evacuated (which are unreferenced now, i.e.
97 // The BOT entries of the unrefined part of TLAB_2 point to the start 92 // dead too) already.
98 // of TLAB_2. If the last object of the TLAB_1 and the first object
99 // of TLAB_2 are coalesced, then the cards of the unrefined part
100 // would point into middle of the filler object.
101 // The current approach is to not coalesce and leave the BOT contents intact.
102 // </original comment>
103 //
104 // We now reset the BOT when we start the object iteration over the
105 // region and refine its entries for every object we come across. So
106 // the above comment is not really relevant and we should be able
107 // to coalesce dead objects if we want to.
108 void do_object(oop obj) { 93 void do_object(oop obj) {
109 HeapWord* obj_addr = (HeapWord*) obj; 94 HeapWord* obj_addr = (HeapWord*) obj;
110 assert(_hr->is_in(obj_addr), "sanity"); 95 assert(_hr->is_in(obj_addr), "sanity");
111 size_t obj_size = obj->size(); 96 size_t obj_size = obj->size();
112 HeapWord* obj_end = obj_addr + obj_size; 97 HeapWord* obj_end = obj_addr + obj_size;
113 98
114 if (_end_of_last_gap != obj_addr) {
115 // there was a gap before obj_addr
116 _last_gap_threshold = _hr->cross_threshold(_end_of_last_gap, obj_addr);
117 }
118
119 if (obj->is_forwarded() && obj->forwardee() == obj) { 99 if (obj->is_forwarded() && obj->forwardee() == obj) {
120 // The object failed to move. 100 // The object failed to move.
121 101
102 zap_dead_objects(_last_forwarded_object_end, obj_addr);
122 // We consider all objects that we find self-forwarded to be 103 // We consider all objects that we find self-forwarded to be
123 // live. What we'll do is that we'll update the prev marking 104 // live. What we'll do is that we'll update the prev marking
124 // info so that they are all under PTAMS and explicitly marked. 105 // info so that they are all under PTAMS and explicitly marked.
125 if (!_cm->isPrevMarked(obj)) { 106 if (!_cm->isPrevMarked(obj)) {
126 _cm->markPrev(obj); 107 _cm->markPrev(obj);
152 // across an array that was being chunked and looking malformed. 133 // across an array that was being chunked and looking malformed.
153 // The problem is that, if evacuation fails, we might have 134 // The problem is that, if evacuation fails, we might have
154 // remembered set entries missing given that we skipped cards on 135 // remembered set entries missing given that we skipped cards on
155 // the collection set. So, we'll recreate such entries now. 136 // the collection set. So, we'll recreate such entries now.
156 obj->oop_iterate(_update_rset_cl); 137 obj->oop_iterate(_update_rset_cl);
157 } else { 138
158 139 _last_forwarded_object_end = obj_end;
159 // The object has been either evacuated or is dead. Fill it with a 140 _hr->cross_threshold(obj_addr, obj_end);
160 // dummy object. 141 }
161 MemRegion mr(obj_addr, obj_size); 142 }
162 CollectedHeap::fill_with_object(mr); 143
163 144 // Fill the memory area from start to end with filler objects, and update the BOT
164 // must nuke all dead objects which we skipped when iterating over the region 145 // and the mark bitmap accordingly.
165 _cm->clearRangePrevBitmap(MemRegion(_end_of_last_gap, obj_end)); 146 void zap_dead_objects(HeapWord* start, HeapWord* end) {
166 } 147 if (start == end) {
167 _end_of_last_gap = obj_end; 148 return;
168 _last_obj_threshold = _hr->cross_threshold(obj_addr, obj_end); 149 }
150
151 size_t gap_size = pointer_delta(end, start);
152 MemRegion mr(start, gap_size);
153 if (gap_size >= CollectedHeap::min_fill_size()) {
154 CollectedHeap::fill_with_objects(start, gap_size);
155
156 HeapWord* end_first_obj = start + ((oop)start)->size();
157 _hr->cross_threshold(start, end_first_obj);
158 // Fill_with_objects() may have created multiple (i.e. two)
159 // objects, as the max_fill_size() is half a region.
160 // After updating the BOT for the first object, also update the
161 // BOT for the second object to make the BOT complete.
162 if (end_first_obj != end) {
163 _hr->cross_threshold(end_first_obj, end);
164 #ifdef ASSERT
165 size_t size_second_obj = ((oop)end_first_obj)->size();
166 HeapWord* end_of_second_obj = end_first_obj + size_second_obj;
167 assert(end == end_of_second_obj,
168 err_msg("More than two objects were used to fill the area from " PTR_FORMAT " to " PTR_FORMAT ", "
169 "second objects size " SIZE_FORMAT " ends at " PTR_FORMAT,
170 p2i(start), p2i(end), size_second_obj, p2i(end_of_second_obj)));
171 #endif
172 }
173 }
174 _cm->clearRangePrevBitmap(mr);
175 }
176
177 void zap_remainder() {
178 zap_dead_objects(_last_forwarded_object_end, _hr->top());
169 } 179 }
170 }; 180 };
171 181
172 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure { 182 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
173 G1CollectedHeap* _g1h; 183 G1CollectedHeap* _g1h;
174 ConcurrentMark* _cm;
175 uint _worker_id; 184 uint _worker_id;
176 HeapRegionClaimer* _hrclaimer; 185 HeapRegionClaimer* _hrclaimer;
177 186
178 DirtyCardQueue _dcq; 187 DirtyCardQueue _dcq;
179 UpdateRSetDeferred _update_rset_cl; 188 UpdateRSetDeferred _update_rset_cl;
180 189
181 public: 190 public:
182 RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h, 191 RemoveSelfForwardPtrHRClosure(uint worker_id,
183 uint worker_id,
184 HeapRegionClaimer* hrclaimer) : 192 HeapRegionClaimer* hrclaimer) :
185 _g1h(g1h), _dcq(&g1h->dirty_card_queue_set()), _update_rset_cl(g1h, &_dcq), 193 _g1h(G1CollectedHeap::heap()),
186 _worker_id(worker_id), _cm(_g1h->concurrent_mark()), _hrclaimer(hrclaimer) { 194 _dcq(&_g1h->dirty_card_queue_set()),
195 _update_rset_cl(&_dcq),
196 _worker_id(worker_id),
197 _hrclaimer(hrclaimer) {
198 }
199
200 size_t remove_self_forward_ptr_by_walking_hr(HeapRegion* hr,
201 bool during_initial_mark) {
202 RemoveSelfForwardPtrObjClosure rspc(hr,
203 &_update_rset_cl,
204 during_initial_mark,
205 _worker_id);
206 _update_rset_cl.set_region(hr);
207 hr->object_iterate(&rspc);
208 // Need to zap the remainder area of the processed region.
209 rspc.zap_remainder();
210
211 return rspc.marked_bytes();
187 } 212 }
188 213
189 bool doHeapRegion(HeapRegion *hr) { 214 bool doHeapRegion(HeapRegion *hr) {
190 bool during_initial_mark = _g1h->collector_state()->during_initial_mark_pause(); 215 bool during_initial_mark = _g1h->collector_state()->during_initial_mark_pause();
191 bool during_conc_mark = _g1h->collector_state()->mark_in_progress(); 216 bool during_conc_mark = _g1h->collector_state()->mark_in_progress();
193 assert(!hr->is_pinned(), err_msg("Unexpected pinned region at index %u", hr->hrm_index())); 218 assert(!hr->is_pinned(), err_msg("Unexpected pinned region at index %u", hr->hrm_index()));
194 assert(hr->in_collection_set(), "bad CS"); 219 assert(hr->in_collection_set(), "bad CS");
195 220
196 if (_hrclaimer->claim_region(hr->hrm_index())) { 221 if (_hrclaimer->claim_region(hr->hrm_index())) {
197 if (hr->evacuation_failed()) { 222 if (hr->evacuation_failed()) {
198 RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, &_update_rset_cl,
199 during_initial_mark,
200 during_conc_mark,
201 _worker_id);
202
203 hr->note_self_forwarding_removal_start(during_initial_mark, 223 hr->note_self_forwarding_removal_start(during_initial_mark,
204 during_conc_mark); 224 during_conc_mark);
205 _g1h->check_bitmaps("Self-Forwarding Ptr Removal", hr); 225 _g1h->check_bitmaps("Self-Forwarding Ptr Removal", hr);
206 226
207 // In the common case (i.e. when there is no evacuation 227 // In the common case (i.e. when there is no evacuation
212 // to a CSet in the future. So we have to be careful here and 232 // to a CSet in the future. So we have to be careful here and
213 // make sure the region's RSet is ready for parallel iteration 233 // make sure the region's RSet is ready for parallel iteration
214 // whenever this might be required in the future. 234 // whenever this might be required in the future.
215 hr->rem_set()->reset_for_par_iteration(); 235 hr->rem_set()->reset_for_par_iteration();
216 hr->reset_bot(); 236 hr->reset_bot();
217 _update_rset_cl.set_region(hr); 237
218 hr->object_iterate(&rspc); 238 size_t live_bytes = remove_self_forward_ptr_by_walking_hr(hr, during_initial_mark);
219 239
220 hr->rem_set()->clean_strong_code_roots(hr); 240 hr->rem_set()->clean_strong_code_roots(hr);
221 241
222 hr->note_self_forwarding_removal_end(during_initial_mark, 242 hr->note_self_forwarding_removal_end(during_initial_mark,
223 during_conc_mark, 243 during_conc_mark,
224 rspc.marked_bytes()); 244 live_bytes);
225 } 245 }
226 } 246 }
227 return false; 247 return false;
228 } 248 }
229 }; 249 };
230 250
231 G1ParRemoveSelfForwardPtrsTask::G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) : 251 G1ParRemoveSelfForwardPtrsTask::G1ParRemoveSelfForwardPtrsTask() :
232 AbstractGangTask("G1 Remove Self-forwarding Pointers"), _g1h(g1h), 252 AbstractGangTask("G1 Remove Self-forwarding Pointers"),
233 _hrclaimer(g1h->workers()->active_workers()) {} 253 _g1h(G1CollectedHeap::heap()),
254 _hrclaimer(_g1h->workers()->active_workers()) { }
234 255
235 void G1ParRemoveSelfForwardPtrsTask::work(uint worker_id) { 256 void G1ParRemoveSelfForwardPtrsTask::work(uint worker_id) {
236 RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, worker_id, &_hrclaimer); 257 RemoveSelfForwardPtrHRClosure rsfp_cl(worker_id, &_hrclaimer);
237 258
238 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id); 259 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
239 _g1h->collection_set_iterate_from(hr, &rsfp_cl); 260 _g1h->collection_set_iterate_from(hr, &rsfp_cl);
240 } 261 }