98 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); |
98 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); |
99 COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); |
99 COMPILER2_PRESENT(DerivedPointerTable::set_active(false)); |
100 |
100 |
101 mark_sweep_phase3(level); |
101 mark_sweep_phase3(level); |
102 |
102 |
103 VALIDATE_MARK_SWEEP_ONLY( |
|
104 if (ValidateMarkSweep) { |
|
105 guarantee(_root_refs_stack->length() == 0, "should be empty by now"); |
|
106 } |
|
107 ) |
|
108 |
|
109 mark_sweep_phase4(); |
103 mark_sweep_phase4(); |
110 |
|
111 VALIDATE_MARK_SWEEP_ONLY( |
|
112 if (ValidateMarkSweep) { |
|
113 guarantee(_live_oops->length() == _live_oops_moved_to->length(), |
|
114 "should be the same size"); |
|
115 } |
|
116 ) |
|
117 |
104 |
118 restore_marks(); |
105 restore_marks(); |
119 |
106 |
120 // Set saved marks for allocation profiler (and other things? -- dld) |
107 // Set saved marks for allocation profiler (and other things? -- dld) |
121 // (Should this be in general part?) |
108 // (Should this be in general part?) |
185 _preserved_count_max = 0; |
172 _preserved_count_max = 0; |
186 } |
173 } |
187 |
174 |
188 _preserved_marks = (PreservedMark*)scratch; |
175 _preserved_marks = (PreservedMark*)scratch; |
189 _preserved_count = 0; |
176 _preserved_count = 0; |
190 |
|
191 #ifdef VALIDATE_MARK_SWEEP |
|
192 if (ValidateMarkSweep) { |
|
193 _root_refs_stack = new (ResourceObj::C_HEAP, mtGC) GrowableArray<void*>(100, true); |
|
194 _other_refs_stack = new (ResourceObj::C_HEAP, mtGC) GrowableArray<void*>(100, true); |
|
195 _adjusted_pointers = new (ResourceObj::C_HEAP, mtGC) GrowableArray<void*>(100, true); |
|
196 _live_oops = new (ResourceObj::C_HEAP, mtGC) GrowableArray<oop>(100, true); |
|
197 _live_oops_moved_to = new (ResourceObj::C_HEAP, mtGC) GrowableArray<oop>(100, true); |
|
198 _live_oops_size = new (ResourceObj::C_HEAP, mtGC) GrowableArray<size_t>(100, true); |
|
199 } |
|
200 if (RecordMarkSweepCompaction) { |
|
201 if (_cur_gc_live_oops == NULL) { |
|
202 _cur_gc_live_oops = new(ResourceObj::C_HEAP, mtGC) GrowableArray<HeapWord*>(100, true); |
|
203 _cur_gc_live_oops_moved_to = new(ResourceObj::C_HEAP, mtGC) GrowableArray<HeapWord*>(100, true); |
|
204 _cur_gc_live_oops_size = new(ResourceObj::C_HEAP, mtGC) GrowableArray<size_t>(100, true); |
|
205 _last_gc_live_oops = new(ResourceObj::C_HEAP, mtGC) GrowableArray<HeapWord*>(100, true); |
|
206 _last_gc_live_oops_moved_to = new(ResourceObj::C_HEAP, mtGC) GrowableArray<HeapWord*>(100, true); |
|
207 _last_gc_live_oops_size = new(ResourceObj::C_HEAP, mtGC) GrowableArray<size_t>(100, true); |
|
208 } else { |
|
209 _cur_gc_live_oops->clear(); |
|
210 _cur_gc_live_oops_moved_to->clear(); |
|
211 _cur_gc_live_oops_size->clear(); |
|
212 } |
|
213 } |
|
214 #endif |
|
215 } |
177 } |
216 |
178 |
217 |
179 |
218 void GenMarkSweep::deallocate_stacks() { |
180 void GenMarkSweep::deallocate_stacks() { |
219 if (!UseG1GC) { |
181 if (!UseG1GC) { |
223 |
185 |
224 _preserved_mark_stack.clear(true); |
186 _preserved_mark_stack.clear(true); |
225 _preserved_oop_stack.clear(true); |
187 _preserved_oop_stack.clear(true); |
226 _marking_stack.clear(); |
188 _marking_stack.clear(); |
227 _objarray_stack.clear(true); |
189 _objarray_stack.clear(true); |
228 |
|
229 #ifdef VALIDATE_MARK_SWEEP |
|
230 if (ValidateMarkSweep) { |
|
231 delete _root_refs_stack; |
|
232 delete _other_refs_stack; |
|
233 delete _adjusted_pointers; |
|
234 delete _live_oops; |
|
235 delete _live_oops_size; |
|
236 delete _live_oops_moved_to; |
|
237 _live_oops_index = 0; |
|
238 _live_oops_index_at_perm = 0; |
|
239 } |
|
240 #endif |
|
241 } |
190 } |
242 |
191 |
243 void GenMarkSweep::mark_sweep_phase1(int level, |
192 void GenMarkSweep::mark_sweep_phase1(int level, |
244 bool clear_all_softrefs) { |
193 bool clear_all_softrefs) { |
245 // Recursively traverse all live objects and mark them |
194 // Recursively traverse all live objects and mark them |
246 TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty); |
195 TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty); |
247 trace(" 1"); |
196 trace(" 1"); |
248 |
|
249 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking()); |
|
250 |
197 |
251 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
198 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
252 |
199 |
253 // Because follow_root_closure is created statically, cannot |
200 // Because follow_root_closure is created statically, cannot |
254 // use OopsInGenClosure constructor which takes a generation, |
201 // use OopsInGenClosure constructor which takes a generation, |
313 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
260 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
314 |
261 |
315 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty); |
262 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty); |
316 trace("2"); |
263 trace("2"); |
317 |
264 |
318 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking()); |
|
319 |
|
320 gch->prepare_for_compaction(); |
265 gch->prepare_for_compaction(); |
321 } |
266 } |
322 |
267 |
323 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure { |
268 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure { |
324 public: |
269 public: |
334 TraceTime tm("phase 3", PrintGC && Verbose, true, gclog_or_tty); |
279 TraceTime tm("phase 3", PrintGC && Verbose, true, gclog_or_tty); |
335 trace("3"); |
280 trace("3"); |
336 |
281 |
337 // Need new claim bits for the pointer adjustment tracing. |
282 // Need new claim bits for the pointer adjustment tracing. |
338 ClassLoaderDataGraph::clear_claimed_marks(); |
283 ClassLoaderDataGraph::clear_claimed_marks(); |
339 |
|
340 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking()); |
|
341 |
284 |
342 // Because the two closures below are created statically, cannot |
285 // Because the two closures below are created statically, cannot |
343 // use OopsInGenClosure constructor which takes a generation, |
286 // use OopsInGenClosure constructor which takes a generation, |
344 // as the Universe has not been created when the static constructors |
287 // as the Universe has not been created when the static constructors |
345 // are run. |
288 // are run. |
391 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
334 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
392 |
335 |
393 TraceTime tm("phase 4", PrintGC && Verbose, true, gclog_or_tty); |
336 TraceTime tm("phase 4", PrintGC && Verbose, true, gclog_or_tty); |
394 trace("4"); |
337 trace("4"); |
395 |
338 |
396 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking()); |
|
397 |
|
398 GenCompactClosure blk; |
339 GenCompactClosure blk; |
399 gch->generation_iterate(&blk, true); |
340 gch->generation_iterate(&blk, true); |
400 |
341 } |
401 VALIDATE_MARK_SWEEP_ONLY(compaction_complete()); |
|
402 } |
|