Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp @ 1111:44f61c24ddab
6862387: tune concurrent refinement further
Summary: Reworked the concurrent refinement: threads activation, feedback-based threshold adjustment, other miscellaneous fixes.
Reviewed-by: apetrusenko, tonyp
author | iveresov |
---|---|
date | Wed, 16 Dec 2009 15:12:51 -0800 |
parents | 035d2e036a9b |
children | b81f3572f355 |
comparison
equal
deleted
inserted
replaced
1104:27f9477e879b | 1111:44f61c24ddab |
---|---|
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "incls/_precompiled.incl" | 25 #include "incls/_precompiled.incl" |
26 #include "incls/_concurrentG1RefineThread.cpp.incl" | 26 #include "incls/_concurrentG1RefineThread.cpp.incl" |
27 | |
28 // ======= Concurrent Mark Thread ======== | |
29 | |
30 // The CM thread is created when the G1 garbage collector is used | |
31 | 27 |
32 ConcurrentG1RefineThread:: | 28 ConcurrentG1RefineThread:: |
33 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, | 29 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
34 int worker_id_offset, int worker_id) : | 30 int worker_id_offset, int worker_id) : |
35 ConcurrentGCThread(), | 31 ConcurrentGCThread(), |
36 _worker_id_offset(worker_id_offset), | 32 _worker_id_offset(worker_id_offset), |
37 _worker_id(worker_id), | 33 _worker_id(worker_id), |
38 _active(false), | 34 _active(false), |
39 _next(next), | 35 _next(next), |
36 _monitor(NULL), | |
40 _cg1r(cg1r), | 37 _cg1r(cg1r), |
41 _vtime_accum(0.0), | 38 _vtime_accum(0.0) |
42 _interval_ms(5.0) | |
43 { | 39 { |
40 | |
41 // Each thread has its own monitor. The i-th thread is responsible for signalling | |
42 // to thread i+1 if the number of buffers in the queue exceeds a threashold for this | |
43 // thread. Monitors are also used to wake up the threads during termination. | |
44 // The 0th worker in notified by mutator threads and has a special monitor. | |
45 // The last worker is used for young gen rset size sampling. | |
46 if (worker_id > 0) { | |
47 _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true); | |
48 } else { | |
49 _monitor = DirtyCardQ_CBL_mon; | |
50 } | |
51 initialize(); | |
44 create_and_start(); | 52 create_and_start(); |
53 } | |
54 | |
55 void ConcurrentG1RefineThread::initialize() { | |
56 if (_worker_id < cg1r()->worker_thread_num()) { | |
57 // Current thread activation threshold | |
58 _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), | |
59 cg1r()->yellow_zone()); | |
60 // A thread deactivates once the number of buffer reached a deactivation threshold | |
61 _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); | |
62 } else { | |
63 set_active(true); | |
64 } | |
45 } | 65 } |
46 | 66 |
47 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { | 67 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { |
48 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | 68 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
49 G1CollectorPolicy* g1p = g1h->g1_policy(); | 69 G1CollectorPolicy* g1p = g1h->g1_policy(); |
50 if (g1p->adaptive_young_list_length()) { | 70 if (g1p->adaptive_young_list_length()) { |
51 int regions_visited = 0; | 71 int regions_visited = 0; |
52 | |
53 g1h->young_list_rs_length_sampling_init(); | 72 g1h->young_list_rs_length_sampling_init(); |
54 while (g1h->young_list_rs_length_sampling_more()) { | 73 while (g1h->young_list_rs_length_sampling_more()) { |
55 g1h->young_list_rs_length_sampling_next(); | 74 g1h->young_list_rs_length_sampling_next(); |
56 ++regions_visited; | 75 ++regions_visited; |
57 | 76 |
68 | 87 |
69 g1p->check_prediction_validity(); | 88 g1p->check_prediction_validity(); |
70 } | 89 } |
71 } | 90 } |
72 | 91 |
73 void ConcurrentG1RefineThread::run() { | 92 void ConcurrentG1RefineThread::run_young_rs_sampling() { |
74 initialize_in_thread(); | 93 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
75 _vtime_start = os::elapsedVTime(); | 94 _vtime_start = os::elapsedVTime(); |
76 wait_for_universe_init(); | 95 while(!_should_terminate) { |
77 | |
78 while (!_should_terminate) { | |
79 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
80 // Wait for completed log buffers to exist. | |
81 { | |
82 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); | |
83 while (((_worker_id == 0 && !dcqs.process_completed_buffers()) || | |
84 (_worker_id > 0 && !is_active())) && | |
85 !_should_terminate) { | |
86 DirtyCardQ_CBL_mon->wait(Mutex::_no_safepoint_check_flag); | |
87 } | |
88 } | |
89 | |
90 if (_should_terminate) { | |
91 return; | |
92 } | |
93 | |
94 // Now we take them off (this doesn't hold locks while it applies | |
95 // closures.) (If we did a full collection, then we'll do a full | |
96 // traversal. | |
97 _sts.join(); | 96 _sts.join(); |
98 int n_logs = 0; | 97 sample_young_list_rs_lengths(); |
99 int lower_limit = 0; | |
100 double start_vtime_sec; // only used when G1SmoothConcRefine is on | |
101 int prev_buffer_num; // only used when G1SmoothConcRefine is on | |
102 // This thread activation threshold | |
103 int threshold = G1UpdateBufferQueueProcessingThreshold * _worker_id; | |
104 // Next thread activation threshold | |
105 int next_threshold = threshold + G1UpdateBufferQueueProcessingThreshold; | |
106 int deactivation_threshold = MAX2<int>(threshold - G1UpdateBufferQueueProcessingThreshold / 2, 0); | |
107 | |
108 if (G1SmoothConcRefine) { | |
109 lower_limit = 0; | |
110 start_vtime_sec = os::elapsedVTime(); | |
111 prev_buffer_num = (int) dcqs.completed_buffers_num(); | |
112 } else { | |
113 lower_limit = G1UpdateBufferQueueProcessingThreshold / 4; // For now. | |
114 } | |
115 while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, lower_limit)) { | |
116 double end_vtime_sec; | |
117 double elapsed_vtime_sec; | |
118 int elapsed_vtime_ms; | |
119 int curr_buffer_num = (int) dcqs.completed_buffers_num(); | |
120 | |
121 if (G1SmoothConcRefine) { | |
122 end_vtime_sec = os::elapsedVTime(); | |
123 elapsed_vtime_sec = end_vtime_sec - start_vtime_sec; | |
124 elapsed_vtime_ms = (int) (elapsed_vtime_sec * 1000.0); | |
125 | |
126 if (curr_buffer_num > prev_buffer_num || | |
127 curr_buffer_num > next_threshold) { | |
128 decreaseInterval(elapsed_vtime_ms); | |
129 } else if (curr_buffer_num < prev_buffer_num) { | |
130 increaseInterval(elapsed_vtime_ms); | |
131 } | |
132 } | |
133 if (_worker_id == 0) { | |
134 sample_young_list_rs_lengths(); | |
135 } else if (curr_buffer_num < deactivation_threshold) { | |
136 // If the number of the buffer has fallen below our threshold | |
137 // we should deactivate. The predecessor will reactivate this | |
138 // thread should the number of the buffers cross the threshold again. | |
139 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); | |
140 deactivate(); | |
141 if (G1TraceConcurrentRefinement) { | |
142 gclog_or_tty->print_cr("G1-Refine-deactivated worker %d", _worker_id); | |
143 } | |
144 break; | |
145 } | |
146 | |
147 // Check if we need to activate the next thread. | |
148 if (curr_buffer_num > next_threshold && _next != NULL && !_next->is_active()) { | |
149 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); | |
150 _next->activate(); | |
151 DirtyCardQ_CBL_mon->notify_all(); | |
152 if (G1TraceConcurrentRefinement) { | |
153 gclog_or_tty->print_cr("G1-Refine-activated worker %d", _next->_worker_id); | |
154 } | |
155 } | |
156 | |
157 if (G1SmoothConcRefine) { | |
158 prev_buffer_num = curr_buffer_num; | |
159 _sts.leave(); | |
160 os::sleep(Thread::current(), (jlong) _interval_ms, false); | |
161 _sts.join(); | |
162 start_vtime_sec = os::elapsedVTime(); | |
163 } | |
164 n_logs++; | |
165 } | |
166 _sts.leave(); | 98 _sts.leave(); |
167 | 99 |
168 if (os::supports_vtime()) { | 100 if (os::supports_vtime()) { |
169 _vtime_accum = (os::elapsedVTime() - _vtime_start); | 101 _vtime_accum = (os::elapsedVTime() - _vtime_start); |
170 } else { | 102 } else { |
171 _vtime_accum = 0.0; | 103 _vtime_accum = 0.0; |
172 } | 104 } |
105 | |
106 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
107 if (_should_terminate) { | |
108 break; | |
109 } | |
110 _monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefineServiceInterval); | |
111 } | |
112 } | |
113 | |
114 void ConcurrentG1RefineThread::wait_for_completed_buffers() { | |
115 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
116 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
117 while (!_should_terminate && !is_active()) { | |
118 _monitor->wait(Mutex::_no_safepoint_check_flag); | |
119 } | |
120 } | |
121 | |
122 bool ConcurrentG1RefineThread::is_active() { | |
123 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
124 return _worker_id > 0 ? _active : dcqs.process_completed_buffers(); | |
125 } | |
126 | |
127 void ConcurrentG1RefineThread::activate() { | |
128 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
129 if (_worker_id > 0) { | |
130 if (G1TraceConcurrentRefinement) { | |
131 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
132 gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d", | |
133 _worker_id, _threshold, (int)dcqs.completed_buffers_num()); | |
134 } | |
135 set_active(true); | |
136 } else { | |
137 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
138 dcqs.set_process_completed(true); | |
139 } | |
140 _monitor->notify(); | |
141 } | |
142 | |
143 void ConcurrentG1RefineThread::deactivate() { | |
144 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); | |
145 if (_worker_id > 0) { | |
146 if (G1TraceConcurrentRefinement) { | |
147 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
148 gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d", | |
149 _worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num()); | |
150 } | |
151 set_active(false); | |
152 } else { | |
153 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
154 dcqs.set_process_completed(false); | |
155 } | |
156 } | |
157 | |
158 void ConcurrentG1RefineThread::run() { | |
159 initialize_in_thread(); | |
160 wait_for_universe_init(); | |
161 | |
162 if (_worker_id >= cg1r()->worker_thread_num()) { | |
163 run_young_rs_sampling(); | |
164 terminate(); | |
165 } | |
166 | |
167 _vtime_start = os::elapsedVTime(); | |
168 while (!_should_terminate) { | |
169 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); | |
170 | |
171 // Wait for work | |
172 wait_for_completed_buffers(); | |
173 | |
174 if (_should_terminate) { | |
175 break; | |
176 } | |
177 | |
178 _sts.join(); | |
179 | |
180 do { | |
181 int curr_buffer_num = (int)dcqs.completed_buffers_num(); | |
182 // If the number of the buffers falls down into the yellow zone, | |
183 // that means that the transition period after the evacuation pause has ended. | |
184 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { | |
185 dcqs.set_completed_queue_padding(0); | |
186 } | |
187 | |
188 if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) { | |
189 // If the number of the buffer has fallen below our threshold | |
190 // we should deactivate. The predecessor will reactivate this | |
191 // thread should the number of the buffers cross the threshold again. | |
192 deactivate(); | |
193 break; | |
194 } | |
195 | |
196 // Check if we need to activate the next thread. | |
197 if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { | |
198 _next->activate(); | |
199 } | |
200 } while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, cg1r()->green_zone())); | |
201 | |
202 // We can exit the loop above while being active if there was a yield request. | |
203 if (is_active()) { | |
204 deactivate(); | |
205 } | |
206 | |
207 _sts.leave(); | |
208 | |
209 if (os::supports_vtime()) { | |
210 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
211 } else { | |
212 _vtime_accum = 0.0; | |
213 } | |
173 } | 214 } |
174 assert(_should_terminate, "just checking"); | 215 assert(_should_terminate, "just checking"); |
175 | |
176 terminate(); | 216 terminate(); |
177 } | 217 } |
178 | 218 |
179 | 219 |
180 void ConcurrentG1RefineThread::yield() { | 220 void ConcurrentG1RefineThread::yield() { |
189 MutexLockerEx mu(Terminator_lock); | 229 MutexLockerEx mu(Terminator_lock); |
190 _should_terminate = true; | 230 _should_terminate = true; |
191 } | 231 } |
192 | 232 |
193 { | 233 { |
194 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); | 234 MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
195 DirtyCardQ_CBL_mon->notify_all(); | 235 _monitor->notify(); |
196 } | 236 } |
197 | 237 |
198 { | 238 { |
199 MutexLockerEx mu(Terminator_lock); | 239 MutexLockerEx mu(Terminator_lock); |
200 while (!_has_terminated) { | 240 while (!_has_terminated) { |