Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp @ 3256:c69b1043dfb1
7036482: clear argument is redundant and unused in cardtable methods
Summary: Removed the unused clear argument to various cardtbale methods and unused mod_oop_in_space_iterate method. Unrelated to synopsis, added a pair of clarifying parens in AllocationStats constructor.
Reviewed-by: brutisso, jcoomes
author | ysr |
---|---|
date | Thu, 14 Apr 2011 12:10:15 -0700 |
parents | f95d63e2154a |
children | c48ad6ab8bdf |
rev | line source |
---|---|
0 | 1 /* |
3256
c69b1043dfb1
7036482: clear argument is redundant and unused in cardtable methods
ysr
parents:
1972
diff
changeset
|
2 * Copyright (c) 2007, 2011 Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
845
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
845
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
845
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/allocation.inline.hpp" | |
27 #include "memory/cardTableModRefBS.hpp" | |
28 #include "memory/cardTableRS.hpp" | |
29 #include "memory/sharedHeap.hpp" | |
30 #include "memory/space.inline.hpp" | |
31 #include "memory/universe.hpp" | |
32 #include "runtime/java.hpp" | |
33 #include "runtime/mutexLocker.hpp" | |
34 #include "runtime/virtualspace.hpp" | |
0 | 35 |
36 void CardTableModRefBS::par_non_clean_card_iterate_work(Space* sp, MemRegion mr, | |
37 DirtyCardToOopClosure* dcto_cl, | |
38 MemRegionClosure* cl, | |
39 int n_threads) { | |
40 if (n_threads > 0) { | |
845 | 41 assert((n_threads == 1 && ParallelGCThreads == 0) || |
42 n_threads <= (int)ParallelGCThreads, | |
43 "# worker threads != # requested!"); | |
44 // Make sure the LNC array is valid for the space. | |
0 | 45 jbyte** lowest_non_clean; |
46 uintptr_t lowest_non_clean_base_chunk_index; | |
47 size_t lowest_non_clean_chunk_size; | |
48 get_LNC_array_for_space(sp, lowest_non_clean, | |
49 lowest_non_clean_base_chunk_index, | |
50 lowest_non_clean_chunk_size); | |
51 | |
52 int n_strides = n_threads * StridesPerThread; | |
53 SequentialSubTasksDone* pst = sp->par_seq_tasks(); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
54 pst->set_n_threads(n_threads); |
0 | 55 pst->set_n_tasks(n_strides); |
56 | |
57 int stride = 0; | |
58 while (!pst->is_task_claimed(/* reference */ stride)) { | |
3256
c69b1043dfb1
7036482: clear argument is redundant and unused in cardtable methods
ysr
parents:
1972
diff
changeset
|
59 process_stride(sp, mr, stride, n_strides, dcto_cl, cl, |
0 | 60 lowest_non_clean, |
61 lowest_non_clean_base_chunk_index, | |
62 lowest_non_clean_chunk_size); | |
63 } | |
64 if (pst->all_tasks_completed()) { | |
65 // Clear lowest_non_clean array for next time. | |
66 intptr_t first_chunk_index = addr_to_chunk_index(mr.start()); | |
67 uintptr_t last_chunk_index = addr_to_chunk_index(mr.last()); | |
68 for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) { | |
69 intptr_t ind = ch - lowest_non_clean_base_chunk_index; | |
70 assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size, | |
71 "Bounds error"); | |
72 lowest_non_clean[ind] = NULL; | |
73 } | |
74 } | |
75 } | |
76 } | |
77 | |
78 void | |
79 CardTableModRefBS:: | |
80 process_stride(Space* sp, | |
81 MemRegion used, | |
82 jint stride, int n_strides, | |
83 DirtyCardToOopClosure* dcto_cl, | |
84 MemRegionClosure* cl, | |
85 jbyte** lowest_non_clean, | |
86 uintptr_t lowest_non_clean_base_chunk_index, | |
87 size_t lowest_non_clean_chunk_size) { | |
88 // We don't have to go downwards here; it wouldn't help anyway, | |
89 // because of parallelism. | |
90 | |
91 // Find the first card address of the first chunk in the stride that is | |
92 // at least "bottom" of the used region. | |
93 jbyte* start_card = byte_for(used.start()); | |
94 jbyte* end_card = byte_after(used.last()); | |
95 uintptr_t start_chunk = addr_to_chunk_index(used.start()); | |
96 uintptr_t start_chunk_stride_num = start_chunk % n_strides; | |
97 jbyte* chunk_card_start; | |
98 | |
99 if ((uintptr_t)stride >= start_chunk_stride_num) { | |
100 chunk_card_start = (jbyte*)(start_card + | |
101 (stride - start_chunk_stride_num) * | |
102 CardsPerStrideChunk); | |
103 } else { | |
104 // Go ahead to the next chunk group boundary, then to the requested stride. | |
105 chunk_card_start = (jbyte*)(start_card + | |
106 (n_strides - start_chunk_stride_num + stride) * | |
107 CardsPerStrideChunk); | |
108 } | |
109 | |
110 while (chunk_card_start < end_card) { | |
111 // We don't have to go downwards here; it wouldn't help anyway, | |
112 // because of parallelism. (We take care with "min_done"; see below.) | |
113 // Invariant: chunk_mr should be fully contained within the "used" region. | |
114 jbyte* chunk_card_end = chunk_card_start + CardsPerStrideChunk; | |
115 MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start), | |
116 chunk_card_end >= end_card ? | |
117 used.end() : addr_for(chunk_card_end)); | |
118 assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)"); | |
119 assert(used.contains(chunk_mr), "chunk_mr should be subset of used"); | |
120 | |
121 // Process the chunk. | |
122 process_chunk_boundaries(sp, | |
123 dcto_cl, | |
124 chunk_mr, | |
125 used, | |
126 lowest_non_clean, | |
127 lowest_non_clean_base_chunk_index, | |
128 lowest_non_clean_chunk_size); | |
129 | |
3256
c69b1043dfb1
7036482: clear argument is redundant and unused in cardtable methods
ysr
parents:
1972
diff
changeset
|
130 non_clean_card_iterate_work(chunk_mr, cl); |
0 | 131 |
132 // Find the next chunk of the stride. | |
133 chunk_card_start += CardsPerStrideChunk * n_strides; | |
134 } | |
135 } | |
136 | |
137 void | |
138 CardTableModRefBS:: | |
139 process_chunk_boundaries(Space* sp, | |
140 DirtyCardToOopClosure* dcto_cl, | |
141 MemRegion chunk_mr, | |
142 MemRegion used, | |
143 jbyte** lowest_non_clean, | |
144 uintptr_t lowest_non_clean_base_chunk_index, | |
145 size_t lowest_non_clean_chunk_size) | |
146 { | |
147 // We must worry about the chunk boundaries. | |
148 | |
149 // First, set our max_to_do: | |
150 HeapWord* max_to_do = NULL; | |
151 uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start()); | |
152 cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index; | |
153 | |
154 if (chunk_mr.end() < used.end()) { | |
155 // This is not the last chunk in the used region. What is the last | |
156 // object? | |
157 HeapWord* last_block = sp->block_start(chunk_mr.end()); | |
158 assert(last_block <= chunk_mr.end(), "In case this property changes."); | |
159 if (last_block == chunk_mr.end() | |
160 || !sp->block_is_obj(last_block)) { | |
161 max_to_do = chunk_mr.end(); | |
162 | |
163 } else { | |
164 // It is an object and starts before the end of the current chunk. | |
165 // last_obj_card is the card corresponding to the start of the last object | |
166 // in the chunk. Note that the last object may not start in | |
167 // the chunk. | |
168 jbyte* last_obj_card = byte_for(last_block); | |
169 if (!card_may_have_been_dirty(*last_obj_card)) { | |
170 // The card containing the head is not dirty. Any marks in | |
171 // subsequent cards still in this chunk must have been made | |
172 // precisely; we can cap processing at the end. | |
173 max_to_do = chunk_mr.end(); | |
174 } else { | |
175 // The last object must be considered dirty, and extends onto the | |
176 // following chunk. Look for a dirty card in that chunk that will | |
177 // bound our processing. | |
178 jbyte* limit_card = NULL; | |
179 size_t last_block_size = sp->block_size(last_block); | |
180 jbyte* last_card_of_last_obj = | |
181 byte_for(last_block + last_block_size - 1); | |
182 jbyte* first_card_of_next_chunk = byte_for(chunk_mr.end()); | |
183 // This search potentially goes a long distance looking | |
184 // for the next card that will be scanned. For example, | |
185 // an object that is an array of primitives will not | |
186 // have any cards covering regions interior to the array | |
187 // that will need to be scanned. The scan can be terminated | |
188 // at the last card of the next chunk. That would leave | |
189 // limit_card as NULL and would result in "max_to_do" | |
190 // being set with the LNC value or with the end | |
191 // of the last block. | |
192 jbyte* last_card_of_next_chunk = first_card_of_next_chunk + | |
193 CardsPerStrideChunk; | |
194 assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start()) | |
195 == CardsPerStrideChunk, "last card of next chunk may be wrong"); | |
196 jbyte* last_card_to_check = (jbyte*) MIN2(last_card_of_last_obj, | |
197 last_card_of_next_chunk); | |
198 for (jbyte* cur = first_card_of_next_chunk; | |
199 cur <= last_card_to_check; cur++) { | |
200 if (card_will_be_scanned(*cur)) { | |
201 limit_card = cur; break; | |
202 } | |
203 } | |
204 assert(0 <= cur_chunk_index+1 && | |
205 cur_chunk_index+1 < lowest_non_clean_chunk_size, | |
206 "Bounds error."); | |
207 // LNC for the next chunk | |
208 jbyte* lnc_card = lowest_non_clean[cur_chunk_index+1]; | |
209 if (limit_card == NULL) { | |
210 limit_card = lnc_card; | |
211 } | |
212 if (limit_card != NULL) { | |
213 if (lnc_card != NULL) { | |
214 limit_card = (jbyte*)MIN2((intptr_t)limit_card, | |
215 (intptr_t)lnc_card); | |
216 } | |
217 max_to_do = addr_for(limit_card); | |
218 } else { | |
219 max_to_do = last_block + last_block_size; | |
220 } | |
221 } | |
222 } | |
223 assert(max_to_do != NULL, "OOPS!"); | |
224 } else { | |
225 max_to_do = used.end(); | |
226 } | |
227 // Now we can set the closure we're using so it doesn't to beyond | |
228 // max_to_do. | |
229 dcto_cl->set_min_done(max_to_do); | |
230 #ifndef PRODUCT | |
231 dcto_cl->set_last_bottom(max_to_do); | |
232 #endif | |
233 | |
234 // Now we set *our" lowest_non_clean entry. | |
235 // Find the object that spans our boundary, if one exists. | |
236 // Nothing to do on the first chunk. | |
237 if (chunk_mr.start() > used.start()) { | |
238 // first_block is the block possibly spanning the chunk start | |
239 HeapWord* first_block = sp->block_start(chunk_mr.start()); | |
240 // Does the block span the start of the chunk and is it | |
241 // an object? | |
242 if (first_block < chunk_mr.start() && | |
243 sp->block_is_obj(first_block)) { | |
244 jbyte* first_dirty_card = NULL; | |
245 jbyte* last_card_of_first_obj = | |
246 byte_for(first_block + sp->block_size(first_block) - 1); | |
247 jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start()); | |
248 jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last()); | |
249 jbyte* last_card_to_check = | |
250 (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk, | |
251 (intptr_t) last_card_of_first_obj); | |
252 for (jbyte* cur = first_card_of_cur_chunk; | |
253 cur <= last_card_to_check; cur++) { | |
254 if (card_will_be_scanned(*cur)) { | |
255 first_dirty_card = cur; break; | |
256 } | |
257 } | |
258 if (first_dirty_card != NULL) { | |
259 assert(0 <= cur_chunk_index && | |
260 cur_chunk_index < lowest_non_clean_chunk_size, | |
261 "Bounds error."); | |
262 lowest_non_clean[cur_chunk_index] = first_dirty_card; | |
263 } | |
264 } | |
265 } | |
266 } | |
267 | |
268 void | |
269 CardTableModRefBS:: | |
270 get_LNC_array_for_space(Space* sp, | |
271 jbyte**& lowest_non_clean, | |
272 uintptr_t& lowest_non_clean_base_chunk_index, | |
273 size_t& lowest_non_clean_chunk_size) { | |
274 | |
275 int i = find_covering_region_containing(sp->bottom()); | |
276 MemRegion covered = _covered[i]; | |
277 size_t n_chunks = chunks_to_cover(covered); | |
278 | |
279 // Only the first thread to obtain the lock will resize the | |
280 // LNC array for the covered region. Any later expansion can't affect | |
281 // the used_at_save_marks region. | |
282 // (I observed a bug in which the first thread to execute this would | |
283 // resize, and then it would cause "expand_and_allocates" that would | |
284 // Increase the number of chunks in the covered region. Then a second | |
285 // thread would come and execute this, see that the size didn't match, | |
286 // and free and allocate again. So the first thread would be using a | |
287 // freed "_lowest_non_clean" array.) | |
288 | |
289 // Do a dirty read here. If we pass the conditional then take the rare | |
290 // event lock and do the read again in case some other thread had already | |
291 // succeeded and done the resize. | |
292 int cur_collection = Universe::heap()->total_collections(); | |
293 if (_last_LNC_resizing_collection[i] != cur_collection) { | |
294 MutexLocker x(ParGCRareEvent_lock); | |
295 if (_last_LNC_resizing_collection[i] != cur_collection) { | |
296 if (_lowest_non_clean[i] == NULL || | |
297 n_chunks != _lowest_non_clean_chunk_size[i]) { | |
298 | |
299 // Should we delete the old? | |
300 if (_lowest_non_clean[i] != NULL) { | |
301 assert(n_chunks != _lowest_non_clean_chunk_size[i], | |
302 "logical consequence"); | |
303 FREE_C_HEAP_ARRAY(CardPtr, _lowest_non_clean[i]); | |
304 _lowest_non_clean[i] = NULL; | |
305 } | |
306 // Now allocate a new one if necessary. | |
307 if (_lowest_non_clean[i] == NULL) { | |
308 _lowest_non_clean[i] = NEW_C_HEAP_ARRAY(CardPtr, n_chunks); | |
309 _lowest_non_clean_chunk_size[i] = n_chunks; | |
310 _lowest_non_clean_base_chunk_index[i] = addr_to_chunk_index(covered.start()); | |
311 for (int j = 0; j < (int)n_chunks; j++) | |
312 _lowest_non_clean[i][j] = NULL; | |
313 } | |
314 } | |
315 _last_LNC_resizing_collection[i] = cur_collection; | |
316 } | |
317 } | |
318 // In any case, now do the initialization. | |
319 lowest_non_clean = _lowest_non_clean[i]; | |
320 lowest_non_clean_base_chunk_index = _lowest_non_clean_base_chunk_index[i]; | |
321 lowest_non_clean_chunk_size = _lowest_non_clean_chunk_size[i]; | |
322 } |