190 _objarray_stack.clear(true); 191 } 192 193 void GenMarkSweep::mark_sweep_phase1(int level, 194 bool clear_all_softrefs) { 195 // Recursively traverse all live objects and mark them 196 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 197 trace(" 1"); 198 199 GenCollectedHeap* gch = GenCollectedHeap::heap(); 200 201 // Because follow_root_closure is created statically, cannot 202 // use OopsInGenClosure constructor which takes a generation, 203 // as the Universe has not been created when the static constructors 204 // are run. 205 follow_root_closure.set_orig_generation(gch->get_gen(level)); 206 207 // Need new claim bits before marking starts. 208 ClassLoaderDataGraph::clear_claimed_marks(); 209 210 gch->gen_process_strong_roots(level, 211 false, // Younger gens are not roots. 212 true, // activate StrongRootsScope 213 SharedHeap::SO_SystemClasses, 214 &follow_root_closure, 215 &follow_root_closure, 216 &follow_klass_closure); 217 218 // Process reference objects found during marking 219 { 220 ref_processor()->setup_policy(clear_all_softrefs); 221 const ReferenceProcessorStats& stats = 222 ref_processor()->process_discovered_references( 223 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer, _gc_tracer->gc_id()); 224 gc_tracer()->report_gc_reference_stats(stats); 225 } 226 227 // This is the point where the entire marking should have completed. 228 assert(_marking_stack.is_empty(), "Marking should have completed"); 229 230 // Unload classes and purge the SystemDictionary. 231 bool purged_class = SystemDictionary::do_unloading(&is_alive); 232 233 // Unload nmethods. 234 CodeCache::do_unloading(&is_alive, purged_class); 235 236 // Prune dead klasses from subklass/sibling/implementor lists. 274 gen->adjust_pointers(); 275 } 276 }; 277 278 void GenMarkSweep::mark_sweep_phase3(int level) { 279 GenCollectedHeap* gch = GenCollectedHeap::heap(); 280 281 // Adjust the pointers to reflect the new locations 282 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 283 trace("3"); 284 285 // Need new claim bits for the pointer adjustment tracing. 286 ClassLoaderDataGraph::clear_claimed_marks(); 287 288 // Because the closure below is created statically, we cannot 289 // use OopsInGenClosure constructor which takes a generation, 290 // as the Universe has not been created when the static constructors 291 // are run. 292 adjust_pointer_closure.set_orig_generation(gch->get_gen(level)); 293 294 gch->gen_process_strong_roots(level, 295 false, // Younger gens are not roots. 296 true, // activate StrongRootsScope 297 SharedHeap::SO_AllClasses | SharedHeap::SO_Strings | SharedHeap::SO_AllCodeCache, 298 &adjust_pointer_closure, 299 &adjust_pointer_closure, 300 &adjust_klass_closure); 301 302 gch->gen_process_weak_roots(&adjust_pointer_closure); 303 304 adjust_marks(); 305 GenAdjustPointersClosure blk; 306 gch->generation_iterate(&blk, true); 307 } 308 309 class GenCompactClosure: public GenCollectedHeap::GenClosure { 310 public: 311 void do_generation(Generation* gen) { 312 gen->compact(); 313 } 314 }; 315 316 void GenMarkSweep::mark_sweep_phase4() { 317 // All pointers are now adjusted, move objects accordingly 318 319 // It is imperative that we traverse perm_gen first in phase4. All 320 // classes must be allocated earlier than their instances, and traversing | 190 _objarray_stack.clear(true); 191 } 192 193 void GenMarkSweep::mark_sweep_phase1(int level, 194 bool clear_all_softrefs) { 195 // Recursively traverse all live objects and mark them 196 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 197 trace(" 1"); 198 199 GenCollectedHeap* gch = GenCollectedHeap::heap(); 200 201 // Because follow_root_closure is created statically, cannot 202 // use OopsInGenClosure constructor which takes a generation, 203 // as the Universe has not been created when the static constructors 204 // are run. 205 follow_root_closure.set_orig_generation(gch->get_gen(level)); 206 207 // Need new claim bits before marking starts. 208 ClassLoaderDataGraph::clear_claimed_marks(); 209 210 gch->gen_process_roots(level, 211 false, // Younger gens are not roots. 212 true, // activate StrongRootsScope 213 SharedHeap::SO_None, 214 GenCollectedHeap::StrongRootsOnly, 215 &follow_root_closure, 216 &follow_root_closure, 217 &follow_cld_closure); 218 219 // Process reference objects found during marking 220 { 221 ref_processor()->setup_policy(clear_all_softrefs); 222 const ReferenceProcessorStats& stats = 223 ref_processor()->process_discovered_references( 224 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer, _gc_tracer->gc_id()); 225 gc_tracer()->report_gc_reference_stats(stats); 226 } 227 228 // This is the point where the entire marking should have completed. 229 assert(_marking_stack.is_empty(), "Marking should have completed"); 230 231 // Unload classes and purge the SystemDictionary. 232 bool purged_class = SystemDictionary::do_unloading(&is_alive); 233 234 // Unload nmethods. 235 CodeCache::do_unloading(&is_alive, purged_class); 236 237 // Prune dead klasses from subklass/sibling/implementor lists. 275 gen->adjust_pointers(); 276 } 277 }; 278 279 void GenMarkSweep::mark_sweep_phase3(int level) { 280 GenCollectedHeap* gch = GenCollectedHeap::heap(); 281 282 // Adjust the pointers to reflect the new locations 283 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id()); 284 trace("3"); 285 286 // Need new claim bits for the pointer adjustment tracing. 287 ClassLoaderDataGraph::clear_claimed_marks(); 288 289 // Because the closure below is created statically, we cannot 290 // use OopsInGenClosure constructor which takes a generation, 291 // as the Universe has not been created when the static constructors 292 // are run. 293 adjust_pointer_closure.set_orig_generation(gch->get_gen(level)); 294 295 gch->gen_process_roots(level, 296 false, // Younger gens are not roots. 297 true, // activate StrongRootsScope 298 SharedHeap::SO_AllCodeCache, 299 GenCollectedHeap::StrongAndWeakRoots, 300 &adjust_pointer_closure, 301 &adjust_pointer_closure, 302 &adjust_cld_closure); 303 304 gch->gen_process_weak_roots(&adjust_pointer_closure); 305 306 adjust_marks(); 307 GenAdjustPointersClosure blk; 308 gch->generation_iterate(&blk, true); 309 } 310 311 class GenCompactClosure: public GenCollectedHeap::GenClosure { 312 public: 313 void do_generation(Generation* gen) { 314 gen->compact(); 315 } 316 }; 317 318 void GenMarkSweep::mark_sweep_phase4() { 319 // All pointers are now adjusted, move objects accordingly 320 321 // It is imperative that we traverse perm_gen first in phase4. All 322 // classes must be allocated earlier than their instances, and traversing |