< prev index next >

src/hotspot/share/gc/g1/g1MarkSweep.cpp

Print this page




  45 #include "gc/shared/space.hpp"
  46 #include "gc/shared/weakProcessor.hpp"
  47 #include "oops/instanceRefKlass.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "prims/jvmtiExport.hpp"
  50 #include "runtime/atomic.hpp"
  51 #include "runtime/biasedLocking.hpp"
  52 #include "runtime/synchronizer.hpp"
  53 #include "runtime/thread.hpp"
  54 #include "runtime/vmThread.hpp"
  55 #include "utilities/copy.hpp"
  56 #include "utilities/events.hpp"
  57 
  58 class HeapRegion;
  59 
  60 void G1MarkSweep::invoke_at_safepoint(ReferenceProcessor* rp,
  61                                       bool clear_all_softrefs) {
  62   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
  63   HandleMark hm;  // Discard invalid handles created during gc
  64 
  65 #if defined(COMPILER2) || INCLUDE_JVMCI
  66   DerivedPointerTable::clear();
  67 #endif
  68 #ifdef ASSERT
  69   if (G1CollectedHeap::heap()->collector_policy()->should_clear_all_soft_refs()) {
  70     assert(clear_all_softrefs, "Policy should have been checked earler");
  71   }
  72 #endif
  73   // hook up weak ref data so it can be used during Mark-Sweep
  74   assert(GenMarkSweep::ref_processor() == NULL, "no stomping");
  75   assert(rp != NULL, "should be non-NULL");
  76   assert(rp == G1CollectedHeap::heap()->ref_processor_stw(), "Precondition");
  77 
  78   GenMarkSweep::set_ref_processor(rp);
  79   rp->setup_policy(clear_all_softrefs);
  80 
  81   // When collecting the permanent generation Method*s may be moving,
  82   // so we either have to flush all bcp data or convert it into bci.
  83   CodeCache::gc_prologue();
  84 
  85   bool marked_for_unloading = false;
  86 
  87   allocate_stacks();
  88 
  89   // We should save the marks of the currently locked biased monitors.
  90   // The marking doesn't preserve the marks of biased objects.
  91   BiasedLocking::preserve_marks();
  92 
  93   // Process roots and do the marking.
  94   mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);
  95 
  96   // Prepare compaction.
  97   mark_sweep_phase2();
  98 
  99 #if defined(COMPILER2) || INCLUDE_JVMCI
 100   // Don't add any more derived pointers during phase3
 101   DerivedPointerTable::set_active(false);
 102 #endif
 103 
 104   // Adjust all pointers.
 105   mark_sweep_phase3();
 106 
 107   // Do the actual compaction.
 108   mark_sweep_phase4();
 109 
 110   GenMarkSweep::restore_marks();
 111   BiasedLocking::restore_marks();
 112   GenMarkSweep::deallocate_stacks();
 113 
 114 #if defined(COMPILER2) || INCLUDE_JVMCI
 115   // Now update the derived pointers.
 116   DerivedPointerTable::update_pointers();
 117 #endif
 118 
 119   CodeCache::gc_epilogue();
 120   JvmtiExport::gc_epilogue();
 121 
 122   // refs processing: clean slate
 123   GenMarkSweep::set_ref_processor(NULL);
 124 }
 125 
 126 STWGCTimer* G1MarkSweep::gc_timer() {
 127   return G1FullGCScope::instance()->timer();
 128 }
 129 
 130 SerialOldTracer* G1MarkSweep::gc_tracer() {
 131   return G1FullGCScope::instance()->tracer();
 132 }
 133 
 134 void G1MarkSweep::allocate_stacks() {


 187 
 188   {
 189     GCTraceTime(Debug, gc, phases) trace("Weak Processing", gc_timer());
 190     WeakProcessor::weak_oops_do(&GenMarkSweep::is_alive, &do_nothing_cl);
 191   }
 192 
 193   if (ClassUnloading) {
 194     GCTraceTime(Debug, gc, phases) trace("Class Unloading", gc_timer());
 195 
 196     // Unload classes and purge the SystemDictionary.
 197     bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive, gc_timer());
 198 
 199     g1h->complete_cleaning(&GenMarkSweep::is_alive, purged_class);
 200   } else {
 201     GCTraceTime(Debug, gc, phases) trace("Cleanup", gc_timer());
 202     g1h->partial_cleaning(&GenMarkSweep::is_alive, true, true, G1StringDedup::is_enabled());
 203   }
 204 
 205   if (VerifyDuringGC) {
 206     HandleMark hm;  // handle scope
 207 #if defined(COMPILER2) || INCLUDE_JVMCI
 208     DerivedPointerTableDeactivate dpt_deact;
 209 #endif
 210     g1h->prepare_for_verify();
 211     // Note: we can verify only the heap here. When an object is
 212     // marked, the previous value of the mark word (including
 213     // identity hash values, ages, etc) is preserved, and the mark
 214     // word is set to markOop::marked_value - effectively removing
 215     // any hash values from the mark word. These hash values are
 216     // used when verifying the dictionaries and so removing them
 217     // from the mark word can make verification of the dictionaries
 218     // fail. At the end of the GC, the original mark word values
 219     // (including hash values) are restored to the appropriate
 220     // objects.
 221     GCTraceTime(Info, gc, verify)("During GC (full)");
 222     g1h->verify(VerifyOption_G1UseMarkWord);
 223   }
 224 
 225   gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
 226 }
 227 




  45 #include "gc/shared/space.hpp"
  46 #include "gc/shared/weakProcessor.hpp"
  47 #include "oops/instanceRefKlass.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "prims/jvmtiExport.hpp"
  50 #include "runtime/atomic.hpp"
  51 #include "runtime/biasedLocking.hpp"
  52 #include "runtime/synchronizer.hpp"
  53 #include "runtime/thread.hpp"
  54 #include "runtime/vmThread.hpp"
  55 #include "utilities/copy.hpp"
  56 #include "utilities/events.hpp"
  57 
  58 class HeapRegion;
  59 
  60 void G1MarkSweep::invoke_at_safepoint(ReferenceProcessor* rp,
  61                                       bool clear_all_softrefs) {
  62   assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
  63   HandleMark hm;  // Discard invalid handles created during gc
  64 
  65 #if COMPILER2_OR_JVMCI
  66   DerivedPointerTable::clear();
  67 #endif
  68 #ifdef ASSERT
  69   if (G1CollectedHeap::heap()->collector_policy()->should_clear_all_soft_refs()) {
  70     assert(clear_all_softrefs, "Policy should have been checked earler");
  71   }
  72 #endif
  73   // hook up weak ref data so it can be used during Mark-Sweep
  74   assert(GenMarkSweep::ref_processor() == NULL, "no stomping");
  75   assert(rp != NULL, "should be non-NULL");
  76   assert(rp == G1CollectedHeap::heap()->ref_processor_stw(), "Precondition");
  77 
  78   GenMarkSweep::set_ref_processor(rp);
  79   rp->setup_policy(clear_all_softrefs);
  80 
  81   // When collecting the permanent generation Method*s may be moving,
  82   // so we either have to flush all bcp data or convert it into bci.
  83   CodeCache::gc_prologue();
  84 
  85   bool marked_for_unloading = false;
  86 
  87   allocate_stacks();
  88 
  89   // We should save the marks of the currently locked biased monitors.
  90   // The marking doesn't preserve the marks of biased objects.
  91   BiasedLocking::preserve_marks();
  92 
  93   // Process roots and do the marking.
  94   mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);
  95 
  96   // Prepare compaction.
  97   mark_sweep_phase2();
  98 
  99 #if COMPILER2_OR_JVMCI
 100   // Don't add any more derived pointers during phase3
 101   DerivedPointerTable::set_active(false);
 102 #endif
 103 
 104   // Adjust all pointers.
 105   mark_sweep_phase3();
 106 
 107   // Do the actual compaction.
 108   mark_sweep_phase4();
 109 
 110   GenMarkSweep::restore_marks();
 111   BiasedLocking::restore_marks();
 112   GenMarkSweep::deallocate_stacks();
 113 
 114 #if COMPILER2_OR_JVMCI
 115   // Now update the derived pointers.
 116   DerivedPointerTable::update_pointers();
 117 #endif
 118 
 119   CodeCache::gc_epilogue();
 120   JvmtiExport::gc_epilogue();
 121 
 122   // refs processing: clean slate
 123   GenMarkSweep::set_ref_processor(NULL);
 124 }
 125 
 126 STWGCTimer* G1MarkSweep::gc_timer() {
 127   return G1FullGCScope::instance()->timer();
 128 }
 129 
 130 SerialOldTracer* G1MarkSweep::gc_tracer() {
 131   return G1FullGCScope::instance()->tracer();
 132 }
 133 
 134 void G1MarkSweep::allocate_stacks() {


 187 
 188   {
 189     GCTraceTime(Debug, gc, phases) trace("Weak Processing", gc_timer());
 190     WeakProcessor::weak_oops_do(&GenMarkSweep::is_alive, &do_nothing_cl);
 191   }
 192 
 193   if (ClassUnloading) {
 194     GCTraceTime(Debug, gc, phases) trace("Class Unloading", gc_timer());
 195 
 196     // Unload classes and purge the SystemDictionary.
 197     bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive, gc_timer());
 198 
 199     g1h->complete_cleaning(&GenMarkSweep::is_alive, purged_class);
 200   } else {
 201     GCTraceTime(Debug, gc, phases) trace("Cleanup", gc_timer());
 202     g1h->partial_cleaning(&GenMarkSweep::is_alive, true, true, G1StringDedup::is_enabled());
 203   }
 204 
 205   if (VerifyDuringGC) {
 206     HandleMark hm;  // handle scope
 207 #if COMPILER2_OR_JVMCI
 208     DerivedPointerTableDeactivate dpt_deact;
 209 #endif
 210     g1h->prepare_for_verify();
 211     // Note: we can verify only the heap here. When an object is
 212     // marked, the previous value of the mark word (including
 213     // identity hash values, ages, etc) is preserved, and the mark
 214     // word is set to markOop::marked_value - effectively removing
 215     // any hash values from the mark word. These hash values are
 216     // used when verifying the dictionaries and so removing them
 217     // from the mark word can make verification of the dictionaries
 218     // fail. At the end of the GC, the original mark word values
 219     // (including hash values) are restored to the appropriate
 220     // objects.
 221     GCTraceTime(Info, gc, verify)("During GC (full)");
 222     g1h->verify(VerifyOption_G1UseMarkWord);
 223   }
 224 
 225   gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
 226 }
 227 


< prev index next >