242 gclog_or_tty->print_cr("[%u] task queue overflow, "
243 "moving entries to the global stack",
244 _worker_id);
245 }
246 move_entries_to_global_stack();
247
248 // this should succeed since, even if we overflow the global
249 // stack, we should have definitely removed some entries from the
250 // local queue. So, there must be space on it.
251 bool success = _task_queue->push(obj);
252 assert(success, "invariant");
253 }
254
255 statsOnly( size_t tmp_size = (size_t)_task_queue->size();
256 if (tmp_size > _local_max_size) {
257 _local_max_size = tmp_size;
258 }
259 ++_local_pushes );
260 }
261
262 // This determines whether the method below will check both the local
263 // and global fingers when determining whether to push on the stack a
264 // gray object (value 1) or whether it will only check the global one
265 // (value 0). The tradeoffs are that the former will be a bit more
266 // accurate and possibly push less on the stack, but it might also be
267 // a little bit slower.
268
269 #define _CHECK_BOTH_FINGERS_ 1
270
271 inline void CMTask::deal_with_reference(oop obj) {
272 if (_cm->verbose_high()) {
273 gclog_or_tty->print_cr("[%u] we're dealing with reference = "PTR_FORMAT,
274 _worker_id, p2i((void*) obj));
275 }
276
277 ++_refs_reached;
278
279 HeapWord* objAddr = (HeapWord*) obj;
280 assert(obj->is_oop_or_null(true /* ignore mark word */), err_msg("Expected an oop or NULL at " PTR_FORMAT, p2i(obj)));
281 if (_g1h->is_in_g1_reserved(objAddr)) {
282 assert(obj != NULL, "null check is implicit");
283 if (!_nextMarkBitMap->isMarked(objAddr)) {
284 // Only get the containing region if the object is not marked on the
285 // bitmap (otherwise, it's a waste of time since we won't do
286 // anything with it).
287 HeapRegion* hr = _g1h->heap_region_containing_raw(obj);
288 if (!hr->obj_allocated_since_next_marking(obj)) {
289 if (_cm->verbose_high()) {
290 gclog_or_tty->print_cr("[%u] "PTR_FORMAT" is not considered marked",
291 _worker_id, p2i((void*) obj));
292 }
293
294 // we need to mark it first
295 if (_cm->par_mark_and_count(obj, hr, _marked_bytes_array, _card_bm)) {
296 // No OrderAccess:store_load() is needed. It is implicit in the
297 // CAS done in CMBitMap::parMark() call in the routine above.
298 HeapWord* global_finger = _cm->finger();
299
300 #if _CHECK_BOTH_FINGERS_
301 // we will check both the local and global fingers
302
303 if (_finger != NULL && objAddr < _finger) {
304 if (_cm->verbose_high()) {
305 gclog_or_tty->print_cr("[%u] below the local finger ("PTR_FORMAT"), "
306 "pushing it", _worker_id, p2i(_finger));
307 }
308 push(obj);
309 } else if (_curr_region != NULL && objAddr < _region_limit) {
310 // do nothing
311 } else if (objAddr < global_finger) {
312 // Notice that the global finger might be moving forward
313 // concurrently. This is not a problem. In the worst case, we
314 // mark the object while it is above the global finger and, by
315 // the time we read the global finger, it has moved forward
316 // passed this object. In this case, the object will probably
317 // be visited when a task is scanning the region and will also
318 // be pushed on the stack. So, some duplicate work, but no
319 // correctness problems.
320
321 if (_cm->verbose_high()) {
322 gclog_or_tty->print_cr("[%u] below the global finger "
323 "("PTR_FORMAT"), pushing it",
324 _worker_id, p2i(global_finger));
325 }
326 push(obj);
327 } else {
328 // do nothing
329 }
330 #else // _CHECK_BOTH_FINGERS_
331 // we will only check the global finger
332
333 if (objAddr < global_finger) {
334 // see long comment above
335
336 if (_cm->verbose_high()) {
337 gclog_or_tty->print_cr("[%u] below the global finger "
338 "("PTR_FORMAT"), pushing it",
339 _worker_id, p2i(global_finger));
340 }
341 push(obj);
342 }
343 #endif // _CHECK_BOTH_FINGERS_
344 }
345 }
346 }
347 }
348 }
349
350 inline void ConcurrentMark::markPrev(oop p) {
351 assert(!_prevMarkBitMap->isMarked((HeapWord*) p), "sanity");
352 // Note we are overriding the read-only view of the prev map here, via
353 // the cast.
354 ((CMBitMap*)_prevMarkBitMap)->mark((HeapWord*) p);
355 }
356
357 inline void ConcurrentMark::grayRoot(oop obj, size_t word_size,
358 uint worker_id, HeapRegion* hr) {
359 assert(obj != NULL, "pre-condition");
360 HeapWord* addr = (HeapWord*) obj;
361 if (hr == NULL) {
362 hr = _g1h->heap_region_containing_raw(addr);
363 } else {
|
242 gclog_or_tty->print_cr("[%u] task queue overflow, "
243 "moving entries to the global stack",
244 _worker_id);
245 }
246 move_entries_to_global_stack();
247
248 // this should succeed since, even if we overflow the global
249 // stack, we should have definitely removed some entries from the
250 // local queue. So, there must be space on it.
251 bool success = _task_queue->push(obj);
252 assert(success, "invariant");
253 }
254
255 statsOnly( size_t tmp_size = (size_t)_task_queue->size();
256 if (tmp_size > _local_max_size) {
257 _local_max_size = tmp_size;
258 }
259 ++_local_pushes );
260 }
261
262 inline bool CMTask::is_below_finger(HeapWord* objAddr,
263 HeapWord* global_finger) const {
264 // Test whether objAddr might have already been passed over by the
265 // mark bitmap scan, and so needs to be pushed onto the mark stack.
266 // If objAddr is above the global finger, then the mark bitmap scan
267 // will find it later, and no push is needed. Similarly, if we have
268 // a current region and objAddr is between the local finger and the
269 // end of the current region, then no push is needed. The tradeoff
270 // of checking both vs only checking the global finger is that the
271 // local check will be more accurate and so result in fewer pushes,
272 // but is also be a little slower.
273 if (_finger != NULL) {
274 // We have a current region.
275
276 // Finger and region values are all NULL or all non-NULL. We
277 // use _finger to check since we immediately use its value.
278 assert(_curr_region != NULL, "invariant");
279 assert(_region_limit != NULL, "invariant");
280 assert(_region_limit <= global_finger, "invariant");
281
282 // True if objAddr is less than the local finger, or is between
283 // the region limit and the global finger.
284 if (objAddr < _finger) {
285 return true;
286 } else if (objAddr < _region_limit) {
287 return false;
288 } // Else check global finger.
289 }
290 // Check global finger.
291 return objAddr < global_finger;
292 }
293
294 inline void CMTask::deal_with_reference(oop obj) {
295 if (_cm->verbose_high()) {
296 gclog_or_tty->print_cr("[%u] we're dealing with reference = "PTR_FORMAT,
297 _worker_id, p2i((void*) obj));
298 }
299
300 ++_refs_reached;
301
302 HeapWord* objAddr = (HeapWord*) obj;
303 assert(obj->is_oop_or_null(true /* ignore mark word */), err_msg("Expected an oop or NULL at " PTR_FORMAT, p2i(obj)));
304 if (_g1h->is_in_g1_reserved(objAddr)) {
305 assert(obj != NULL, "null check is implicit");
306 if (!_nextMarkBitMap->isMarked(objAddr)) {
307 // Only get the containing region if the object is not marked on the
308 // bitmap (otherwise, it's a waste of time since we won't do
309 // anything with it).
310 HeapRegion* hr = _g1h->heap_region_containing_raw(obj);
311 if (!hr->obj_allocated_since_next_marking(obj)) {
312 if (_cm->verbose_high()) {
313 gclog_or_tty->print_cr("[%u] "PTR_FORMAT" is not considered marked",
314 _worker_id, p2i((void*) obj));
315 }
316
317 // we need to mark it first
318 if (_cm->par_mark_and_count(obj, hr, _marked_bytes_array, _card_bm)) {
319 // No OrderAccess:store_load() is needed. It is implicit in the
320 // CAS done in CMBitMap::parMark() call in the routine above.
321 HeapWord* global_finger = _cm->finger();
322
323 // We only need to push a newly grey object on the mark
324 // stack if it is in a section of memory the mark bitmap
325 // scan has already examined. Mark bitmap scanning
326 // maintains progress "fingers" for determining that.
327 //
328 // Notice that the global finger might be moving forward
329 // concurrently. This is not a problem. In the worst case, we
330 // mark the object while it is above the global finger and, by
331 // the time we read the global finger, it has moved forward
332 // past this object. In this case, the object will probably
333 // be visited when a task is scanning the region and will also
334 // be pushed on the stack. So, some duplicate work, but no
335 // correctness problems.
336 if (is_below_finger(objAddr, global_finger)) {
337 if (_cm->verbose_high()) {
338 gclog_or_tty->print_cr("[%u] below a finger (local: " PTR_FORMAT
339 ", global: " PTR_FORMAT ") pushing "
340 PTR_FORMAT " on mark stack",
341 _worker_id, p2i(_finger),
342 p2i(global_finger), p2i(objAddr));
343 }
344 push(obj);
345 }
346 }
347 }
348 }
349 }
350 }
351
352 inline void ConcurrentMark::markPrev(oop p) {
353 assert(!_prevMarkBitMap->isMarked((HeapWord*) p), "sanity");
354 // Note we are overriding the read-only view of the prev map here, via
355 // the cast.
356 ((CMBitMap*)_prevMarkBitMap)->mark((HeapWord*) p);
357 }
358
359 inline void ConcurrentMark::grayRoot(oop obj, size_t word_size,
360 uint worker_id, HeapRegion* hr) {
361 assert(obj != NULL, "pre-condition");
362 HeapWord* addr = (HeapWord*) obj;
363 if (hr == NULL) {
364 hr = _g1h->heap_region_containing_raw(addr);
365 } else {
|