257 _local_max_size = tmp_size; |
257 _local_max_size = tmp_size; |
258 } |
258 } |
259 ++_local_pushes ); |
259 ++_local_pushes ); |
260 } |
260 } |
261 |
261 |
262 inline bool CMTask::is_below_finger(HeapWord* objAddr, |
262 inline bool CMTask::is_below_finger(oop obj, HeapWord* global_finger) const { |
263 HeapWord* global_finger) const { |
263 // If obj is above the global finger, then the mark bitmap scan |
264 // If objAddr is above the global finger, then the mark bitmap scan |
|
265 // will find it later, and no push is needed. Similarly, if we have |
264 // will find it later, and no push is needed. Similarly, if we have |
266 // a current region and objAddr is between the local finger and the |
265 // a current region and obj is between the local finger and the |
267 // end of the current region, then no push is needed. The tradeoff |
266 // end of the current region, then no push is needed. The tradeoff |
268 // of checking both vs only checking the global finger is that the |
267 // of checking both vs only checking the global finger is that the |
269 // local check will be more accurate and so result in fewer pushes, |
268 // local check will be more accurate and so result in fewer pushes, |
270 // but may also be a little slower. |
269 // but may also be a little slower. |
|
270 HeapWord* objAddr = (HeapWord*)obj; |
271 if (_finger != NULL) { |
271 if (_finger != NULL) { |
272 // We have a current region. |
272 // We have a current region. |
273 |
273 |
274 // Finger and region values are all NULL or all non-NULL. We |
274 // Finger and region values are all NULL or all non-NULL. We |
275 // use _finger to check since we immediately use its value. |
275 // use _finger to check since we immediately use its value. |
276 assert(_curr_region != NULL, "invariant"); |
276 assert(_curr_region != NULL, "invariant"); |
277 assert(_region_limit != NULL, "invariant"); |
277 assert(_region_limit != NULL, "invariant"); |
278 assert(_region_limit <= global_finger, "invariant"); |
278 assert(_region_limit <= global_finger, "invariant"); |
279 |
279 |
280 // True if objAddr is less than the local finger, or is between |
280 // True if obj is less than the local finger, or is between |
281 // the region limit and the global finger. |
281 // the region limit and the global finger. |
282 if (objAddr < _finger) { |
282 if (objAddr < _finger) { |
283 return true; |
283 return true; |
284 } else if (objAddr < _region_limit) { |
284 } else if (objAddr < _region_limit) { |
285 return false; |
285 return false; |
287 } |
287 } |
288 // Check global finger. |
288 // Check global finger. |
289 return objAddr < global_finger; |
289 return objAddr < global_finger; |
290 } |
290 } |
291 |
291 |
|
292 inline void CMTask::make_reference_grey(oop obj, HeapRegion* hr) { |
|
293 if (_cm->par_mark_and_count(obj, hr, _marked_bytes_array, _card_bm)) { |
|
294 |
|
295 if (_cm->verbose_high()) { |
|
296 gclog_or_tty->print_cr("[%u] marked object " PTR_FORMAT, |
|
297 _worker_id, p2i(obj)); |
|
298 } |
|
299 |
|
300 // No OrderAccess:store_load() is needed. It is implicit in the |
|
301 // CAS done in CMBitMap::parMark() call in the routine above. |
|
302 HeapWord* global_finger = _cm->finger(); |
|
303 |
|
304 // We only need to push a newly grey object on the mark |
|
305 // stack if it is in a section of memory the mark bitmap |
|
306 // scan has already examined. Mark bitmap scanning |
|
307 // maintains progress "fingers" for determining that. |
|
308 // |
|
309 // Notice that the global finger might be moving forward |
|
310 // concurrently. This is not a problem. In the worst case, we |
|
311 // mark the object while it is above the global finger and, by |
|
312 // the time we read the global finger, it has moved forward |
|
313 // past this object. In this case, the object will probably |
|
314 // be visited when a task is scanning the region and will also |
|
315 // be pushed on the stack. So, some duplicate work, but no |
|
316 // correctness problems. |
|
317 if (is_below_finger(obj, global_finger)) { |
|
318 if (obj->is_typeArray()) { |
|
319 // Immediately process arrays of primitive types, rather |
|
320 // than pushing on the mark stack. This keeps us from |
|
321 // adding humongous objects to the mark stack that might |
|
322 // be reclaimed before the entry is processed - see |
|
323 // selection of candidates for eager reclaim of humongous |
|
324 // objects. The cost of the additional type test is |
|
325 // mitigated by avoiding a trip through the mark stack, |
|
326 // by only doing a bookkeeping update and avoiding the |
|
327 // actual scan of the object - a typeArray contains no |
|
328 // references, and the metadata is built-in. |
|
329 process_grey_object<false>(obj); |
|
330 } else { |
|
331 if (_cm->verbose_high()) { |
|
332 gclog_or_tty->print_cr("[%u] below a finger (local: " PTR_FORMAT |
|
333 ", global: " PTR_FORMAT ") pushing " |
|
334 PTR_FORMAT " on mark stack", |
|
335 _worker_id, p2i(_finger), |
|
336 p2i(global_finger), p2i(obj)); |
|
337 } |
|
338 push(obj); |
|
339 } |
|
340 } |
|
341 } |
|
342 } |
|
343 |
292 inline void CMTask::deal_with_reference(oop obj) { |
344 inline void CMTask::deal_with_reference(oop obj) { |
293 if (_cm->verbose_high()) { |
345 if (_cm->verbose_high()) { |
294 gclog_or_tty->print_cr("[%u] we're dealing with reference = "PTR_FORMAT, |
346 gclog_or_tty->print_cr("[%u] we're dealing with reference = "PTR_FORMAT, |
295 _worker_id, p2i((void*) obj)); |
347 _worker_id, p2i((void*) obj)); |
296 } |
348 } |
297 |
349 |
298 ++_refs_reached; |
350 increment_refs_reached(); |
299 |
351 |
300 HeapWord* objAddr = (HeapWord*) obj; |
352 HeapWord* objAddr = (HeapWord*) obj; |
301 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
353 assert(obj->is_oop_or_null(true /* ignore mark word */), "Error"); |
302 if (_g1h->is_in_g1_reserved(objAddr)) { |
354 if (_g1h->is_in_g1_reserved(objAddr)) { |
303 assert(obj != NULL, "null check is implicit"); |
355 assert(obj != NULL, "null check is implicit"); |
305 // Only get the containing region if the object is not marked on the |
357 // Only get the containing region if the object is not marked on the |
306 // bitmap (otherwise, it's a waste of time since we won't do |
358 // bitmap (otherwise, it's a waste of time since we won't do |
307 // anything with it). |
359 // anything with it). |
308 HeapRegion* hr = _g1h->heap_region_containing_raw(obj); |
360 HeapRegion* hr = _g1h->heap_region_containing_raw(obj); |
309 if (!hr->obj_allocated_since_next_marking(obj)) { |
361 if (!hr->obj_allocated_since_next_marking(obj)) { |
310 if (_cm->verbose_high()) { |
362 make_reference_grey(obj, hr); |
311 gclog_or_tty->print_cr("[%u] "PTR_FORMAT" is not considered marked", |
|
312 _worker_id, p2i((void*) obj)); |
|
313 } |
|
314 |
|
315 // we need to mark it first |
|
316 if (_cm->par_mark_and_count(obj, hr, _marked_bytes_array, _card_bm)) { |
|
317 // No OrderAccess:store_load() is needed. It is implicit in the |
|
318 // CAS done in CMBitMap::parMark() call in the routine above. |
|
319 HeapWord* global_finger = _cm->finger(); |
|
320 |
|
321 // We only need to push a newly grey object on the mark |
|
322 // stack if it is in a section of memory the mark bitmap |
|
323 // scan has already examined. Mark bitmap scanning |
|
324 // maintains progress "fingers" for determining that. |
|
325 // |
|
326 // Notice that the global finger might be moving forward |
|
327 // concurrently. This is not a problem. In the worst case, we |
|
328 // mark the object while it is above the global finger and, by |
|
329 // the time we read the global finger, it has moved forward |
|
330 // past this object. In this case, the object will probably |
|
331 // be visited when a task is scanning the region and will also |
|
332 // be pushed on the stack. So, some duplicate work, but no |
|
333 // correctness problems. |
|
334 if (is_below_finger(objAddr, global_finger)) { |
|
335 if (obj->is_typeArray()) { |
|
336 // Immediately process arrays of primitive types, rather |
|
337 // than pushing on the mark stack. This keeps us from |
|
338 // adding humongous objects to the mark stack that might |
|
339 // be reclaimed before the entry is processed - see |
|
340 // selection of candidates for eager reclaim of humongous |
|
341 // objects. The cost of the additional type test is |
|
342 // mitigated by avoiding a trip through the mark stack, |
|
343 // by only doing a bookkeeping update and avoiding the |
|
344 // actual scan of the object - a typeArray contains no |
|
345 // references, and the metadata is built-in. |
|
346 process_grey_object<false>(obj); |
|
347 } else { |
|
348 if (_cm->verbose_high()) { |
|
349 gclog_or_tty->print_cr("[%u] below a finger (local: " PTR_FORMAT |
|
350 ", global: " PTR_FORMAT ") pushing " |
|
351 PTR_FORMAT " on mark stack", |
|
352 _worker_id, p2i(_finger), |
|
353 p2i(global_finger), p2i(objAddr)); |
|
354 } |
|
355 push(obj); |
|
356 } |
|
357 } |
|
358 } |
|
359 } |
363 } |
360 } |
364 } |
361 } |
365 } |
362 } |
366 } |
363 |
367 |