hotspot/src/share/vm/memory/genMarkSweep.cpp
changeset 29684 a36d90acae41
parent 29200 5e480434bef4
child 29693 fac175f7a466
equal deleted inserted replaced
29683:7675ca064fdc 29684:a36d90acae41
   107   // (Should this be in general part?)
   107   // (Should this be in general part?)
   108   gch->save_marks();
   108   gch->save_marks();
   109 
   109 
   110   deallocate_stacks();
   110   deallocate_stacks();
   111 
   111 
   112   // If compaction completely evacuated all generations younger than this
   112   // If compaction completely evacuated the young generation then we
   113   // one, then we can clear the card table.  Otherwise, we must invalidate
   113   // can clear the card table.  Otherwise, we must invalidate
   114   // it (consider all cards dirty).  In the future, we might consider doing
   114   // it (consider all cards dirty).  In the future, we might consider doing
   115   // compaction within generations only, and doing card-table sliding.
   115   // compaction within generations only, and doing card-table sliding.
   116   bool all_empty = true;
       
   117   for (int i = 0; all_empty && i < level; i++) {
       
   118     Generation* g = gch->get_gen(i);
       
   119     all_empty = all_empty && gch->get_gen(i)->used() == 0;
       
   120   }
       
   121   GenRemSet* rs = gch->rem_set();
   116   GenRemSet* rs = gch->rem_set();
   122   Generation* old_gen = gch->get_gen(level);
   117   Generation* old_gen = gch->old_gen();
       
   118 
   123   // Clear/invalidate below make use of the "prev_used_regions" saved earlier.
   119   // Clear/invalidate below make use of the "prev_used_regions" saved earlier.
   124   if (all_empty) {
   120   if (gch->young_gen()->used() == 0) {
   125     // We've evacuated all generations below us.
   121     // We've evacuated the young generation.
   126     rs->clear_into_younger(old_gen);
   122     rs->clear_into_younger(old_gen);
   127   } else {
   123   } else {
   128     // Invalidate the cards corresponding to the currently used
   124     // Invalidate the cards corresponding to the currently used
   129     // region and clear those corresponding to the evacuated region.
   125     // region and clear those corresponding to the evacuated region.
   130     rs->invalidate_or_clear(old_gen);
   126     rs->invalidate_or_clear(old_gen);
   155   gch->trace_heap_after_gc(_gc_tracer);
   151   gch->trace_heap_after_gc(_gc_tracer);
   156 }
   152 }
   157 
   153 
   158 void GenMarkSweep::allocate_stacks() {
   154 void GenMarkSweep::allocate_stacks() {
   159   GenCollectedHeap* gch = GenCollectedHeap::heap();
   155   GenCollectedHeap* gch = GenCollectedHeap::heap();
   160   // Scratch request on behalf of oldest generation; will do no
   156   // Scratch request on behalf of old generation; will do no allocation.
   161   // allocation.
   157   ScratchBlock* scratch = gch->gather_scratch(gch->old_gen(), 0);
   162   ScratchBlock* scratch = gch->gather_scratch(gch->get_gen(gch->_n_gens-1), 0);
       
   163 
   158 
   164   // $$$ To cut a corner, we'll only use the first scratch block, and then
   159   // $$$ To cut a corner, we'll only use the first scratch block, and then
   165   // revert to malloc.
   160   // revert to malloc.
   166   if (scratch != NULL) {
   161   if (scratch != NULL) {
   167     _preserved_count_max =
   162     _preserved_count_max =
   186   _marking_stack.clear();
   181   _marking_stack.clear();
   187   _objarray_stack.clear(true);
   182   _objarray_stack.clear(true);
   188 }
   183 }
   189 
   184 
   190 void GenMarkSweep::mark_sweep_phase1(int level,
   185 void GenMarkSweep::mark_sweep_phase1(int level,
   191                                   bool clear_all_softrefs) {
   186                                      bool clear_all_softrefs) {
   192   // Recursively traverse all live objects and mark them
   187   // Recursively traverse all live objects and mark them
   193   GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
   188   GCTraceTime tm("phase 1", PrintGC && Verbose, true, _gc_timer, _gc_tracer->gc_id());
   194   trace(" 1");
   189   trace(" 1");
   195 
   190 
   196   GenCollectedHeap* gch = GenCollectedHeap::heap();
   191   GenCollectedHeap* gch = GenCollectedHeap::heap();
   197 
   192 
   198   // Because follow_root_closure is created statically, cannot
   193   // Because follow_root_closure is created statically, cannot
   199   // use OopsInGenClosure constructor which takes a generation,
   194   // use OopsInGenClosure constructor which takes a generation,
   200   // as the Universe has not been created when the static constructors
   195   // as the Universe has not been created when the static constructors
   201   // are run.
   196   // are run.
   202   follow_root_closure.set_orig_generation(gch->get_gen(level));
   197   assert(level == 1, "We don't use mark-sweep on young generations");
       
   198   follow_root_closure.set_orig_generation(gch->old_gen());
   203 
   199 
   204   // Need new claim bits before marking starts.
   200   // Need new claim bits before marking starts.
   205   ClassLoaderDataGraph::clear_claimed_marks();
   201   ClassLoaderDataGraph::clear_claimed_marks();
   206 
   202 
   207   gch->gen_process_roots(level,
   203   gch->gen_process_roots(level,
   285 
   281 
   286   // Because the closure below is created statically, we cannot
   282   // Because the closure below is created statically, we cannot
   287   // use OopsInGenClosure constructor which takes a generation,
   283   // use OopsInGenClosure constructor which takes a generation,
   288   // as the Universe has not been created when the static constructors
   284   // as the Universe has not been created when the static constructors
   289   // are run.
   285   // are run.
   290   adjust_pointer_closure.set_orig_generation(gch->get_gen(level));
   286   assert(level == 1, "We don't use mark-sweep on young generations.");
       
   287   adjust_pointer_closure.set_orig_generation(gch->old_gen());
   291 
   288 
   292   gch->gen_process_roots(level,
   289   gch->gen_process_roots(level,
   293                          false, // Younger gens are not roots.
   290                          false, // Younger gens are not roots.
   294                          true,  // activate StrongRootsScope
   291                          true,  // activate StrongRootsScope
   295                          SharedHeap::SO_AllCodeCache,
   292                          SharedHeap::SO_AllCodeCache,