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 log_debug(gc, refine)("G1-Refine-activated worker %d, on threshold %d, current %d", 93 _worker_id, _threshold, JavaThread::dirty_card_queue_set().completed_buffers_num()); 94 set_active(true); 95 } else { 96 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 97 dcqs.set_process_completed(true); 98 } 99 _monitor->notify(); 100 } 101 102 void ConcurrentG1RefineThread::deactivate() { 103 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 104 if (!is_primary()) { 105 log_debug(gc, refine)("G1-Refine-deactivated worker %d, off threshold %d, current %d", 106 _worker_id, _deactivation_threshold, JavaThread::dirty_card_queue_set().completed_buffers_num()); 107 set_active(false); 108 } else { 109 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 110 dcqs.set_process_completed(false); 111 } 112 } 113 114 void ConcurrentG1RefineThread::run() { 115 initialize_in_thread(); 116 wait_for_universe_init(); 117 118 run_service(); 119 120 terminate(); 121 } 122 123 void ConcurrentG1RefineThread::run_service() { 124 _vtime_start = os::elapsedVTime(); 125 126 while (!_should_terminate) { 127 // Wait for work 128 wait_for_completed_buffers(); 129 if (_should_terminate) { 130 break; 131 } 132 133 { 134 SuspendibleThreadSetJoiner sts_join; 135 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 136 137 do { 138 int curr_buffer_num = (int)dcqs.completed_buffers_num(); 139 // If the number of the buffers falls down into the yellow zone, 140 // that means that the transition period after the evacuation pause has ended. 141 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { 142 dcqs.set_completed_queue_padding(0); 143 } 144 145 if (!is_primary() && curr_buffer_num <= _deactivation_threshold) { 146 // If the number of the buffer has fallen below our threshold 147 // we should deactivate. The predecessor will reactivate this 148 // thread should the number of the buffers cross the threshold again. 149 deactivate(); 150 break; 151 } 152 153 // Check if we need to activate the next thread. 154 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { 155 _next->activate(); 156 } 157 } while (dcqs.apply_closure_to_completed_buffer(_refine_closure, 158 _worker_id + _worker_id_offset, | 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 = MAX2(_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 log_debug(gc, refine)("G1-Refine-activated worker %d, on threshold " SIZE_FORMAT ", current " SIZE_FORMAT, 93 _worker_id, _threshold, JavaThread::dirty_card_queue_set().completed_buffers_num()); 94 set_active(true); 95 } else { 96 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 97 dcqs.set_process_completed(true); 98 } 99 _monitor->notify(); 100 } 101 102 void ConcurrentG1RefineThread::deactivate() { 103 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); 104 if (!is_primary()) { 105 log_debug(gc, refine)("G1-Refine-deactivated worker %d, off threshold " SIZE_FORMAT ", current " SIZE_FORMAT, 106 _worker_id, _deactivation_threshold, JavaThread::dirty_card_queue_set().completed_buffers_num()); 107 set_active(false); 108 } else { 109 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 110 dcqs.set_process_completed(false); 111 } 112 } 113 114 void ConcurrentG1RefineThread::run() { 115 initialize_in_thread(); 116 wait_for_universe_init(); 117 118 run_service(); 119 120 terminate(); 121 } 122 123 void ConcurrentG1RefineThread::run_service() { 124 _vtime_start = os::elapsedVTime(); 125 126 while (!_should_terminate) { 127 // Wait for work 128 wait_for_completed_buffers(); 129 if (_should_terminate) { 130 break; 131 } 132 133 { 134 SuspendibleThreadSetJoiner sts_join; 135 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 136 137 do { 138 size_t curr_buffer_num = dcqs.completed_buffers_num(); 139 // If the number of the buffers falls down into the yellow zone, 140 // that means that the transition period after the evacuation pause has ended. 141 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { 142 dcqs.set_completed_queue_padding(0); 143 } 144 145 if (!is_primary() && curr_buffer_num <= _deactivation_threshold) { 146 // If the number of the buffer has fallen below our threshold 147 // we should deactivate. The predecessor will reactivate this 148 // thread should the number of the buffers cross the threshold again. 149 deactivate(); 150 break; 151 } 152 153 // Check if we need to activate the next thread. 154 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { 155 _next->activate(); 156 } 157 } while (dcqs.apply_closure_to_completed_buffer(_refine_closure, 158 _worker_id + _worker_id_offset, |