< prev index next >

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

Print this page
rev 8331 : 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
Reviewed-by:


 175       double end_time = os::elapsedVTime();
 176       // Update the total virtual time before doing this, since it will try
 177       // to measure it to get the vtime for this marking.  We purposely
 178       // neglect the presumably-short "completeCleanup" phase here.
 179       _vtime_accum = (end_time - _vtime_start);
 180 
 181       if (!cm()->has_aborted()) {
 182         if (g1_policy->adaptive_young_list_length()) {
 183           double now = os::elapsedTime();
 184           double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
 185           jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
 186           os::sleep(current_thread, sleep_time_ms, false);
 187         }
 188 
 189         CMCleanUp cl_cl(_cm);
 190         VM_CGC_Operation op(&cl_cl, "GC cleanup", false /* needs_pll */);
 191         VMThread::execute(&op);
 192       } else {
 193         // We don't want to update the marking status if a GC pause
 194         // is already underway.
 195         SuspendibleThreadSetJoiner sts;
 196         g1h->set_marking_complete();
 197       }
 198 
 199       // Check if cleanup set the free_regions_coming flag. If it
 200       // hasn't, we can just skip the next step.
 201       if (g1h->free_regions_coming()) {
 202         // The following will finish freeing up any regions that we
 203         // found to be empty during cleanup. We'll do this part
 204         // without joining the suspendible set. If an evacuation pause
 205         // takes place, then we would carry on freeing regions in
 206         // case they are needed by the pause. If a Full GC takes
 207         // place, it would wait for us to process the regions
 208         // reclaimed by cleanup.
 209 
 210         double cleanup_start_sec = os::elapsedTime();
 211         if (G1Log::fine()) {
 212           gclog_or_tty->gclog_stamp(cm()->concurrent_gc_id());
 213           gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
 214         }
 215 


 245       // the method that will reset the concurrent mark state. If we
 246       // end up calling record_concurrent_mark_cleanup_completed()
 247       // after abort() then we might incorrectly undo some of the work
 248       // abort() did. Checking the has_aborted() flag after joining
 249       // the STS allows the correct ordering of the two methods. There
 250       // are two scenarios:
 251       //
 252       // a) If we reach here before the Full GC, the fact that we have
 253       // joined the STS means that the Full GC cannot start until we
 254       // leave the STS, so record_concurrent_mark_cleanup_completed()
 255       // will complete before abort() is called.
 256       //
 257       // b) If we reach here during the Full GC, we'll be held up from
 258       // joining the STS until the Full GC is done, which means that
 259       // abort() will have completed and has_aborted() will return
 260       // true to prevent us from calling
 261       // record_concurrent_mark_cleanup_completed() (and, in fact, it's
 262       // not needed any more as the concurrent mark state has been
 263       // already reset).
 264       {
 265         SuspendibleThreadSetJoiner sts;
 266         if (!cm()->has_aborted()) {
 267           g1_policy->record_concurrent_mark_cleanup_completed();
 268         }
 269       }
 270 
 271       if (cm()->has_aborted()) {
 272         if (G1Log::fine()) {
 273           gclog_or_tty->gclog_stamp(cm()->concurrent_gc_id());
 274           gclog_or_tty->print_cr("[GC concurrent-mark-abort]");
 275         }
 276       }
 277 
 278       // We now want to allow clearing of the marking bitmap to be
 279       // suspended by a collection pause.
 280       // We may have aborted just before the remark. Do not bother clearing the
 281       // bitmap then, as it has been done during mark abort.
 282       if (!cm()->has_aborted()) {
 283         _cm->clearNextBitmap();
 284       } else {
 285         assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear");
 286       }
 287     }
 288 
 289     // Update the number of full collections that have been
 290     // completed. This will also notify the FullGCCount_lock in case a
 291     // Java thread is waiting for a full GC to happen (e.g., it
 292     // called System.gc() with +ExplicitGCInvokesConcurrent).
 293     {
 294       SuspendibleThreadSetJoiner sts;
 295       g1h->increment_old_marking_cycles_completed(true /* concurrent */);
 296       g1h->register_concurrent_cycle_end();
 297     }
 298   }
 299   assert(_should_terminate, "just checking");
 300 
 301   terminate();
 302 }
 303 
 304 void ConcurrentMarkThread::stop() {
 305   {
 306     MutexLockerEx ml(Terminator_lock);
 307     _should_terminate = true;
 308   }
 309 
 310   {
 311     MutexLockerEx ml(CGC_lock, Mutex::_no_safepoint_check_flag);
 312     CGC_lock->notify_all();
 313   }
 314 




 175       double end_time = os::elapsedVTime();
 176       // Update the total virtual time before doing this, since it will try
 177       // to measure it to get the vtime for this marking.  We purposely
 178       // neglect the presumably-short "completeCleanup" phase here.
 179       _vtime_accum = (end_time - _vtime_start);
 180 
 181       if (!cm()->has_aborted()) {
 182         if (g1_policy->adaptive_young_list_length()) {
 183           double now = os::elapsedTime();
 184           double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
 185           jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
 186           os::sleep(current_thread, sleep_time_ms, false);
 187         }
 188 
 189         CMCleanUp cl_cl(_cm);
 190         VM_CGC_Operation op(&cl_cl, "GC cleanup", false /* needs_pll */);
 191         VMThread::execute(&op);
 192       } else {
 193         // We don't want to update the marking status if a GC pause
 194         // is already underway.
 195         SuspendibleThreadSetJoiner sts_join;
 196         g1h->set_marking_complete();
 197       }
 198 
 199       // Check if cleanup set the free_regions_coming flag. If it
 200       // hasn't, we can just skip the next step.
 201       if (g1h->free_regions_coming()) {
 202         // The following will finish freeing up any regions that we
 203         // found to be empty during cleanup. We'll do this part
 204         // without joining the suspendible set. If an evacuation pause
 205         // takes place, then we would carry on freeing regions in
 206         // case they are needed by the pause. If a Full GC takes
 207         // place, it would wait for us to process the regions
 208         // reclaimed by cleanup.
 209 
 210         double cleanup_start_sec = os::elapsedTime();
 211         if (G1Log::fine()) {
 212           gclog_or_tty->gclog_stamp(cm()->concurrent_gc_id());
 213           gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
 214         }
 215 


 245       // the method that will reset the concurrent mark state. If we
 246       // end up calling record_concurrent_mark_cleanup_completed()
 247       // after abort() then we might incorrectly undo some of the work
 248       // abort() did. Checking the has_aborted() flag after joining
 249       // the STS allows the correct ordering of the two methods. There
 250       // are two scenarios:
 251       //
 252       // a) If we reach here before the Full GC, the fact that we have
 253       // joined the STS means that the Full GC cannot start until we
 254       // leave the STS, so record_concurrent_mark_cleanup_completed()
 255       // will complete before abort() is called.
 256       //
 257       // b) If we reach here during the Full GC, we'll be held up from
 258       // joining the STS until the Full GC is done, which means that
 259       // abort() will have completed and has_aborted() will return
 260       // true to prevent us from calling
 261       // record_concurrent_mark_cleanup_completed() (and, in fact, it's
 262       // not needed any more as the concurrent mark state has been
 263       // already reset).
 264       {
 265         SuspendibleThreadSetJoiner sts_join;
 266         if (!cm()->has_aborted()) {
 267           g1_policy->record_concurrent_mark_cleanup_completed();
 268         }
 269       }
 270 
 271       if (cm()->has_aborted()) {
 272         if (G1Log::fine()) {
 273           gclog_or_tty->gclog_stamp(cm()->concurrent_gc_id());
 274           gclog_or_tty->print_cr("[GC concurrent-mark-abort]");
 275         }
 276       }
 277 
 278       // We now want to allow clearing of the marking bitmap to be
 279       // suspended by a collection pause.
 280       // We may have aborted just before the remark. Do not bother clearing the
 281       // bitmap then, as it has been done during mark abort.
 282       if (!cm()->has_aborted()) {
 283         _cm->clearNextBitmap();
 284       } else {
 285         assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear");
 286       }
 287     }
 288 
 289     // Update the number of full collections that have been
 290     // completed. This will also notify the FullGCCount_lock in case a
 291     // Java thread is waiting for a full GC to happen (e.g., it
 292     // called System.gc() with +ExplicitGCInvokesConcurrent).
 293     {
 294       SuspendibleThreadSetJoiner sts_join;
 295       g1h->increment_old_marking_cycles_completed(true /* concurrent */);
 296       g1h->register_concurrent_cycle_end();
 297     }
 298   }
 299   assert(_should_terminate, "just checking");
 300 
 301   terminate();
 302 }
 303 
 304 void ConcurrentMarkThread::stop() {
 305   {
 306     MutexLockerEx ml(Terminator_lock);
 307     _should_terminate = true;
 308   }
 309 
 310   {
 311     MutexLockerEx ml(CGC_lock, Mutex::_no_safepoint_check_flag);
 312     CGC_lock->notify_all();
 313   }
 314 


< prev index next >