Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp @ 1084:5f932a151fd4
6895788: G1: SATB and update buffer allocation code allocates too much space
Summary: The type in the NEW_C_HEAP_ARRRY and FREE_C_HEAP_ARRAY calls in the buffer allocation code was changed from void* to char as the size argument had already been mulitipled by the byte size of an object pointer.
Reviewed-by: ysr, tonyp
author | johnc |
---|---|
date | Fri, 06 Nov 2009 11:10:05 -0800 |
parents | 035d2e036a9b |
children | 44f61c24ddab |
rev | line source |
---|---|
342 | 1 /* |
844 | 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
342 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.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 | |
32 ConcurrentG1RefineThread:: | |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
33 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
34 int worker_id_offset, int worker_id) : |
342 | 35 ConcurrentGCThread(), |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
36 _worker_id_offset(worker_id_offset), |
794 | 37 _worker_id(worker_id), |
38 _active(false), | |
39 _next(next), | |
342 | 40 _cg1r(cg1r), |
41 _vtime_accum(0.0), | |
42 _interval_ms(5.0) | |
43 { | |
44 create_and_start(); | |
45 } | |
46 | |
47 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() { | |
48 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
49 G1CollectorPolicy* g1p = g1h->g1_policy(); | |
50 if (g1p->adaptive_young_list_length()) { | |
51 int regions_visited = 0; | |
52 | |
53 g1h->young_list_rs_length_sampling_init(); | |
54 while (g1h->young_list_rs_length_sampling_more()) { | |
55 g1h->young_list_rs_length_sampling_next(); | |
56 ++regions_visited; | |
57 | |
58 // we try to yield every time we visit 10 regions | |
59 if (regions_visited == 10) { | |
60 if (_sts.should_yield()) { | |
61 _sts.yield("G1 refine"); | |
62 // we just abandon the iteration | |
63 break; | |
64 } | |
65 regions_visited = 0; | |
66 } | |
67 } | |
68 | |
69 g1p->check_prediction_validity(); | |
70 } | |
71 } | |
72 | |
73 void ConcurrentG1RefineThread::run() { | |
74 initialize_in_thread(); | |
75 _vtime_start = os::elapsedVTime(); | |
76 wait_for_universe_init(); | |
77 | |
78 while (!_should_terminate) { | |
794 | 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(); | |
98 int n_logs = 0; | |
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 | |
883
27f6a9b9c311
6864886: G1: rename -XX parameters related to update buffers
tonyp
parents:
795
diff
changeset
|
103 int threshold = G1UpdateBufferQueueProcessingThreshold * _worker_id; |
794 | 104 // Next thread activation threshold |
883
27f6a9b9c311
6864886: G1: rename -XX parameters related to update buffers
tonyp
parents:
795
diff
changeset
|
105 int next_threshold = threshold + G1UpdateBufferQueueProcessingThreshold; |
27f6a9b9c311
6864886: G1: rename -XX parameters related to update buffers
tonyp
parents:
795
diff
changeset
|
106 int deactivation_threshold = MAX2<int>(threshold - G1UpdateBufferQueueProcessingThreshold / 2, 0); |
794 | 107 |
108 if (G1SmoothConcRefine) { | |
109 lower_limit = 0; | |
110 start_vtime_sec = os::elapsedVTime(); | |
111 prev_buffer_num = (int) dcqs.completed_buffers_num(); | |
342 | 112 } else { |
883
27f6a9b9c311
6864886: G1: rename -XX parameters related to update buffers
tonyp
parents:
795
diff
changeset
|
113 lower_limit = G1UpdateBufferQueueProcessingThreshold / 4; // For now. |
342 | 114 } |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
115 while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, lower_limit)) { |
794 | 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 } | |
342 | 166 _sts.leave(); |
794 | 167 |
342 | 168 if (os::supports_vtime()) { |
169 _vtime_accum = (os::elapsedVTime() - _vtime_start); | |
170 } else { | |
171 _vtime_accum = 0.0; | |
172 } | |
173 } | |
174 assert(_should_terminate, "just checking"); | |
175 | |
176 terminate(); | |
177 } | |
178 | |
179 | |
180 void ConcurrentG1RefineThread::yield() { | |
751 | 181 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield"); |
342 | 182 _sts.yield("G1 refine"); |
751 | 183 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield-end"); |
342 | 184 } |
185 | |
186 void ConcurrentG1RefineThread::stop() { | |
187 // it is ok to take late safepoints here, if needed | |
188 { | |
189 MutexLockerEx mu(Terminator_lock); | |
190 _should_terminate = true; | |
191 } | |
192 | |
193 { | |
194 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag); | |
195 DirtyCardQ_CBL_mon->notify_all(); | |
196 } | |
197 | |
198 { | |
199 MutexLockerEx mu(Terminator_lock); | |
200 while (!_has_terminated) { | |
201 Terminator_lock->wait(); | |
202 } | |
203 } | |
751 | 204 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-stop"); |
342 | 205 } |
206 | |
1019 | 207 void ConcurrentG1RefineThread::print() const { |
208 print_on(tty); | |
342 | 209 } |
1019 | 210 |
211 void ConcurrentG1RefineThread::print_on(outputStream* st) const { | |
212 st->print("\"G1 Concurrent Refinement Thread#%d\" ", _worker_id); | |
213 Thread::print_on(st); | |
214 st->cr(); | |
215 } |