< prev index next >

src/share/vm/gc/serial/genMarkSweep.cpp

Print this page




 163 
 164   _preserved_marks = (PreservedMark*)scratch;
 165   _preserved_count = 0;
 166 }
 167 
 168 
 169 void GenMarkSweep::deallocate_stacks() {
 170   if (!UseG1GC) {
 171     GenCollectedHeap* gch = GenCollectedHeap::heap();
 172     gch->release_scratch();
 173   }
 174 
 175   _preserved_mark_stack.clear(true);
 176   _preserved_oop_stack.clear(true);
 177   _marking_stack.clear();
 178   _objarray_stack.clear(true);
 179 }
 180 
 181 void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
 182   // Recursively traverse all live objects and mark them
 183   GCTraceTime(Trace, gc) tm("Phase 1: Mark live objects", _gc_timer);
 184 
 185   GenCollectedHeap* gch = GenCollectedHeap::heap();
 186 
 187   // Because follow_root_closure is created statically, cannot
 188   // use OopsInGenClosure constructor which takes a generation,
 189   // as the Universe has not been created when the static constructors
 190   // are run.
 191   follow_root_closure.set_orig_generation(gch->old_gen());
 192 
 193   // Need new claim bits before marking starts.
 194   ClassLoaderDataGraph::clear_claimed_marks();
 195 
 196   {
 197     StrongRootsScope srs(1);
 198 
 199     gch->gen_process_roots(&srs,
 200                            GenCollectedHeap::OldGen,
 201                            false, // Younger gens are not roots.
 202                            GenCollectedHeap::SO_None,
 203                            ClassUnloading,
 204                            &follow_root_closure,
 205                            &follow_root_closure,
 206                            &follow_cld_closure);
 207   }
 208 
 209   // Process reference objects found during marking
 210   {


 211     ref_processor()->setup_policy(clear_all_softrefs);
 212     const ReferenceProcessorStats& stats =
 213       ref_processor()->process_discovered_references(
 214         &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer);
 215     gc_tracer()->report_gc_reference_stats(stats);
 216   }
 217 
 218   // This is the point where the entire marking should have completed.
 219   assert(_marking_stack.is_empty(), "Marking should have completed");
 220 
 221   {
 222     GCTraceTime(Debug, gc) tm_m("Class Unloading", gc_timer());
 223 
 224     // Unload classes and purge the SystemDictionary.
 225     bool purged_class = SystemDictionary::do_unloading(&is_alive);
 226 
 227     // Unload nmethods.
 228     CodeCache::do_unloading(&is_alive, purged_class);
 229 
 230     // Prune dead klasses from subklass/sibling/implementor lists.
 231     Klass::clean_weak_klass_links(&is_alive);
 232   }
 233 
 234   {
 235     GCTraceTime(Debug, gc) t("Scrub String Table", gc_timer());
 236     // Delete entries for dead interned strings.
 237     StringTable::unlink(&is_alive);
 238   }
 239 
 240   {
 241     GCTraceTime(Debug, gc) t("Scrub Symbol Table", gc_timer());
 242     // Clean up unreferenced symbols in symbol table.
 243     SymbolTable::unlink();
 244   }
 245 
 246   gc_tracer()->report_object_count_after_gc(&is_alive);
 247 }
 248 
 249 
 250 void GenMarkSweep::mark_sweep_phase2() {
 251   // Now all live objects are marked, compute the new object addresses.
 252 
 253   // It is imperative that we traverse perm_gen LAST. If dead space is
 254   // allowed a range of dead object may get overwritten by a dead int
 255   // array. If perm_gen is not traversed last a Klass* may get
 256   // overwritten. This is fine since it is dead, but if the class has dead
 257   // instances we have to skip them, and in order to find their size we
 258   // need the Klass*!
 259   //
 260   // It is not required that we traverse spaces in the same order in
 261   // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
 262   // tracking expects us to do so. See comment under phase4.
 263 
 264   GenCollectedHeap* gch = GenCollectedHeap::heap();
 265 
 266   GCTraceTime(Trace, gc) tm("Phase 2: Compute new object addresses", _gc_timer);
 267 
 268   gch->prepare_for_compaction();
 269 }
 270 
 271 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
 272 public:
 273   void do_generation(Generation* gen) {
 274     gen->adjust_pointers();
 275   }
 276 };
 277 
 278 void GenMarkSweep::mark_sweep_phase3() {
 279   GenCollectedHeap* gch = GenCollectedHeap::heap();
 280 
 281   // Adjust the pointers to reflect the new locations
 282   GCTraceTime(Trace, gc) tm("Phase 3: Adjust pointers", _gc_timer);
 283 
 284   // Need new claim bits for the pointer adjustment tracing.
 285   ClassLoaderDataGraph::clear_claimed_marks();
 286 
 287   // Because the closure below is created statically, we cannot
 288   // use OopsInGenClosure constructor which takes a generation,
 289   // as the Universe has not been created when the static constructors
 290   // are run.
 291   adjust_pointer_closure.set_orig_generation(gch->old_gen());
 292 
 293   {
 294     StrongRootsScope srs(1);
 295 
 296     gch->gen_process_roots(&srs,
 297                            GenCollectedHeap::OldGen,
 298                            false, // Younger gens are not roots.
 299                            GenCollectedHeap::SO_AllCodeCache,
 300                            GenCollectedHeap::StrongAndWeakRoots,
 301                            &adjust_pointer_closure,
 302                            &adjust_pointer_closure,


 314 public:
 315   void do_generation(Generation* gen) {
 316     gen->compact();
 317   }
 318 };
 319 
 320 void GenMarkSweep::mark_sweep_phase4() {
 321   // All pointers are now adjusted, move objects accordingly
 322 
 323   // It is imperative that we traverse perm_gen first in phase4. All
 324   // classes must be allocated earlier than their instances, and traversing
 325   // perm_gen first makes sure that all Klass*s have moved to their new
 326   // location before any instance does a dispatch through it's klass!
 327 
 328   // The ValidateMarkSweep live oops tracking expects us to traverse spaces
 329   // in the same order in phase2, phase3 and phase4. We don't quite do that
 330   // here (perm_gen first rather than last), so we tell the validate code
 331   // to use a higher index (saved from phase2) when verifying perm_gen.
 332   GenCollectedHeap* gch = GenCollectedHeap::heap();
 333 
 334   GCTraceTime(Trace, gc) tm("Phase 4: Move objects", _gc_timer);
 335 
 336   GenCompactClosure blk;
 337   gch->generation_iterate(&blk, true);
 338 }


 163 
 164   _preserved_marks = (PreservedMark*)scratch;
 165   _preserved_count = 0;
 166 }
 167 
 168 
 169 void GenMarkSweep::deallocate_stacks() {
 170   if (!UseG1GC) {
 171     GenCollectedHeap* gch = GenCollectedHeap::heap();
 172     gch->release_scratch();
 173   }
 174 
 175   _preserved_mark_stack.clear(true);
 176   _preserved_oop_stack.clear(true);
 177   _marking_stack.clear();
 178   _objarray_stack.clear(true);
 179 }
 180 
 181 void GenMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
 182   // Recursively traverse all live objects and mark them
 183   GCTraceTime(Info, gc, phases) tm("Phase 1: Mark live objects", _gc_timer);
 184 
 185   GenCollectedHeap* gch = GenCollectedHeap::heap();
 186 
 187   // Because follow_root_closure is created statically, cannot
 188   // use OopsInGenClosure constructor which takes a generation,
 189   // as the Universe has not been created when the static constructors
 190   // are run.
 191   follow_root_closure.set_orig_generation(gch->old_gen());
 192 
 193   // Need new claim bits before marking starts.
 194   ClassLoaderDataGraph::clear_claimed_marks();
 195 
 196   {
 197     StrongRootsScope srs(1);
 198 
 199     gch->gen_process_roots(&srs,
 200                            GenCollectedHeap::OldGen,
 201                            false, // Younger gens are not roots.
 202                            GenCollectedHeap::SO_None,
 203                            ClassUnloading,
 204                            &follow_root_closure,
 205                            &follow_root_closure,
 206                            &follow_cld_closure);
 207   }
 208 
 209   // Process reference objects found during marking
 210   {
 211     GCTraceTime(Debug, gc, phases) tm_m("Reference Processing", gc_timer());
 212 
 213     ref_processor()->setup_policy(clear_all_softrefs);
 214     const ReferenceProcessorStats& stats =
 215       ref_processor()->process_discovered_references(
 216         &is_alive, &keep_alive, &follow_stack_closure, NULL, _gc_timer);
 217     gc_tracer()->report_gc_reference_stats(stats);
 218   }
 219 
 220   // This is the point where the entire marking should have completed.
 221   assert(_marking_stack.is_empty(), "Marking should have completed");
 222 
 223   {
 224     GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", gc_timer());
 225 
 226     // Unload classes and purge the SystemDictionary.
 227     bool purged_class = SystemDictionary::do_unloading(&is_alive);
 228 
 229     // Unload nmethods.
 230     CodeCache::do_unloading(&is_alive, purged_class);
 231 
 232     // Prune dead klasses from subklass/sibling/implementor lists.
 233     Klass::clean_weak_klass_links(&is_alive);
 234   }
 235 
 236   {
 237     GCTraceTime(Debug, gc, phases) t("Scrub String Table", gc_timer());
 238     // Delete entries for dead interned strings.
 239     StringTable::unlink(&is_alive);
 240   }
 241 
 242   {
 243     GCTraceTime(Debug, gc, phases) t("Scrub Symbol Table", gc_timer());
 244     // Clean up unreferenced symbols in symbol table.
 245     SymbolTable::unlink();
 246   }
 247 
 248   gc_tracer()->report_object_count_after_gc(&is_alive);
 249 }
 250 
 251 
 252 void GenMarkSweep::mark_sweep_phase2() {
 253   // Now all live objects are marked, compute the new object addresses.
 254 
 255   // It is imperative that we traverse perm_gen LAST. If dead space is
 256   // allowed a range of dead object may get overwritten by a dead int
 257   // array. If perm_gen is not traversed last a Klass* may get
 258   // overwritten. This is fine since it is dead, but if the class has dead
 259   // instances we have to skip them, and in order to find their size we
 260   // need the Klass*!
 261   //
 262   // It is not required that we traverse spaces in the same order in
 263   // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
 264   // tracking expects us to do so. See comment under phase4.
 265 
 266   GenCollectedHeap* gch = GenCollectedHeap::heap();
 267 
 268   GCTraceTime(Info, gc, phases) tm("Phase 2: Compute new object addresses", _gc_timer);
 269 
 270   gch->prepare_for_compaction();
 271 }
 272 
 273 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
 274 public:
 275   void do_generation(Generation* gen) {
 276     gen->adjust_pointers();
 277   }
 278 };
 279 
 280 void GenMarkSweep::mark_sweep_phase3() {
 281   GenCollectedHeap* gch = GenCollectedHeap::heap();
 282 
 283   // Adjust the pointers to reflect the new locations
 284   GCTraceTime(Info, gc, phases) tm("Phase 3: Adjust pointers", gc_timer());
 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->old_gen());
 294 
 295   {
 296     StrongRootsScope srs(1);
 297 
 298     gch->gen_process_roots(&srs,
 299                            GenCollectedHeap::OldGen,
 300                            false, // Younger gens are not roots.
 301                            GenCollectedHeap::SO_AllCodeCache,
 302                            GenCollectedHeap::StrongAndWeakRoots,
 303                            &adjust_pointer_closure,
 304                            &adjust_pointer_closure,


 316 public:
 317   void do_generation(Generation* gen) {
 318     gen->compact();
 319   }
 320 };
 321 
 322 void GenMarkSweep::mark_sweep_phase4() {
 323   // All pointers are now adjusted, move objects accordingly
 324 
 325   // It is imperative that we traverse perm_gen first in phase4. All
 326   // classes must be allocated earlier than their instances, and traversing
 327   // perm_gen first makes sure that all Klass*s have moved to their new
 328   // location before any instance does a dispatch through it's klass!
 329 
 330   // The ValidateMarkSweep live oops tracking expects us to traverse spaces
 331   // in the same order in phase2, phase3 and phase4. We don't quite do that
 332   // here (perm_gen first rather than last), so we tell the validate code
 333   // to use a higher index (saved from phase2) when verifying perm_gen.
 334   GenCollectedHeap* gch = GenCollectedHeap::heap();
 335 
 336   GCTraceTime(Info, gc, phases) tm("Phase 4: Move objects", _gc_timer);
 337 
 338   GenCompactClosure blk;
 339   gch->generation_iterate(&blk, true);
 340 }
< prev index next >