src/share/vm/gc_implementation/g1/g1MarkSweep.cpp

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_g1MarkSweep.cpp.incl"
  27 
  28 class HeapRegion;
  29 
  30 void G1MarkSweep::invoke_at_safepoint(ReferenceProcessor* rp,
  31                                       bool clear_all_softrefs) {
  32   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
  33 
  34   // hook up weak ref data so it can be used during Mark-Sweep
  35   assert(GenMarkSweep::ref_processor() == NULL, "no stomping");
  36   GenMarkSweep::_ref_processor = rp;
  37   assert(rp != NULL, "should be non-NULL");


  38 
  39   // When collecting the permanent generation methodOops may be moving,
  40   // so we either have to flush all bcp data or convert it into bci.
  41   CodeCache::gc_prologue();
  42   Threads::gc_prologue();
  43 
  44   // Increment the invocation count for the permanent generation, since it is
  45   // implicitly collected whenever we do a full mark sweep collection.
  46   SharedHeap* sh = SharedHeap::heap();
  47   sh->perm_gen()->stat_record()->invocations++;
  48 
  49   bool marked_for_unloading = false;
  50 
  51   allocate_stacks();
  52 
  53   // We should save the marks of the currently locked biased monitors.
  54   // The marking doesn't preserve the marks of biased objects.
  55   BiasedLocking::preserve_marks();
  56 
  57   mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);


 104   size_t size = SystemDictionary::number_of_classes() * 2;
 105   GenMarkSweep::_revisit_klass_stack =
 106     new (ResourceObj::C_HEAP) GrowableArray<Klass*>((int)size, true);
 107 }
 108 
 109 void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
 110                                     bool clear_all_softrefs) {
 111   // Recursively traverse all live objects and mark them
 112   EventMark m("1 mark object");
 113   TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty);
 114   GenMarkSweep::trace(" 1");
 115 
 116   SharedHeap* sh = SharedHeap::heap();
 117 
 118   sh->process_strong_roots(true,  // Collecting permanent generation.
 119                            SharedHeap::SO_SystemClasses,
 120                            &GenMarkSweep::follow_root_closure,
 121                            &GenMarkSweep::follow_root_closure);
 122 
 123   // Process reference objects found during marking
 124   ReferencePolicy *soft_ref_policy;
 125   if (clear_all_softrefs) {
 126     soft_ref_policy = new AlwaysClearPolicy();
 127   } else {
 128 #ifdef COMPILER2
 129     soft_ref_policy = new LRUMaxHeapPolicy();
 130 #else
 131     soft_ref_policy = new LRUCurrentHeapPolicy();
 132 #endif
 133   }
 134   assert(soft_ref_policy != NULL,"No soft reference policy");
 135   GenMarkSweep::ref_processor()->process_discovered_references(
 136                                    soft_ref_policy,
 137                                    &GenMarkSweep::is_alive,
 138                                    &GenMarkSweep::keep_alive,
 139                                    &GenMarkSweep::follow_stack_closure,
 140                                    NULL);
 141 
 142   // Follow system dictionary roots and unload classes
 143   bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
 144   assert(GenMarkSweep::_marking_stack->is_empty(),
 145          "stack should be empty by now");
 146 
 147   // Follow code cache roots (has to be done after system dictionary,
 148   // assumes all live klasses are marked)
 149   CodeCache::do_unloading(&GenMarkSweep::is_alive,
 150                                    &GenMarkSweep::keep_alive,
 151                                    purged_class);
 152            GenMarkSweep::follow_stack();
 153 
 154   // Update subklass/sibling/implementor links of live klasses
 155   GenMarkSweep::follow_weak_klass_links();
 156   assert(GenMarkSweep::_marking_stack->is_empty(),
 157          "stack should be empty by now");




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 #include "incls/_precompiled.incl"
  26 #include "incls/_g1MarkSweep.cpp.incl"
  27 
  28 class HeapRegion;
  29 
  30 void G1MarkSweep::invoke_at_safepoint(ReferenceProcessor* rp,
  31                                       bool clear_all_softrefs) {
  32   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
  33 
  34   // hook up weak ref data so it can be used during Mark-Sweep
  35   assert(GenMarkSweep::ref_processor() == NULL, "no stomping");

  36   assert(rp != NULL, "should be non-NULL");
  37   GenMarkSweep::_ref_processor = rp;
  38   rp->snap_policy(clear_all_softrefs);
  39 
  40   // When collecting the permanent generation methodOops may be moving,
  41   // so we either have to flush all bcp data or convert it into bci.
  42   CodeCache::gc_prologue();
  43   Threads::gc_prologue();
  44 
  45   // Increment the invocation count for the permanent generation, since it is
  46   // implicitly collected whenever we do a full mark sweep collection.
  47   SharedHeap* sh = SharedHeap::heap();
  48   sh->perm_gen()->stat_record()->invocations++;
  49 
  50   bool marked_for_unloading = false;
  51 
  52   allocate_stacks();
  53 
  54   // We should save the marks of the currently locked biased monitors.
  55   // The marking doesn't preserve the marks of biased objects.
  56   BiasedLocking::preserve_marks();
  57 
  58   mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);


 105   size_t size = SystemDictionary::number_of_classes() * 2;
 106   GenMarkSweep::_revisit_klass_stack =
 107     new (ResourceObj::C_HEAP) GrowableArray<Klass*>((int)size, true);
 108 }
 109 
 110 void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
 111                                     bool clear_all_softrefs) {
 112   // Recursively traverse all live objects and mark them
 113   EventMark m("1 mark object");
 114   TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty);
 115   GenMarkSweep::trace(" 1");
 116 
 117   SharedHeap* sh = SharedHeap::heap();
 118 
 119   sh->process_strong_roots(true,  // Collecting permanent generation.
 120                            SharedHeap::SO_SystemClasses,
 121                            &GenMarkSweep::follow_root_closure,
 122                            &GenMarkSweep::follow_root_closure);
 123 
 124   // Process reference objects found during marking
 125   ReferenceProcessor* rp = GenMarkSweep::ref_processor();
 126   rp->snap_policy(clear_all_softrefs);
 127   rp->process_discovered_references(&GenMarkSweep::is_alive,











 128                                     &GenMarkSweep::keep_alive,
 129                                     &GenMarkSweep::follow_stack_closure,
 130                                     NULL);
 131 
 132   // Follow system dictionary roots and unload classes
 133   bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
 134   assert(GenMarkSweep::_marking_stack->is_empty(),
 135          "stack should be empty by now");
 136 
 137   // Follow code cache roots (has to be done after system dictionary,
 138   // assumes all live klasses are marked)
 139   CodeCache::do_unloading(&GenMarkSweep::is_alive,
 140                                    &GenMarkSweep::keep_alive,
 141                                    purged_class);
 142            GenMarkSweep::follow_stack();
 143 
 144   // Update subklass/sibling/implementor links of live klasses
 145   GenMarkSweep::follow_weak_klass_links();
 146   assert(GenMarkSweep::_marking_stack->is_empty(),
 147          "stack should be empty by now");