50 51 // Each thread has its own monitor. The i-th thread is responsible for signaling 52 // to thread i+1 if the number of buffers in the queue exceeds a threshold for this 53 // thread. Monitors are also used to wake up the threads during termination. 54 // The 0th (primary) worker is notified by mutator threads and has a special monitor. 55 if (!is_primary()) { 56 _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true, 57 Monitor::_safepoint_check_never); 58 } else { 59 _monitor = DirtyCardQ_CBL_mon; 60 } 61 initialize(); 62 63 // set name 64 set_name("G1 Refine#%d", worker_id); 65 create_and_start(); 66 } 67 68 void ConcurrentG1RefineThread::initialize() { 69 // Current thread activation threshold 70 _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), 71 cg1r()->yellow_zone()); 72 // A thread deactivates once the number of buffer reached a deactivation threshold 73 _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); 74 } 75 76 void ConcurrentG1RefineThread::wait_for_completed_buffers() { 77 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 78 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 79 while (!_should_terminate && !is_active()) { 80 _monitor->wait(Mutex::_no_safepoint_check_flag); 81 } 82 } 83 84 bool ConcurrentG1RefineThread::is_active() { 85 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 86 return is_primary() ? dcqs.process_completed_buffers() : _active; 87 } 88 89 void ConcurrentG1RefineThread::activate() { 90 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 91 if (!is_primary()) { 92 set_active(true); 93 } else { 110 void ConcurrentG1RefineThread::run() { 111 initialize_in_thread(); 112 wait_for_universe_init(); 113 114 run_service(); 115 116 terminate(); 117 } 118 119 void ConcurrentG1RefineThread::run_service() { 120 _vtime_start = os::elapsedVTime(); 121 122 while (!_should_terminate) { 123 // Wait for work 124 wait_for_completed_buffers(); 125 if (_should_terminate) { 126 break; 127 } 128 129 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 130 log_debug(gc, refine)("Activated %d, on threshold: %d, current: %d", 131 _worker_id, _threshold, dcqs.completed_buffers_num()); 132 133 { 134 SuspendibleThreadSetJoiner sts_join; 135 136 do { 137 int curr_buffer_num = (int)dcqs.completed_buffers_num(); 138 // If the number of the buffers falls down into the yellow zone, 139 // that means that the transition period after the evacuation pause has ended. 140 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { 141 dcqs.set_completed_queue_padding(0); 142 } 143 144 // Check if we need to activate the next thread. 145 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { 146 _next->activate(); 147 } 148 } while (dcqs.apply_closure_to_completed_buffer(_refine_closure, 149 _worker_id + _worker_id_offset, 150 _deactivation_threshold, 151 false /* during_pause */)); 152 153 deactivate(); 154 log_debug(gc, refine)("Deactivated %d, off threshold: %d, current: %d", 155 _worker_id, _deactivation_threshold, 156 dcqs.completed_buffers_num()); 157 } 158 159 if (os::supports_vtime()) { 160 _vtime_accum = (os::elapsedVTime() - _vtime_start); 161 } else { 162 _vtime_accum = 0.0; 163 } 164 } 165 166 log_debug(gc, refine)("Stopping %d", _worker_id); 167 } 168 169 void ConcurrentG1RefineThread::stop() { 170 // it is ok to take late safepoints here, if needed 171 { 172 MutexLockerEx mu(Terminator_lock); 173 _should_terminate = true; 174 } | 50 51 // Each thread has its own monitor. The i-th thread is responsible for signaling 52 // to thread i+1 if the number of buffers in the queue exceeds a threshold for this 53 // thread. Monitors are also used to wake up the threads during termination. 54 // The 0th (primary) worker is notified by mutator threads and has a special monitor. 55 if (!is_primary()) { 56 _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true, 57 Monitor::_safepoint_check_never); 58 } else { 59 _monitor = DirtyCardQ_CBL_mon; 60 } 61 initialize(); 62 63 // set name 64 set_name("G1 Refine#%d", worker_id); 65 create_and_start(); 66 } 67 68 void ConcurrentG1RefineThread::initialize() { 69 // Current thread activation threshold 70 _threshold = MIN2(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), 71 cg1r()->yellow_zone()); 72 // A thread deactivates once the number of buffer reached a deactivation threshold 73 _deactivation_threshold = 74 MAX2(_threshold - MIN2(_threshold, cg1r()->thread_threshold_step()), 75 cg1r()->green_zone()); 76 } 77 78 void ConcurrentG1RefineThread::wait_for_completed_buffers() { 79 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 80 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 81 while (!_should_terminate && !is_active()) { 82 _monitor->wait(Mutex::_no_safepoint_check_flag); 83 } 84 } 85 86 bool ConcurrentG1RefineThread::is_active() { 87 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 88 return is_primary() ? dcqs.process_completed_buffers() : _active; 89 } 90 91 void ConcurrentG1RefineThread::activate() { 92 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 93 if (!is_primary()) { 94 set_active(true); 95 } else { 112 void ConcurrentG1RefineThread::run() { 113 initialize_in_thread(); 114 wait_for_universe_init(); 115 116 run_service(); 117 118 terminate(); 119 } 120 121 void ConcurrentG1RefineThread::run_service() { 122 _vtime_start = os::elapsedVTime(); 123 124 while (!_should_terminate) { 125 // Wait for work 126 wait_for_completed_buffers(); 127 if (_should_terminate) { 128 break; 129 } 130 131 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 132 log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT, 133 _worker_id, _threshold, dcqs.completed_buffers_num()); 134 135 { 136 SuspendibleThreadSetJoiner sts_join; 137 138 do { 139 size_t curr_buffer_num = dcqs.completed_buffers_num(); 140 // If the number of the buffers falls down into the yellow zone, 141 // that means that the transition period after the evacuation pause has ended. 142 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { 143 dcqs.set_completed_queue_padding(0); 144 } 145 146 // Check if we need to activate the next thread. 147 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { 148 _next->activate(); 149 } 150 } while (dcqs.apply_closure_to_completed_buffer(_refine_closure, 151 _worker_id + _worker_id_offset, 152 _deactivation_threshold, 153 false /* during_pause */)); 154 155 deactivate(); 156 log_debug(gc, refine)("Deactivated %d, off threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT, 157 _worker_id, _deactivation_threshold, 158 dcqs.completed_buffers_num()); 159 } 160 161 if (os::supports_vtime()) { 162 _vtime_accum = (os::elapsedVTime() - _vtime_start); 163 } else { 164 _vtime_accum = 0.0; 165 } 166 } 167 168 log_debug(gc, refine)("Stopping %d", _worker_id); 169 } 170 171 void ConcurrentG1RefineThread::stop() { 172 // it is ok to take late safepoints here, if needed 173 { 174 MutexLockerEx mu(Terminator_lock); 175 _should_terminate = true; 176 } |