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

Print this page
rev 2724 : 6484965: G1: piggy-back liveness accounting phase on marking
Summary: Remove the separate counting phase of concurrent marking by tracking the amount of marked bytes and the cards spanned by marked objects in marking task/worker thread local data structures, which are updated as individual objects are marked.
Reviewed-by:


  27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  29 #include "gc_implementation/g1/g1MMUTracker.hpp"
  30 #include "gc_implementation/g1/vm_operations_g1.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/vmThread.hpp"
  33 
  34 // ======= Concurrent Mark Thread ========
  35 
  36 // The CM thread is created when the G1 garbage collector is used
  37 
  38 SurrogateLockerThread*
  39      ConcurrentMarkThread::_slt = NULL;
  40 
  41 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
  42   ConcurrentGCThread(),
  43   _cm(cm),
  44   _started(false),
  45   _in_progress(false),
  46   _vtime_accum(0.0),
  47   _vtime_mark_accum(0.0),
  48   _vtime_count_accum(0.0)
  49 {
  50   create_and_start();
  51 }
  52 
  53 class CMCheckpointRootsFinalClosure: public VoidClosure {
  54 
  55   ConcurrentMark* _cm;
  56 public:
  57 
  58   CMCheckpointRootsFinalClosure(ConcurrentMark* cm) :
  59     _cm(cm) {}
  60 
  61   void do_void(){
  62     _cm->checkpointRootsFinal(false); // !clear_all_soft_refs
  63   }
  64 };
  65 
  66 class CMCleanUp: public VoidClosure {
  67   ConcurrentMark* _cm;
  68 public:


 130 
 131           CMCheckpointRootsFinalClosure final_cl(_cm);
 132           sprintf(verbose_str, "GC remark");
 133           VM_CGC_Operation op(&final_cl, verbose_str);
 134           VMThread::execute(&op);
 135         }
 136         if (cm()->restart_for_overflow() &&
 137             G1TraceMarkStackOverflow) {
 138           gclog_or_tty->print_cr("Restarting conc marking because of MS overflow "
 139                                  "in remark (restart #%d).", iter);
 140         }
 141 
 142         if (cm()->restart_for_overflow()) {
 143           if (PrintGC) {
 144             gclog_or_tty->date_stamp(PrintGCDateStamps);
 145             gclog_or_tty->stamp(PrintGCTimeStamps);
 146             gclog_or_tty->print_cr("[GC concurrent-mark-restart-for-overflow]");
 147           }
 148         }
 149       } while (cm()->restart_for_overflow());
 150       double counting_start_time = os::elapsedVTime();
 151 
 152       // YSR: These look dubious (i.e. redundant) !!! FIX ME
 153       slt()->manipulatePLL(SurrogateLockerThread::acquirePLL);
 154       slt()->manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL);
 155 
 156       if (!cm()->has_aborted()) {
 157         double count_start_sec = os::elapsedTime();
 158         if (PrintGC) {
 159           gclog_or_tty->date_stamp(PrintGCDateStamps);
 160           gclog_or_tty->stamp(PrintGCTimeStamps);
 161           gclog_or_tty->print_cr("[GC concurrent-count-start]");
 162         }
 163 
 164         _sts.join();
 165         _cm->calcDesiredRegions();
 166         _sts.leave();
 167 
 168         if (!cm()->has_aborted()) {
 169           double count_end_sec = os::elapsedTime();
 170           if (PrintGC) {
 171             gclog_or_tty->date_stamp(PrintGCDateStamps);
 172             gclog_or_tty->stamp(PrintGCTimeStamps);
 173             gclog_or_tty->print_cr("[GC concurrent-count-end, %1.7lf]",
 174                                    count_end_sec - count_start_sec);
 175           }
 176         }
 177       }
 178       double end_time = os::elapsedVTime();
 179       _vtime_count_accum += (end_time - counting_start_time);
 180       // Update the total virtual time before doing this, since it will try
 181       // to measure it to get the vtime for this marking.  We purposely
 182       // neglect the presumably-short "completeCleanup" phase here.
 183       _vtime_accum = (end_time - _vtime_start);

 184       if (!cm()->has_aborted()) {
 185         if (g1_policy->adaptive_young_list_length()) {
 186           double now = os::elapsedTime();
 187           double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
 188           jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
 189           os::sleep(current_thread, sleep_time_ms, false);
 190         }
 191 
 192         CMCleanUp cl_cl(_cm);
 193         sprintf(verbose_str, "GC cleanup");
 194         VM_CGC_Operation op(&cl_cl, verbose_str);
 195         VMThread::execute(&op);
 196       } else {
 197         g1h->set_marking_complete();
 198       }
 199 
 200       // Check if cleanup set the free_regions_coming flag. If it
 201       // hasn't, we can just skip the next step.
 202       if (g1h->free_regions_coming()) {
 203         // The following will finish freeing up any regions that we




  27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  29 #include "gc_implementation/g1/g1MMUTracker.hpp"
  30 #include "gc_implementation/g1/vm_operations_g1.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/vmThread.hpp"
  33 
  34 // ======= Concurrent Mark Thread ========
  35 
  36 // The CM thread is created when the G1 garbage collector is used
  37 
  38 SurrogateLockerThread*
  39      ConcurrentMarkThread::_slt = NULL;
  40 
  41 ConcurrentMarkThread::ConcurrentMarkThread(ConcurrentMark* cm) :
  42   ConcurrentGCThread(),
  43   _cm(cm),
  44   _started(false),
  45   _in_progress(false),
  46   _vtime_accum(0.0),
  47   _vtime_mark_accum(0.0)

  48 {
  49   create_and_start();
  50 }
  51 
  52 class CMCheckpointRootsFinalClosure: public VoidClosure {
  53 
  54   ConcurrentMark* _cm;
  55 public:
  56 
  57   CMCheckpointRootsFinalClosure(ConcurrentMark* cm) :
  58     _cm(cm) {}
  59 
  60   void do_void(){
  61     _cm->checkpointRootsFinal(false); // !clear_all_soft_refs
  62   }
  63 };
  64 
  65 class CMCleanUp: public VoidClosure {
  66   ConcurrentMark* _cm;
  67 public:


 129 
 130           CMCheckpointRootsFinalClosure final_cl(_cm);
 131           sprintf(verbose_str, "GC remark");
 132           VM_CGC_Operation op(&final_cl, verbose_str);
 133           VMThread::execute(&op);
 134         }
 135         if (cm()->restart_for_overflow() &&
 136             G1TraceMarkStackOverflow) {
 137           gclog_or_tty->print_cr("Restarting conc marking because of MS overflow "
 138                                  "in remark (restart #%d).", iter);
 139         }
 140 
 141         if (cm()->restart_for_overflow()) {
 142           if (PrintGC) {
 143             gclog_or_tty->date_stamp(PrintGCDateStamps);
 144             gclog_or_tty->stamp(PrintGCTimeStamps);
 145             gclog_or_tty->print_cr("[GC concurrent-mark-restart-for-overflow]");
 146           }
 147         }
 148       } while (cm()->restart_for_overflow());

 149 
 150       // YSR: These look dubious (i.e. redundant) !!! FIX ME
 151       slt()->manipulatePLL(SurrogateLockerThread::acquirePLL);
 152       slt()->manipulatePLL(SurrogateLockerThread::releaseAndNotifyPLL);
 153 






















 154       double end_time = os::elapsedVTime();

 155       // Update the total virtual time before doing this, since it will try
 156       // to measure it to get the vtime for this marking.  We purposely
 157       // neglect the presumably-short "completeCleanup" phase here.
 158       _vtime_accum = (end_time - _vtime_start);
 159 
 160       if (!cm()->has_aborted()) {
 161         if (g1_policy->adaptive_young_list_length()) {
 162           double now = os::elapsedTime();
 163           double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
 164           jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
 165           os::sleep(current_thread, sleep_time_ms, false);
 166         }
 167 
 168         CMCleanUp cl_cl(_cm);
 169         sprintf(verbose_str, "GC cleanup");
 170         VM_CGC_Operation op(&cl_cl, verbose_str);
 171         VMThread::execute(&op);
 172       } else {
 173         g1h->set_marking_complete();
 174       }
 175 
 176       // Check if cleanup set the free_regions_coming flag. If it
 177       // hasn't, we can just skip the next step.
 178       if (g1h->free_regions_coming()) {
 179         // The following will finish freeing up any regions that we