342
|
1 /*
|
|
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
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/_concurrentG1Refine.cpp.incl"
|
|
27
|
|
28 ConcurrentG1Refine::ConcurrentG1Refine() :
|
|
29 _card_counts(NULL), _cur_card_count_histo(NULL), _cum_card_count_histo(NULL),
|
|
30 _hot_cache(NULL),
|
|
31 _def_use_cache(false), _use_cache(false),
|
794
|
32 _n_periods(0), _total_cards(0), _total_travs(0),
|
|
33 _threads(NULL), _n_threads(0)
|
342
|
34 {
|
|
35 if (G1ConcRefine) {
|
794
|
36 _n_threads = (G1ParallelRSetThreads > 0) ? G1ParallelRSetThreads : ParallelGCThreads;
|
|
37 if (_n_threads > 0) {
|
|
38 _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads);
|
|
39 ConcurrentG1RefineThread *next = NULL;
|
|
40 for (int i = _n_threads - 1; i >= 0; i--) {
|
|
41 ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, i);
|
|
42 assert(t != NULL, "Conc refine should have been created");
|
|
43 assert(t->cg1r() == this, "Conc refine thread should refer to this");
|
|
44 _threads[i] = t;
|
|
45 next = t;
|
|
46 }
|
|
47 }
|
342
|
48 }
|
|
49 }
|
|
50
|
|
51 void ConcurrentG1Refine::init() {
|
|
52 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
|
|
53 G1CollectedHeap* g1h = G1CollectedHeap::heap();
|
|
54 _n_card_counts =
|
|
55 (unsigned) (g1h->g1_reserved_obj_bytes() >> CardTableModRefBS::card_shift);
|
|
56 _card_counts = NEW_C_HEAP_ARRAY(unsigned char, _n_card_counts);
|
|
57 for (size_t i = 0; i < _n_card_counts; i++) _card_counts[i] = 0;
|
|
58 ModRefBarrierSet* bs = g1h->mr_bs();
|
|
59 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
|
|
60 CardTableModRefBS* ctbs = (CardTableModRefBS*)bs;
|
|
61 _ct_bot = ctbs->byte_for_const(g1h->reserved_region().start());
|
|
62 if (G1ConcRSCountTraversals) {
|
|
63 _cur_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
|
|
64 _cum_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
|
|
65 for (int i = 0; i < 256; i++) {
|
|
66 _cur_card_count_histo[i] = 0;
|
|
67 _cum_card_count_histo[i] = 0;
|
|
68 }
|
|
69 }
|
|
70 }
|
|
71 if (G1ConcRSLogCacheSize > 0) {
|
|
72 _def_use_cache = true;
|
|
73 _use_cache = true;
|
|
74 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
|
|
75 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size);
|
|
76 _n_hot = 0;
|
|
77 _hot_cache_idx = 0;
|
|
78 }
|
|
79 }
|
|
80
|
794
|
81 void ConcurrentG1Refine::stop() {
|
|
82 if (_threads != NULL) {
|
|
83 for (int i = 0; i < _n_threads; i++) {
|
|
84 _threads[i]->stop();
|
|
85 }
|
|
86 }
|
|
87 }
|
|
88
|
342
|
89 ConcurrentG1Refine::~ConcurrentG1Refine() {
|
|
90 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
|
|
91 assert(_card_counts != NULL, "Logic");
|
|
92 FREE_C_HEAP_ARRAY(unsigned char, _card_counts);
|
|
93 assert(_cur_card_count_histo != NULL, "Logic");
|
|
94 FREE_C_HEAP_ARRAY(unsigned, _cur_card_count_histo);
|
|
95 assert(_cum_card_count_histo != NULL, "Logic");
|
|
96 FREE_C_HEAP_ARRAY(unsigned, _cum_card_count_histo);
|
|
97 }
|
|
98 if (G1ConcRSLogCacheSize > 0) {
|
|
99 assert(_hot_cache != NULL, "Logic");
|
|
100 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
|
|
101 }
|
794
|
102 if (_threads != NULL) {
|
|
103 for (int i = 0; i < _n_threads; i++) {
|
|
104 delete _threads[i];
|
|
105 }
|
|
106 FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads);
|
342
|
107 }
|
|
108 }
|
|
109
|
794
|
110 void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
|
|
111 if (_threads != NULL) {
|
|
112 for (int i = 0; i < _n_threads; i++) {
|
|
113 tc->do_thread(_threads[i]);
|
|
114 }
|
342
|
115 }
|
|
116 }
|
|
117
|
|
118
|
|
119 int ConcurrentG1Refine::add_card_count(jbyte* card_ptr) {
|
|
120 size_t card_num = (card_ptr - _ct_bot);
|
|
121 guarantee(0 <= card_num && card_num < _n_card_counts, "Bounds");
|
|
122 unsigned char cnt = _card_counts[card_num];
|
|
123 if (cnt < 255) _card_counts[card_num]++;
|
|
124 return cnt;
|
|
125 _total_travs++;
|
|
126 }
|
|
127
|
|
128 jbyte* ConcurrentG1Refine::cache_insert(jbyte* card_ptr) {
|
|
129 int count = add_card_count(card_ptr);
|
|
130 // Count previously unvisited cards.
|
|
131 if (count == 0) _total_cards++;
|
|
132 // We'll assume a traversal unless we store it in the cache.
|
|
133 if (count < G1ConcRSHotCardLimit) {
|
|
134 _total_travs++;
|
|
135 return card_ptr;
|
|
136 }
|
|
137 // Otherwise, it's hot.
|
|
138 jbyte* res = NULL;
|
|
139 MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
|
|
140 if (_n_hot == _hot_cache_size) {
|
|
141 _total_travs++;
|
|
142 res = _hot_cache[_hot_cache_idx];
|
|
143 _n_hot--;
|
|
144 }
|
|
145 // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
|
|
146 _hot_cache[_hot_cache_idx] = card_ptr;
|
|
147 _hot_cache_idx++;
|
|
148 if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0;
|
|
149 _n_hot++;
|
|
150 return res;
|
|
151 }
|
|
152
|
|
153
|
|
154 void ConcurrentG1Refine::clean_up_cache(int worker_i, G1RemSet* g1rs) {
|
|
155 assert(!use_cache(), "cache should be disabled");
|
|
156 int start_ind = _hot_cache_idx-1;
|
|
157 for (int i = 0; i < _n_hot; i++) {
|
|
158 int ind = start_ind - i;
|
|
159 if (ind < 0) ind = ind + _hot_cache_size;
|
|
160 jbyte* entry = _hot_cache[ind];
|
|
161 if (entry != NULL) {
|
|
162 g1rs->concurrentRefineOneCard(entry, worker_i);
|
|
163 }
|
|
164 }
|
|
165 _n_hot = 0;
|
|
166 _hot_cache_idx = 0;
|
|
167 }
|
|
168
|
|
169 void ConcurrentG1Refine::clear_and_record_card_counts() {
|
|
170 if (G1ConcRSLogCacheSize == 0 && !G1ConcRSCountTraversals) return;
|
|
171 _n_periods++;
|
|
172 if (G1ConcRSCountTraversals) {
|
|
173 for (size_t i = 0; i < _n_card_counts; i++) {
|
|
174 unsigned char bucket = _card_counts[i];
|
|
175 _cur_card_count_histo[bucket]++;
|
|
176 _card_counts[i] = 0;
|
|
177 }
|
|
178 gclog_or_tty->print_cr("Card counts:");
|
|
179 for (int i = 0; i < 256; i++) {
|
|
180 if (_cur_card_count_histo[i] > 0) {
|
|
181 gclog_or_tty->print_cr(" %3d: %9d", i, _cur_card_count_histo[i]);
|
|
182 _cum_card_count_histo[i] += _cur_card_count_histo[i];
|
|
183 _cur_card_count_histo[i] = 0;
|
|
184 }
|
|
185 }
|
|
186 } else {
|
|
187 assert(G1ConcRSLogCacheSize > 0, "Logic");
|
|
188 Copy::fill_to_words((HeapWord*)(&_card_counts[0]),
|
|
189 _n_card_counts / HeapWordSize);
|
|
190 }
|
|
191 }
|
|
192
|
|
193 void
|
|
194 ConcurrentG1Refine::
|
|
195 print_card_count_histo_range(unsigned* histo, int from, int to,
|
|
196 float& cum_card_pct,
|
|
197 float& cum_travs_pct) {
|
|
198 unsigned cards = 0;
|
|
199 unsigned travs = 0;
|
|
200 guarantee(to <= 256, "Precondition");
|
|
201 for (int i = from; i < to-1; i++) {
|
|
202 cards += histo[i];
|
|
203 travs += histo[i] * i;
|
|
204 }
|
|
205 if (to == 256) {
|
|
206 unsigned histo_card_sum = 0;
|
|
207 unsigned histo_trav_sum = 0;
|
|
208 for (int i = 1; i < 255; i++) {
|
|
209 histo_trav_sum += histo[i] * i;
|
|
210 }
|
|
211 cards += histo[255];
|
|
212 // correct traversals for the last one.
|
|
213 unsigned travs_255 = (unsigned) (_total_travs - histo_trav_sum);
|
|
214 travs += travs_255;
|
|
215
|
|
216 } else {
|
|
217 cards += histo[to-1];
|
|
218 travs += histo[to-1] * (to-1);
|
|
219 }
|
|
220 float fperiods = (float)_n_periods;
|
|
221 float f_tot_cards = (float)_total_cards/fperiods;
|
|
222 float f_tot_travs = (float)_total_travs/fperiods;
|
|
223 if (cards > 0) {
|
|
224 float fcards = (float)cards/fperiods;
|
|
225 float ftravs = (float)travs/fperiods;
|
|
226 if (to == 256) {
|
|
227 gclog_or_tty->print(" %4d- %10.2f%10.2f", from, fcards, ftravs);
|
|
228 } else {
|
|
229 gclog_or_tty->print(" %4d-%4d %10.2f%10.2f", from, to-1, fcards, ftravs);
|
|
230 }
|
|
231 float pct_cards = fcards*100.0/f_tot_cards;
|
|
232 cum_card_pct += pct_cards;
|
|
233 float pct_travs = ftravs*100.0/f_tot_travs;
|
|
234 cum_travs_pct += pct_travs;
|
|
235 gclog_or_tty->print_cr("%10.2f%10.2f%10.2f%10.2f",
|
|
236 pct_cards, cum_card_pct,
|
|
237 pct_travs, cum_travs_pct);
|
|
238 }
|
|
239 }
|
|
240
|
|
241 void ConcurrentG1Refine::print_final_card_counts() {
|
|
242 if (!G1ConcRSCountTraversals) return;
|
|
243
|
|
244 gclog_or_tty->print_cr("Did %d total traversals of %d distinct cards.",
|
|
245 _total_travs, _total_cards);
|
|
246 float fperiods = (float)_n_periods;
|
|
247 gclog_or_tty->print_cr(" This is an average of %8.2f traversals, %8.2f cards, "
|
|
248 "per collection.", (float)_total_travs/fperiods,
|
|
249 (float)_total_cards/fperiods);
|
|
250 gclog_or_tty->print_cr(" This is an average of %8.2f traversals/distinct "
|
|
251 "dirty card.\n",
|
|
252 _total_cards > 0 ?
|
|
253 (float)_total_travs/(float)_total_cards : 0.0);
|
|
254
|
|
255
|
|
256 gclog_or_tty->print_cr("Histogram:\n\n%10s %10s%10s%10s%10s%10s%10s",
|
|
257 "range", "# cards", "# travs", "% cards", "(cum)",
|
|
258 "% travs", "(cum)");
|
|
259 gclog_or_tty->print_cr("------------------------------------------------------------"
|
|
260 "-------------");
|
|
261 float cum_cards_pct = 0.0;
|
|
262 float cum_travs_pct = 0.0;
|
|
263 for (int i = 1; i < 10; i++) {
|
|
264 print_card_count_histo_range(_cum_card_count_histo, i, i+1,
|
|
265 cum_cards_pct, cum_travs_pct);
|
|
266 }
|
|
267 for (int i = 10; i < 100; i += 10) {
|
|
268 print_card_count_histo_range(_cum_card_count_histo, i, i+10,
|
|
269 cum_cards_pct, cum_travs_pct);
|
|
270 }
|
|
271 print_card_count_histo_range(_cum_card_count_histo, 100, 150,
|
|
272 cum_cards_pct, cum_travs_pct);
|
|
273 print_card_count_histo_range(_cum_card_count_histo, 150, 200,
|
|
274 cum_cards_pct, cum_travs_pct);
|
|
275 print_card_count_histo_range(_cum_card_count_histo, 150, 255,
|
|
276 cum_cards_pct, cum_travs_pct);
|
|
277 print_card_count_histo_range(_cum_card_count_histo, 255, 256,
|
|
278 cum_cards_pct, cum_travs_pct);
|
|
279 }
|