comparison src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp @ 3357:fc2b798ab316

6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests Summary: Fixed process_chunk_boundaries(), used for parallel card scanning when using ParNew/CMS, so as to prevent double-scanning, or worse, non-scanning of imprecisely marked objects exceeding parallel chunk size. Made some sizing parameters for parallel card scanning diagnostic, disabled ParallelGCRetainPLAB, and elaborated and clarified some comments. Reviewed-by: stefank, johnc
author ysr
date Tue, 10 May 2011 00:33:21 -0700
parents c48ad6ab8bdf
children 7d64aa23eb96
comparison
equal deleted inserted replaced
3325:54a56bbaf95b 3357:fc2b798ab316
27 #include "memory/cardTableModRefBS.hpp" 27 #include "memory/cardTableModRefBS.hpp"
28 #include "memory/cardTableRS.hpp" 28 #include "memory/cardTableRS.hpp"
29 #include "memory/sharedHeap.hpp" 29 #include "memory/sharedHeap.hpp"
30 #include "memory/space.inline.hpp" 30 #include "memory/space.inline.hpp"
31 #include "memory/universe.hpp" 31 #include "memory/universe.hpp"
32 #include "oops/oop.inline.hpp"
32 #include "runtime/java.hpp" 33 #include "runtime/java.hpp"
33 #include "runtime/mutexLocker.hpp" 34 #include "runtime/mutexLocker.hpp"
34 #include "runtime/virtualspace.hpp" 35 #include "runtime/virtualspace.hpp"
35 36
36 void CardTableModRefBS::non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr, 37 void CardTableModRefBS::non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
37 DirtyCardToOopClosure* dcto_cl, 38 OopsInGenClosure* cl,
38 ClearNoncleanCardWrapper* cl, 39 CardTableRS* ct,
39 int n_threads) { 40 int n_threads) {
40 assert(n_threads > 0, "Error: expected n_threads > 0"); 41 assert(n_threads > 0, "Error: expected n_threads > 0");
41 assert((n_threads == 1 && ParallelGCThreads == 0) || 42 assert((n_threads == 1 && ParallelGCThreads == 0) ||
42 n_threads <= (int)ParallelGCThreads, 43 n_threads <= (int)ParallelGCThreads,
43 "# worker threads != # requested!"); 44 "# worker threads != # requested!");
47 size_t lowest_non_clean_chunk_size; 48 size_t lowest_non_clean_chunk_size;
48 get_LNC_array_for_space(sp, lowest_non_clean, 49 get_LNC_array_for_space(sp, lowest_non_clean,
49 lowest_non_clean_base_chunk_index, 50 lowest_non_clean_base_chunk_index,
50 lowest_non_clean_chunk_size); 51 lowest_non_clean_chunk_size);
51 52
52 int n_strides = n_threads * StridesPerThread; 53 int n_strides = n_threads * ParGCStridesPerThread;
53 SequentialSubTasksDone* pst = sp->par_seq_tasks(); 54 SequentialSubTasksDone* pst = sp->par_seq_tasks();
54 pst->set_n_threads(n_threads); 55 pst->set_n_threads(n_threads);
55 pst->set_n_tasks(n_strides); 56 pst->set_n_tasks(n_strides);
56 57
57 int stride = 0; 58 int stride = 0;
58 while (!pst->is_task_claimed(/* reference */ stride)) { 59 while (!pst->is_task_claimed(/* reference */ stride)) {
59 process_stride(sp, mr, stride, n_strides, dcto_cl, cl, 60 process_stride(sp, mr, stride, n_strides, cl, ct,
60 lowest_non_clean, 61 lowest_non_clean,
61 lowest_non_clean_base_chunk_index, 62 lowest_non_clean_base_chunk_index,
62 lowest_non_clean_chunk_size); 63 lowest_non_clean_chunk_size);
63 } 64 }
64 if (pst->all_tasks_completed()) { 65 if (pst->all_tasks_completed()) {
77 void 78 void
78 CardTableModRefBS:: 79 CardTableModRefBS::
79 process_stride(Space* sp, 80 process_stride(Space* sp,
80 MemRegion used, 81 MemRegion used,
81 jint stride, int n_strides, 82 jint stride, int n_strides,
82 DirtyCardToOopClosure* dcto_cl, 83 OopsInGenClosure* cl,
83 ClearNoncleanCardWrapper* cl, 84 CardTableRS* ct,
84 jbyte** lowest_non_clean, 85 jbyte** lowest_non_clean,
85 uintptr_t lowest_non_clean_base_chunk_index, 86 uintptr_t lowest_non_clean_base_chunk_index,
86 size_t lowest_non_clean_chunk_size) { 87 size_t lowest_non_clean_chunk_size) {
87 // We don't have to go downwards here; it wouldn't help anyway, 88 // We go from higher to lower addresses here; it wouldn't help that much
88 // because of parallelism. 89 // because of the strided parallelism pattern used here.
89 90
90 // Find the first card address of the first chunk in the stride that is 91 // Find the first card address of the first chunk in the stride that is
91 // at least "bottom" of the used region. 92 // at least "bottom" of the used region.
92 jbyte* start_card = byte_for(used.start()); 93 jbyte* start_card = byte_for(used.start());
93 jbyte* end_card = byte_after(used.last()); 94 jbyte* end_card = byte_after(used.last());
96 jbyte* chunk_card_start; 97 jbyte* chunk_card_start;
97 98
98 if ((uintptr_t)stride >= start_chunk_stride_num) { 99 if ((uintptr_t)stride >= start_chunk_stride_num) {
99 chunk_card_start = (jbyte*)(start_card + 100 chunk_card_start = (jbyte*)(start_card +
100 (stride - start_chunk_stride_num) * 101 (stride - start_chunk_stride_num) *
101 CardsPerStrideChunk); 102 ParGCCardsPerStrideChunk);
102 } else { 103 } else {
103 // Go ahead to the next chunk group boundary, then to the requested stride. 104 // Go ahead to the next chunk group boundary, then to the requested stride.
104 chunk_card_start = (jbyte*)(start_card + 105 chunk_card_start = (jbyte*)(start_card +
105 (n_strides - start_chunk_stride_num + stride) * 106 (n_strides - start_chunk_stride_num + stride) *
106 CardsPerStrideChunk); 107 ParGCCardsPerStrideChunk);
107 } 108 }
108 109
109 while (chunk_card_start < end_card) { 110 while (chunk_card_start < end_card) {
110 // We don't have to go downwards here; it wouldn't help anyway, 111 // Even though we go from lower to higher addresses below, the
111 // because of parallelism. (We take care with "min_done"; see below.) 112 // strided parallelism can interleave the actual processing of the
113 // dirty pages in various ways. For a specific chunk within this
114 // stride, we take care to avoid double scanning or missing a card
115 // by suitably initializing the "min_done" field in process_chunk_boundaries()
116 // below, together with the dirty region extension accomplished in
117 // DirtyCardToOopClosure::do_MemRegion().
118 jbyte* chunk_card_end = chunk_card_start + ParGCCardsPerStrideChunk;
112 // Invariant: chunk_mr should be fully contained within the "used" region. 119 // Invariant: chunk_mr should be fully contained within the "used" region.
113 jbyte* chunk_card_end = chunk_card_start + CardsPerStrideChunk;
114 MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start), 120 MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start),
115 chunk_card_end >= end_card ? 121 chunk_card_end >= end_card ?
116 used.end() : addr_for(chunk_card_end)); 122 used.end() : addr_for(chunk_card_end));
117 assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)"); 123 assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)");
118 assert(used.contains(chunk_mr), "chunk_mr should be subset of used"); 124 assert(used.contains(chunk_mr), "chunk_mr should be subset of used");
125
126 DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(),
127 cl->gen_boundary());
128 ClearNoncleanCardWrapper clear_cl(dcto_cl, ct);
129
119 130
120 // Process the chunk. 131 // Process the chunk.
121 process_chunk_boundaries(sp, 132 process_chunk_boundaries(sp,
122 dcto_cl, 133 dcto_cl,
123 chunk_mr, 134 chunk_mr,
124 used, 135 used,
125 lowest_non_clean, 136 lowest_non_clean,
126 lowest_non_clean_base_chunk_index, 137 lowest_non_clean_base_chunk_index,
127 lowest_non_clean_chunk_size); 138 lowest_non_clean_chunk_size);
128 139
140 // We want the LNC array updates above in process_chunk_boundaries
141 // to be visible before any of the card table value changes as a
142 // result of the dirty card iteration below.
143 OrderAccess::storestore();
144
129 // We do not call the non_clean_card_iterate_serial() version because 145 // We do not call the non_clean_card_iterate_serial() version because
130 // we want to clear the cards, and the ClearNoncleanCardWrapper closure 146 // we want to clear the cards: clear_cl here does the work of finding
131 // itself does the work of finding contiguous dirty ranges of cards to 147 // contiguous dirty ranges of cards to process and clear.
132 // process (and clear). 148 clear_cl.do_MemRegion(chunk_mr);
133 cl->do_MemRegion(chunk_mr);
134 149
135 // Find the next chunk of the stride. 150 // Find the next chunk of the stride.
136 chunk_card_start += CardsPerStrideChunk * n_strides; 151 chunk_card_start += ParGCCardsPerStrideChunk * n_strides;
137 } 152 }
138 } 153 }
154
155
156 // If you want a talkative process_chunk_boundaries,
157 // then #define NOISY(x) x
158 #ifdef NOISY
159 #error "Encountered a global preprocessor flag, NOISY, which might clash with local definition to follow"
160 #else
161 #define NOISY(x)
162 #endif
139 163
140 void 164 void
141 CardTableModRefBS:: 165 CardTableModRefBS::
142 process_chunk_boundaries(Space* sp, 166 process_chunk_boundaries(Space* sp,
143 DirtyCardToOopClosure* dcto_cl, 167 DirtyCardToOopClosure* dcto_cl,
145 MemRegion used, 169 MemRegion used,
146 jbyte** lowest_non_clean, 170 jbyte** lowest_non_clean,
147 uintptr_t lowest_non_clean_base_chunk_index, 171 uintptr_t lowest_non_clean_base_chunk_index,
148 size_t lowest_non_clean_chunk_size) 172 size_t lowest_non_clean_chunk_size)
149 { 173 {
150 // We must worry about the chunk boundaries. 174 // We must worry about non-array objects that cross chunk boundaries,
151 175 // because such objects are both precisely and imprecisely marked:
152 // First, set our max_to_do: 176 // .. if the head of such an object is dirty, the entire object
153 HeapWord* max_to_do = NULL; 177 // needs to be scanned, under the interpretation that this
178 // was an imprecise mark
179 // .. if the head of such an object is not dirty, we can assume
180 // precise marking and it's efficient to scan just the dirty
181 // cards.
182 // In either case, each scanned reference must be scanned precisely
183 // once so as to avoid cloning of a young referent. For efficiency,
184 // our closures depend on this property and do not protect against
185 // double scans.
186
154 uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start()); 187 uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start());
155 cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index; 188 cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index;
156 189
190 NOISY(tty->print_cr("===========================================================================");)
191 NOISY(tty->print_cr(" process_chunk_boundary: Called with [" PTR_FORMAT "," PTR_FORMAT ")",
192 chunk_mr.start(), chunk_mr.end());)
193
194 // First, set "our" lowest_non_clean entry, which would be
195 // used by the thread scanning an adjoining left chunk with
196 // a non-array object straddling the mutual boundary.
197 // Find the object that spans our boundary, if one exists.
198 // first_block is the block possibly straddling our left boundary.
199 HeapWord* first_block = sp->block_start(chunk_mr.start());
200 assert((chunk_mr.start() != used.start()) || (first_block == chunk_mr.start()),
201 "First chunk should always have a co-initial block");
202 // Does the block straddle the chunk's left boundary, and is it
203 // a non-array object?
204 if (first_block < chunk_mr.start() // first block straddles left bdry
205 && sp->block_is_obj(first_block) // first block is an object
206 && !(oop(first_block)->is_objArray() // first block is not an array (arrays are precisely dirtied)
207 || oop(first_block)->is_typeArray())) {
208 // Find our least non-clean card, so that a left neighbour
209 // does not scan an object straddling the mutual boundary
210 // too far to the right, and attempt to scan a portion of
211 // that object twice.
212 jbyte* first_dirty_card = NULL;
213 jbyte* last_card_of_first_obj =
214 byte_for(first_block + sp->block_size(first_block) - 1);
215 jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
216 jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last());
217 jbyte* last_card_to_check =
218 (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk,
219 (intptr_t) last_card_of_first_obj);
220 // Note that this does not need to go beyond our last card
221 // if our first object completely straddles this chunk.
222 for (jbyte* cur = first_card_of_cur_chunk;
223 cur <= last_card_to_check; cur++) {
224 jbyte val = *cur;
225 if (card_will_be_scanned(val)) {
226 first_dirty_card = cur; break;
227 } else {
228 assert(!card_may_have_been_dirty(val), "Error");
229 }
230 }
231 if (first_dirty_card != NULL) {
232 NOISY(tty->print_cr(" LNC: Found a dirty card at " PTR_FORMAT " in current chunk",
233 first_dirty_card);)
234 assert(0 <= cur_chunk_index && cur_chunk_index < lowest_non_clean_chunk_size,
235 "Bounds error.");
236 assert(lowest_non_clean[cur_chunk_index] == NULL,
237 "Write exactly once : value should be stable hereafter for this round");
238 lowest_non_clean[cur_chunk_index] = first_dirty_card;
239 } NOISY(else {
240 tty->print_cr(" LNC: Found no dirty card in current chunk; leaving LNC entry NULL");
241 // In the future, we could have this thread look for a non-NULL value to copy from its
242 // right neighbour (up to the end of the first object).
243 if (last_card_of_cur_chunk < last_card_of_first_obj) {
244 tty->print_cr(" LNC: BEWARE!!! first obj straddles past right end of chunk:\n"
245 " might be efficient to get value from right neighbour?");
246 }
247 })
248 } else {
249 // In this case we can help our neighbour by just asking them
250 // to stop at our first card (even though it may not be dirty).
251 NOISY(tty->print_cr(" LNC: first block is not a non-array object; setting LNC to first card of current chunk");)
252 assert(lowest_non_clean[cur_chunk_index] == NULL, "Write once : value should be stable hereafter");
253 jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
254 lowest_non_clean[cur_chunk_index] = first_card_of_cur_chunk;
255 }
256 NOISY(tty->print_cr(" process_chunk_boundary: lowest_non_clean[" INTPTR_FORMAT "] = " PTR_FORMAT
257 " which corresponds to the heap address " PTR_FORMAT,
258 cur_chunk_index, lowest_non_clean[cur_chunk_index],
259 (lowest_non_clean[cur_chunk_index] != NULL)
260 ? addr_for(lowest_non_clean[cur_chunk_index])
261 : NULL);)
262 NOISY(tty->print_cr("---------------------------------------------------------------------------");)
263
264 // Next, set our own max_to_do, which will strictly/exclusively bound
265 // the highest address that we will scan past the right end of our chunk.
266 HeapWord* max_to_do = NULL;
157 if (chunk_mr.end() < used.end()) { 267 if (chunk_mr.end() < used.end()) {
158 // This is not the last chunk in the used region. What is the last 268 // This is not the last chunk in the used region.
159 // object? 269 // What is our last block? We check the first block of
160 HeapWord* last_block = sp->block_start(chunk_mr.end()); 270 // the next (right) chunk rather than strictly check our last block
271 // because it's potentially more efficient to do so.
272 HeapWord* const last_block = sp->block_start(chunk_mr.end());
161 assert(last_block <= chunk_mr.end(), "In case this property changes."); 273 assert(last_block <= chunk_mr.end(), "In case this property changes.");
162 if (last_block == chunk_mr.end() 274 if ((last_block == chunk_mr.end()) // our last block does not straddle boundary
163 || !sp->block_is_obj(last_block)) { 275 || !sp->block_is_obj(last_block) // last_block isn't an object
276 || oop(last_block)->is_objArray() // last_block is an array (precisely marked)
277 || oop(last_block)->is_typeArray()) {
164 max_to_do = chunk_mr.end(); 278 max_to_do = chunk_mr.end();
165 279 NOISY(tty->print_cr(" process_chunk_boundary: Last block on this card is not a non-array object;\n"
280 " max_to_do left at " PTR_FORMAT, max_to_do);)
166 } else { 281 } else {
167 // It is an object and starts before the end of the current chunk. 282 assert(last_block < chunk_mr.end(), "Tautology");
283 // It is a non-array object that straddles the right boundary of this chunk.
168 // last_obj_card is the card corresponding to the start of the last object 284 // last_obj_card is the card corresponding to the start of the last object
169 // in the chunk. Note that the last object may not start in 285 // in the chunk. Note that the last object may not start in
170 // the chunk. 286 // the chunk.
171 jbyte* last_obj_card = byte_for(last_block); 287 jbyte* const last_obj_card = byte_for(last_block);
172 if (!card_may_have_been_dirty(*last_obj_card)) { 288 const jbyte val = *last_obj_card;
173 // The card containing the head is not dirty. Any marks in 289 if (!card_will_be_scanned(val)) {
290 assert(!card_may_have_been_dirty(val), "Error");
291 // The card containing the head is not dirty. Any marks on
174 // subsequent cards still in this chunk must have been made 292 // subsequent cards still in this chunk must have been made
175 // precisely; we can cap processing at the end. 293 // precisely; we can cap processing at the end of our chunk.
176 max_to_do = chunk_mr.end(); 294 max_to_do = chunk_mr.end();
295 NOISY(tty->print_cr(" process_chunk_boundary: Head of last object on this card is not dirty;\n"
296 " max_to_do left at " PTR_FORMAT,
297 max_to_do);)
177 } else { 298 } else {
178 // The last object must be considered dirty, and extends onto the 299 // The last object must be considered dirty, and extends onto the
179 // following chunk. Look for a dirty card in that chunk that will 300 // following chunk. Look for a dirty card in that chunk that will
180 // bound our processing. 301 // bound our processing.
181 jbyte* limit_card = NULL; 302 jbyte* limit_card = NULL;
182 size_t last_block_size = sp->block_size(last_block); 303 const size_t last_block_size = sp->block_size(last_block);
183 jbyte* last_card_of_last_obj = 304 jbyte* const last_card_of_last_obj =
184 byte_for(last_block + last_block_size - 1); 305 byte_for(last_block + last_block_size - 1);
185 jbyte* first_card_of_next_chunk = byte_for(chunk_mr.end()); 306 jbyte* const first_card_of_next_chunk = byte_for(chunk_mr.end());
186 // This search potentially goes a long distance looking 307 // This search potentially goes a long distance looking
187 // for the next card that will be scanned. For example, 308 // for the next card that will be scanned, terminating
188 // an object that is an array of primitives will not 309 // at the end of the last_block, if no earlier dirty card
189 // have any cards covering regions interior to the array 310 // is found.
190 // that will need to be scanned. The scan can be terminated 311 assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start()) == ParGCCardsPerStrideChunk,
191 // at the last card of the next chunk. That would leave 312 "last card of next chunk may be wrong");
192 // limit_card as NULL and would result in "max_to_do"
193 // being set with the LNC value or with the end
194 // of the last block.
195 jbyte* last_card_of_next_chunk = first_card_of_next_chunk +
196 CardsPerStrideChunk;
197 assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start())
198 == CardsPerStrideChunk, "last card of next chunk may be wrong");
199 jbyte* last_card_to_check = (jbyte*) MIN2(last_card_of_last_obj,
200 last_card_of_next_chunk);
201 for (jbyte* cur = first_card_of_next_chunk; 313 for (jbyte* cur = first_card_of_next_chunk;
202 cur <= last_card_to_check; cur++) { 314 cur <= last_card_of_last_obj; cur++) {
203 if (card_will_be_scanned(*cur)) { 315 const jbyte val = *cur;
316 if (card_will_be_scanned(val)) {
317 NOISY(tty->print_cr(" Found a non-clean card " PTR_FORMAT " with value 0x%x",
318 cur, (int)val);)
204 limit_card = cur; break; 319 limit_card = cur; break;
320 } else {
321 assert(!card_may_have_been_dirty(val), "Error: card can't be skipped");
205 } 322 }
206 } 323 }
207 assert(0 <= cur_chunk_index+1 && 324 if (limit_card != NULL) {
208 cur_chunk_index+1 < lowest_non_clean_chunk_size, 325 max_to_do = addr_for(limit_card);
326 assert(limit_card != NULL && max_to_do != NULL, "Error");
327 NOISY(tty->print_cr(" process_chunk_boundary: Found a dirty card at " PTR_FORMAT
328 " max_to_do set at " PTR_FORMAT " which is before end of last block in chunk: "
329 PTR_FORMAT " + " PTR_FORMAT " = " PTR_FORMAT,
330 limit_card, max_to_do, last_block, last_block_size, (last_block+last_block_size));)
331 } else {
332 // The following is a pessimistic value, because it's possible
333 // that a dirty card on a subsequent chunk has been cleared by
334 // the time we get to look at it; we'll correct for that further below,
335 // using the LNC array which records the least non-clean card
336 // before cards were cleared in a particular chunk.
337 limit_card = last_card_of_last_obj;
338 max_to_do = last_block + last_block_size;
339 assert(limit_card != NULL && max_to_do != NULL, "Error");
340 NOISY(tty->print_cr(" process_chunk_boundary: Found no dirty card before end of last block in chunk\n"
341 " Setting limit_card to " PTR_FORMAT
342 " and max_to_do " PTR_FORMAT " + " PTR_FORMAT " = " PTR_FORMAT,
343 limit_card, last_block, last_block_size, max_to_do);)
344 }
345 assert(0 < cur_chunk_index+1 && cur_chunk_index+1 < lowest_non_clean_chunk_size,
209 "Bounds error."); 346 "Bounds error.");
210 // LNC for the next chunk 347 // It is possible that a dirty card for the last object may have been
211 jbyte* lnc_card = lowest_non_clean[cur_chunk_index+1]; 348 // cleared before we had a chance to examine it. In that case, the value
212 if (limit_card == NULL) { 349 // will have been logged in the LNC for that chunk.
213 limit_card = lnc_card; 350 // We need to examine as many chunks to the right as this object
351 // covers.
352 const uintptr_t last_chunk_index_to_check = addr_to_chunk_index(last_block + last_block_size - 1)
353 - lowest_non_clean_base_chunk_index;
354 DEBUG_ONLY(const uintptr_t last_chunk_index = addr_to_chunk_index(used.end())
355 - lowest_non_clean_base_chunk_index;)
356 assert(last_chunk_index_to_check <= last_chunk_index,
357 err_msg("Out of bounds: last_chunk_index_to_check " INTPTR_FORMAT
358 " exceeds last_chunk_index " INTPTR_FORMAT,
359 last_chunk_index_to_check, last_chunk_index));
360 for (uintptr_t lnc_index = cur_chunk_index + 1;
361 lnc_index <= last_chunk_index_to_check;
362 lnc_index++) {
363 jbyte* lnc_card = lowest_non_clean[lnc_index];
364 if (lnc_card != NULL) {
365 // we can stop at the first non-NULL entry we find
366 if (lnc_card <= limit_card) {
367 NOISY(tty->print_cr(" process_chunk_boundary: LNC card " PTR_FORMAT " is lower than limit_card " PTR_FORMAT,
368 " max_to_do will be lowered to " PTR_FORMAT " from " PTR_FORMAT,
369 lnc_card, limit_card, addr_for(lnc_card), max_to_do);)
370 limit_card = lnc_card;
371 max_to_do = addr_for(limit_card);
372 assert(limit_card != NULL && max_to_do != NULL, "Error");
373 }
374 // In any case, we break now
375 break;
376 } // else continue to look for a non-NULL entry if any
214 } 377 }
215 if (limit_card != NULL) { 378 assert(limit_card != NULL && max_to_do != NULL, "Error");
216 if (lnc_card != NULL) {
217 limit_card = (jbyte*)MIN2((intptr_t)limit_card,
218 (intptr_t)lnc_card);
219 }
220 max_to_do = addr_for(limit_card);
221 } else {
222 max_to_do = last_block + last_block_size;
223 }
224 } 379 }
380 assert(max_to_do != NULL, "OOPS 1 !");
225 } 381 }
226 assert(max_to_do != NULL, "OOPS!"); 382 assert(max_to_do != NULL, "OOPS 2!");
227 } else { 383 } else {
228 max_to_do = used.end(); 384 max_to_do = used.end();
229 } 385 NOISY(tty->print_cr(" process_chunk_boundary: Last chunk of this space;\n"
386 " max_to_do left at " PTR_FORMAT,
387 max_to_do);)
388 }
389 assert(max_to_do != NULL, "OOPS 3!");
230 // Now we can set the closure we're using so it doesn't to beyond 390 // Now we can set the closure we're using so it doesn't to beyond
231 // max_to_do. 391 // max_to_do.
232 dcto_cl->set_min_done(max_to_do); 392 dcto_cl->set_min_done(max_to_do);
233 #ifndef PRODUCT 393 #ifndef PRODUCT
234 dcto_cl->set_last_bottom(max_to_do); 394 dcto_cl->set_last_bottom(max_to_do);
235 #endif 395 #endif
236 396 NOISY(tty->print_cr("===========================================================================\n");)
237 // Now we set *our" lowest_non_clean entry.
238 // Find the object that spans our boundary, if one exists.
239 // Nothing to do on the first chunk.
240 if (chunk_mr.start() > used.start()) {
241 // first_block is the block possibly spanning the chunk start
242 HeapWord* first_block = sp->block_start(chunk_mr.start());
243 // Does the block span the start of the chunk and is it
244 // an object?
245 if (first_block < chunk_mr.start() &&
246 sp->block_is_obj(first_block)) {
247 jbyte* first_dirty_card = NULL;
248 jbyte* last_card_of_first_obj =
249 byte_for(first_block + sp->block_size(first_block) - 1);
250 jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
251 jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last());
252 jbyte* last_card_to_check =
253 (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk,
254 (intptr_t) last_card_of_first_obj);
255 for (jbyte* cur = first_card_of_cur_chunk;
256 cur <= last_card_to_check; cur++) {
257 if (card_will_be_scanned(*cur)) {
258 first_dirty_card = cur; break;
259 }
260 }
261 if (first_dirty_card != NULL) {
262 assert(0 <= cur_chunk_index &&
263 cur_chunk_index < lowest_non_clean_chunk_size,
264 "Bounds error.");
265 lowest_non_clean[cur_chunk_index] = first_dirty_card;
266 }
267 }
268 }
269 } 397 }
398
399 #undef NOISY
270 400
271 void 401 void
272 CardTableModRefBS:: 402 CardTableModRefBS::
273 get_LNC_array_for_space(Space* sp, 403 get_LNC_array_for_space(Space* sp,
274 jbyte**& lowest_non_clean, 404 jbyte**& lowest_non_clean,
281 411
282 // Only the first thread to obtain the lock will resize the 412 // Only the first thread to obtain the lock will resize the
283 // LNC array for the covered region. Any later expansion can't affect 413 // LNC array for the covered region. Any later expansion can't affect
284 // the used_at_save_marks region. 414 // the used_at_save_marks region.
285 // (I observed a bug in which the first thread to execute this would 415 // (I observed a bug in which the first thread to execute this would
286 // resize, and then it would cause "expand_and_allocates" that would 416 // resize, and then it would cause "expand_and_allocate" that would
287 // Increase the number of chunks in the covered region. Then a second 417 // increase the number of chunks in the covered region. Then a second
288 // thread would come and execute this, see that the size didn't match, 418 // thread would come and execute this, see that the size didn't match,
289 // and free and allocate again. So the first thread would be using a 419 // and free and allocate again. So the first thread would be using a
290 // freed "_lowest_non_clean" array.) 420 // freed "_lowest_non_clean" array.)
291 421
292 // Do a dirty read here. If we pass the conditional then take the rare 422 // Do a dirty read here. If we pass the conditional then take the rare