177 GenCollectedHeap* gch = GenCollectedHeap::heap(); 178 gch->release_scratch(); 179 } 180 181 _preserved_mark_stack.clear(true); 182 _preserved_oop_stack.clear(true); 183 _marking_stack.clear(); 184 _objarray_stack.clear(true); 185 } 186 187 void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { 188 // Recursively traverse all live objects and mark them 189 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer); 190 191 GenCollectedHeap* gch = GenCollectedHeap::heap(); 192 193 // Because follow_root_closure is created statically, cannot 194 // use OopsInGenClosure constructor which takes a generation, 195 // as the Universe has not been created when the static constructors 196 // are run. 197 follow_root_closure.set_orig_generation(gch->old_gen()); 198 199 // Need new claim bits before marking starts. 200 ClassLoaderDataGraph::clear_claimed_marks(); 201 202 { 203 StrongRootsScope srs(1); 204 205 gch->gen_process_roots(&srs, 206 GenCollectedHeap::OldGen, 207 false, // Younger gens are not roots. 208 GenCollectedHeap::SO_None, 209 ClassUnloading, 210 &follow_root_closure, 211 &follow_root_closure, 212 &follow_cld_closure); 213 } 214 215 // Process reference objects found during marking 216 { 217 ref_processor()->setup_policy(clear_all_softrefs); 218 const ReferenceProcessorStats& stats = 219 ref_processor()->process_discovered_references( 220 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer); 221 gc_tracer()->report_gc_reference_stats(stats); 222 } 223 224 // This is the point where the entire marking should have completed. 225 assert(_marking_stack.is_empty(), "Marking should have completed"); 226 227 // Unload classes and purge the SystemDictionary. 228 bool purged_class = SystemDictionary::do_unloading(&is_alive); 229 230 // Unload nmethods. 231 CodeCache::do_unloading(&is_alive, purged_class); 267 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure { 268 public: 269 void do_generation(Generation* gen) { 270 gen->adjust_pointers(); 271 } 272 }; 273 274 void GenMarkSweep::mark_sweep_phase3() { 275 GenCollectedHeap* gch = GenCollectedHeap::heap(); 276 277 // Adjust the pointers to reflect the new locations 278 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer); 279 280 // Need new claim bits for the pointer adjustment tracing. 281 ClassLoaderDataGraph::clear_claimed_marks(); 282 283 // Because the closure below is created statically, we cannot 284 // use OopsInGenClosure constructor which takes a generation, 285 // as the Universe has not been created when the static constructors 286 // are run. 287 adjust_pointer_closure.set_orig_generation(gch->old_gen()); 288 289 { 290 StrongRootsScope srs(1); 291 292 gch->gen_process_roots(&srs, 293 GenCollectedHeap::OldGen, 294 false, // Younger gens are not roots. 295 GenCollectedHeap::SO_AllCodeCache, 296 GenCollectedHeap::StrongAndWeakRoots, 297 &adjust_pointer_closure, 298 &adjust_pointer_closure, 299 &adjust_cld_closure); 300 } 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 | 177 GenCollectedHeap* gch = GenCollectedHeap::heap(); 178 gch->release_scratch(); 179 } 180 181 _preserved_mark_stack.clear(true); 182 _preserved_oop_stack.clear(true); 183 _marking_stack.clear(); 184 _objarray_stack.clear(true); 185 } 186 187 void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) { 188 // Recursively traverse all live objects and mark them 189 GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer); 190 191 GenCollectedHeap* gch = GenCollectedHeap::heap(); 192 193 // Because follow_root_closure is created statically, cannot 194 // use OopsInGenClosure constructor which takes a generation, 195 // as the Universe has not been created when the static constructors 196 // are run. 197 follow_root_closure.set_generation(gch->old_gen()); 198 199 // Need new claim bits before marking starts. 200 ClassLoaderDataGraph::clear_claimed_marks(); 201 202 { 203 StrongRootsScope srs(1); 204 205 gch->old_process_roots(&srs, 206 false, // Younger gens are not roots. 207 GenCollectedHeap::SO_None, 208 ClassUnloading, 209 &follow_root_closure, 210 &follow_cld_closure); 211 } 212 213 // Process reference objects found during marking 214 { 215 ref_processor()->setup_policy(clear_all_softrefs); 216 const ReferenceProcessorStats& stats = 217 ref_processor()->process_discovered_references( 218 &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer); 219 gc_tracer()->report_gc_reference_stats(stats); 220 } 221 222 // This is the point where the entire marking should have completed. 223 assert(_marking_stack.is_empty(), "Marking should have completed"); 224 225 // Unload classes and purge the SystemDictionary. 226 bool purged_class = SystemDictionary::do_unloading(&is_alive); 227 228 // Unload nmethods. 229 CodeCache::do_unloading(&is_alive, purged_class); 265 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure { 266 public: 267 void do_generation(Generation* gen) { 268 gen->adjust_pointers(); 269 } 270 }; 271 272 void GenMarkSweep::mark_sweep_phase3() { 273 GenCollectedHeap* gch = GenCollectedHeap::heap(); 274 275 // Adjust the pointers to reflect the new locations 276 GCTraceTime tm("phase 3", PrintGC && Verbose, true, _gc_timer); 277 278 // Need new claim bits for the pointer adjustment tracing. 279 ClassLoaderDataGraph::clear_claimed_marks(); 280 281 // Because the closure below is created statically, we cannot 282 // use OopsInGenClosure constructor which takes a generation, 283 // as the Universe has not been created when the static constructors 284 // are run. 285 adjust_pointer_closure.set_generation(gch->old_gen()); 286 287 { 288 StrongRootsScope srs(1); 289 290 gch->old_process_roots(&srs, 291 false, // Younger gens are not roots. 292 GenCollectedHeap::SO_AllCodeCache, 293 false, // Strong and weak roots. 294 &adjust_pointer_closure, 295 &adjust_cld_closure); 296 } 297 298 gch->gen_process_weak_roots(&adjust_pointer_closure); 299 300 adjust_marks(); 301 GenAdjustPointersClosure blk; 302 gch->generation_iterate(&blk, true); 303 } 304 305 class GenCompactClosure: public GenCollectedHeap::GenClosure { 306 public: 307 void do_generation(Generation* gen) { 308 gen->compact(); 309 } 310 }; 311 312 void GenMarkSweep::mark_sweep_phase4() { 313 // All pointers are now adjusted, move objects accordingly |