< prev index next >

src/hotspot/share/gc/g1/g1ParScanThreadState.cpp

Print this page
rev 52211 : [mq]: 8212753-improve-forward-to-atomic


 248     }
 249   }
 250 
 251   assert(obj_ptr != NULL, "when we get here, allocation should have succeeded");
 252   assert(_g1h->is_in_reserved(obj_ptr), "Allocated memory should be in the heap");
 253 
 254 #ifndef PRODUCT
 255   // Should this evacuation fail?
 256   if (_g1h->evacuation_should_fail()) {
 257     // Doing this after all the allocation attempts also tests the
 258     // undo_allocation() method too.
 259     _plab_allocator->undo_allocation(dest_state, obj_ptr, word_sz);
 260     return handle_evacuation_failure_par(old, old_mark);
 261   }
 262 #endif // !PRODUCT
 263 
 264   // We're going to allocate linearly, so might as well prefetch ahead.
 265   Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes);
 266 
 267   const oop obj = oop(obj_ptr);
 268   const oop forward_ptr = old->forward_to_atomic(obj, memory_order_relaxed);
 269   if (forward_ptr == NULL) {
 270     Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz);
 271 
 272     if (dest_state.is_young()) {
 273       if (age < markOopDesc::max_age) {
 274         age++;
 275       }
 276       if (old_mark->has_displaced_mark_helper()) {
 277         // In this case, we have to install the mark word first,
 278         // otherwise obj looks to be forwarded (the old mark word,
 279         // which contains the forward pointer, was copied)
 280         obj->set_mark_raw(old_mark);
 281         markOop new_mark = old_mark->displaced_mark_helper()->set_age(age);
 282         old_mark->set_displaced_mark_helper(new_mark);
 283       } else {
 284         obj->set_mark_raw(old_mark->set_age(age));
 285       }
 286       _age_table.add(age, word_sz);
 287     } else {
 288       obj->set_mark_raw(old_mark);


 293       const bool is_to_young = dest_state.is_young();
 294       assert(is_from_young == _g1h->heap_region_containing(old)->is_young(),
 295              "sanity");
 296       assert(is_to_young == _g1h->heap_region_containing(obj)->is_young(),
 297              "sanity");
 298       G1StringDedup::enqueue_from_evacuation(is_from_young,
 299                                              is_to_young,
 300                                              _worker_id,
 301                                              obj);
 302     }
 303 
 304     _surviving_young_words[young_index] += word_sz;
 305 
 306     if (obj->is_objArray() && arrayOop(obj)->length() >= ParGCArrayScanChunk) {
 307       // We keep track of the next start index in the length field of
 308       // the to-space object. The actual length can be found in the
 309       // length field of the from-space object.
 310       arrayOop(obj)->set_length(0);
 311       oop* old_p = set_partial_array_mask(old);
 312       do_oop_partial_array(old_p);
 313     } else {
 314       HeapRegion* const to_region = _g1h->heap_region_containing(obj_ptr);
 315       _scanner.set_region(to_region);
 316       obj->oop_iterate_backwards(&_scanner);
 317     }
 318     return obj;
 319   } else {
 320     _plab_allocator->undo_allocation(dest_state, obj_ptr, word_sz);
 321     return forward_ptr;
 322   }
 323 }
 324 
 325 G1ParScanThreadState* G1ParScanThreadStateSet::state_for_worker(uint worker_id) {
 326   assert(worker_id < _n_workers, "out of bounds access");
 327   if (_states[worker_id] == NULL) {
 328     _states[worker_id] = new G1ParScanThreadState(_g1h, worker_id, _young_cset_length);
 329   }
 330   return _states[worker_id];
 331 }
 332 
 333 const size_t* G1ParScanThreadStateSet::surviving_young_words() const {


 338 void G1ParScanThreadStateSet::flush() {
 339   assert(!_flushed, "thread local state from the per thread states should be flushed once");
 340 
 341   for (uint worker_index = 0; worker_index < _n_workers; ++worker_index) {
 342     G1ParScanThreadState* pss = _states[worker_index];
 343 
 344     if (pss == NULL) {
 345       continue;
 346     }
 347 
 348     pss->flush(_surviving_young_words_total);
 349     delete pss;
 350     _states[worker_index] = NULL;
 351   }
 352   _flushed = true;
 353 }
 354 
 355 oop G1ParScanThreadState::handle_evacuation_failure_par(oop old, markOop m) {
 356   assert(_g1h->is_in_cset(old), "Object " PTR_FORMAT " should be in the CSet", p2i(old));
 357 
 358   oop forward_ptr = old->forward_to_atomic(old, memory_order_relaxed);
 359   if (forward_ptr == NULL) {
 360     // Forward-to-self succeeded. We are the "owner" of the object.
 361     HeapRegion* r = _g1h->heap_region_containing(old);
 362 
 363     if (!r->evacuation_failed()) {
 364       r->set_evacuation_failed(true);
 365      _g1h->hr_printer()->evac_failure(r);
 366     }
 367 
 368     _g1h->preserve_mark_during_evac_failure(_worker_id, old, m);
 369 
 370     _scanner.set_region(r);
 371     old->oop_iterate_backwards(&_scanner);
 372 
 373     return old;
 374   } else {
 375     // Forward-to-self failed. Either someone else managed to allocate
 376     // space for this object (old != forward_ptr) or they beat us in
 377     // self-forwarding it (old == forward_ptr).
 378     assert(old == forward_ptr || !_g1h->is_in_cset(forward_ptr),




 248     }
 249   }
 250 
 251   assert(obj_ptr != NULL, "when we get here, allocation should have succeeded");
 252   assert(_g1h->is_in_reserved(obj_ptr), "Allocated memory should be in the heap");
 253 
 254 #ifndef PRODUCT
 255   // Should this evacuation fail?
 256   if (_g1h->evacuation_should_fail()) {
 257     // Doing this after all the allocation attempts also tests the
 258     // undo_allocation() method too.
 259     _plab_allocator->undo_allocation(dest_state, obj_ptr, word_sz);
 260     return handle_evacuation_failure_par(old, old_mark);
 261   }
 262 #endif // !PRODUCT
 263 
 264   // We're going to allocate linearly, so might as well prefetch ahead.
 265   Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes);
 266 
 267   const oop obj = oop(obj_ptr);
 268   const oop forward_ptr = old->forward_to_atomic(obj, old_mark, memory_order_relaxed);
 269   if (forward_ptr == NULL) {
 270     Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz);
 271 
 272     if (dest_state.is_young()) {
 273       if (age < markOopDesc::max_age) {
 274         age++;
 275       }
 276       if (old_mark->has_displaced_mark_helper()) {
 277         // In this case, we have to install the mark word first,
 278         // otherwise obj looks to be forwarded (the old mark word,
 279         // which contains the forward pointer, was copied)
 280         obj->set_mark_raw(old_mark);
 281         markOop new_mark = old_mark->displaced_mark_helper()->set_age(age);
 282         old_mark->set_displaced_mark_helper(new_mark);
 283       } else {
 284         obj->set_mark_raw(old_mark->set_age(age));
 285       }
 286       _age_table.add(age, word_sz);
 287     } else {
 288       obj->set_mark_raw(old_mark);


 293       const bool is_to_young = dest_state.is_young();
 294       assert(is_from_young == _g1h->heap_region_containing(old)->is_young(),
 295              "sanity");
 296       assert(is_to_young == _g1h->heap_region_containing(obj)->is_young(),
 297              "sanity");
 298       G1StringDedup::enqueue_from_evacuation(is_from_young,
 299                                              is_to_young,
 300                                              _worker_id,
 301                                              obj);
 302     }
 303 
 304     _surviving_young_words[young_index] += word_sz;
 305 
 306     if (obj->is_objArray() && arrayOop(obj)->length() >= ParGCArrayScanChunk) {
 307       // We keep track of the next start index in the length field of
 308       // the to-space object. The actual length can be found in the
 309       // length field of the from-space object.
 310       arrayOop(obj)->set_length(0);
 311       oop* old_p = set_partial_array_mask(old);
 312       do_oop_partial_array(old_p);
 313     } else if (!obj->is_typeArray()) {
 314       HeapRegion* const to_region = _g1h->heap_region_containing(obj_ptr);
 315       _scanner.set_region(to_region);
 316       obj->oop_iterate_backwards(&_scanner);
 317     }
 318     return obj;
 319   } else {
 320     _plab_allocator->undo_allocation(dest_state, obj_ptr, word_sz);
 321     return forward_ptr;
 322   }
 323 }
 324 
 325 G1ParScanThreadState* G1ParScanThreadStateSet::state_for_worker(uint worker_id) {
 326   assert(worker_id < _n_workers, "out of bounds access");
 327   if (_states[worker_id] == NULL) {
 328     _states[worker_id] = new G1ParScanThreadState(_g1h, worker_id, _young_cset_length);
 329   }
 330   return _states[worker_id];
 331 }
 332 
 333 const size_t* G1ParScanThreadStateSet::surviving_young_words() const {


 338 void G1ParScanThreadStateSet::flush() {
 339   assert(!_flushed, "thread local state from the per thread states should be flushed once");
 340 
 341   for (uint worker_index = 0; worker_index < _n_workers; ++worker_index) {
 342     G1ParScanThreadState* pss = _states[worker_index];
 343 
 344     if (pss == NULL) {
 345       continue;
 346     }
 347 
 348     pss->flush(_surviving_young_words_total);
 349     delete pss;
 350     _states[worker_index] = NULL;
 351   }
 352   _flushed = true;
 353 }
 354 
 355 oop G1ParScanThreadState::handle_evacuation_failure_par(oop old, markOop m) {
 356   assert(_g1h->is_in_cset(old), "Object " PTR_FORMAT " should be in the CSet", p2i(old));
 357 
 358   oop forward_ptr = old->forward_to_atomic(old, m, memory_order_relaxed);
 359   if (forward_ptr == NULL) {
 360     // Forward-to-self succeeded. We are the "owner" of the object.
 361     HeapRegion* r = _g1h->heap_region_containing(old);
 362 
 363     if (!r->evacuation_failed()) {
 364       r->set_evacuation_failed(true);
 365      _g1h->hr_printer()->evac_failure(r);
 366     }
 367 
 368     _g1h->preserve_mark_during_evac_failure(_worker_id, old, m);
 369 
 370     _scanner.set_region(r);
 371     old->oop_iterate_backwards(&_scanner);
 372 
 373     return old;
 374   } else {
 375     // Forward-to-self failed. Either someone else managed to allocate
 376     // space for this object (old != forward_ptr) or they beat us in
 377     // self-forwarding it (old == forward_ptr).
 378     assert(old == forward_ptr || !_g1h->is_in_cset(forward_ptr),


< prev index next >