< prev index next >

src/hotspot/share/gc/cms/concurrentMarkSweepThread.cpp

Print this page




 214   set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
 215   CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis);
 216   clear_CMS_flag(CMS_cms_wants_token);
 217   assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
 218          "Should not be set");
 219 }
 220 
 221 // Wait until the next synchronous GC, a concurrent full gc request,
 222 // or a timeout, whichever is earlier.
 223 void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) {
 224   // Wait time in millis or 0 value representing infinite wait for a scavenge
 225   assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
 226 
 227   CMSHeap* heap = CMSHeap::heap();
 228   double start_time_secs = os::elapsedTime();
 229   double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
 230 
 231   // Total collections count before waiting loop
 232   unsigned int before_count;
 233   {
 234     MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
 235     before_count = heap->total_collections();
 236   }
 237 
 238   unsigned int loop_count = 0;
 239 
 240   while(!should_terminate()) {
 241     double now_time = os::elapsedTime();
 242     long wait_time_millis;
 243 
 244     if(t_millis != 0) {
 245       // New wait limit
 246       wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS);
 247       if(wait_time_millis <= 0) {
 248         // Wait time is over
 249         break;
 250       }
 251     } else {
 252       // No wait limit, wait if necessary forever
 253       wait_time_millis = 0;
 254     }


 260       if (should_terminate() || _collector->_full_gc_requested) {
 261         return;
 262       }
 263       set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
 264       assert(t_millis == 0 || wait_time_millis > 0, "Sanity");
 265       CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis);
 266       clear_CMS_flag(CMS_cms_wants_token);
 267       assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
 268              "Should not be set");
 269     }
 270 
 271     // Extra wait time check before entering the heap lock to get the collection count
 272     if(t_millis != 0 && os::elapsedTime() >= end_time_secs) {
 273       // Wait time is over
 274       break;
 275     }
 276 
 277     // Total collections count after the event
 278     unsigned int after_count;
 279     {
 280       MutexLockerEx hl(Heap_lock, Mutex::_no_safepoint_check_flag);
 281       after_count = heap->total_collections();
 282     }
 283 
 284     if(before_count != after_count) {
 285       // There was a collection - success
 286       break;
 287     }
 288 
 289     // Too many loops warning
 290     if(++loop_count == 0) {
 291       log_warning(gc)("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1);
 292     }
 293   }
 294 }
 295 
 296 void ConcurrentMarkSweepThread::sleepBeforeNextCycle() {
 297   while (!should_terminate()) {
 298     if(CMSWaitDuration >= 0) {
 299       // Wait until the next synchronous GC, a concurrent full gc
 300       // request or a timeout, whichever is earlier.


 214   set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
 215   CGC_lock->wait(Mutex::_no_safepoint_check_flag, t_millis);
 216   clear_CMS_flag(CMS_cms_wants_token);
 217   assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
 218          "Should not be set");
 219 }
 220 
 221 // Wait until the next synchronous GC, a concurrent full gc request,
 222 // or a timeout, whichever is earlier.
 223 void ConcurrentMarkSweepThread::wait_on_cms_lock_for_scavenge(long t_millis) {
 224   // Wait time in millis or 0 value representing infinite wait for a scavenge
 225   assert(t_millis >= 0, "Wait time for scavenge should be 0 or positive");
 226 
 227   CMSHeap* heap = CMSHeap::heap();
 228   double start_time_secs = os::elapsedTime();
 229   double end_time_secs = start_time_secs + (t_millis / ((double) MILLIUNITS));
 230 
 231   // Total collections count before waiting loop
 232   unsigned int before_count;
 233   {
 234     MutexLocker hl(Heap_lock);
 235     before_count = heap->total_collections();
 236   }
 237 
 238   unsigned int loop_count = 0;
 239 
 240   while(!should_terminate()) {
 241     double now_time = os::elapsedTime();
 242     long wait_time_millis;
 243 
 244     if(t_millis != 0) {
 245       // New wait limit
 246       wait_time_millis = (long) ((end_time_secs - now_time) * MILLIUNITS);
 247       if(wait_time_millis <= 0) {
 248         // Wait time is over
 249         break;
 250       }
 251     } else {
 252       // No wait limit, wait if necessary forever
 253       wait_time_millis = 0;
 254     }


 260       if (should_terminate() || _collector->_full_gc_requested) {
 261         return;
 262       }
 263       set_CMS_flag(CMS_cms_wants_token);   // to provoke notifies
 264       assert(t_millis == 0 || wait_time_millis > 0, "Sanity");
 265       CGC_lock->wait(Mutex::_no_safepoint_check_flag, wait_time_millis);
 266       clear_CMS_flag(CMS_cms_wants_token);
 267       assert(!CMS_flag_is_set(CMS_cms_has_token | CMS_cms_wants_token),
 268              "Should not be set");
 269     }
 270 
 271     // Extra wait time check before entering the heap lock to get the collection count
 272     if(t_millis != 0 && os::elapsedTime() >= end_time_secs) {
 273       // Wait time is over
 274       break;
 275     }
 276 
 277     // Total collections count after the event
 278     unsigned int after_count;
 279     {
 280       MutexLocker hl(Heap_lock);
 281       after_count = heap->total_collections();
 282     }
 283 
 284     if(before_count != after_count) {
 285       // There was a collection - success
 286       break;
 287     }
 288 
 289     // Too many loops warning
 290     if(++loop_count == 0) {
 291       log_warning(gc)("wait_on_cms_lock_for_scavenge() has looped %u times", loop_count - 1);
 292     }
 293   }
 294 }
 295 
 296 void ConcurrentMarkSweepThread::sleepBeforeNextCycle() {
 297   while (!should_terminate()) {
 298     if(CMSWaitDuration >= 0) {
 299       // Wait until the next synchronous GC, a concurrent full gc
 300       // request or a timeout, whichever is earlier.
< prev index next >