src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp

Print this page
rev 6670 : fast reclaim main patch


 159   assert( (from_region->is_young() && young_index >  0) ||
 160          (!from_region->is_young() && young_index == 0), "invariant" );
 161   G1CollectorPolicy* g1p = _g1h->g1_policy();
 162   markOop m = old->mark();
 163   int age = m->has_displaced_mark_helper() ? m->displaced_mark_helper()->age()
 164                                            : m->age();
 165   GCAllocPurpose alloc_purpose = g1p->evacuation_destination(from_region, age,
 166                                                              word_sz);
 167   HeapWord* obj_ptr = allocate(alloc_purpose, word_sz);
 168 #ifndef PRODUCT
 169   // Should this evacuation fail?
 170   if (_g1h->evacuation_should_fail()) {
 171     if (obj_ptr != NULL) {
 172       undo_allocation(alloc_purpose, obj_ptr, word_sz);
 173       obj_ptr = NULL;
 174     }
 175   }
 176 #endif // !PRODUCT
 177 
 178   if (obj_ptr == NULL) {






 179     // This will either forward-to-self, or detect that someone else has
 180     // installed a forwarding pointer.
 181     return _g1h->handle_evacuation_failure_par(this, old);
 182   }
 183 
 184   oop obj = oop(obj_ptr);
 185 
 186   // We're going to allocate linearly, so might as well prefetch ahead.
 187   Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes);
 188 
 189   oop forward_ptr = old->forward_to_atomic(obj);
 190   if (forward_ptr == NULL) {
 191     Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz);
 192 
 193     // alloc_purpose is just a hint to allocate() above, recheck the type of region
 194     // we actually allocated from and update alloc_purpose accordingly
 195     HeapRegion* to_region = _g1h->heap_region_containing_raw(obj_ptr);
 196     alloc_purpose = to_region->is_young() ? GCAllocForSurvived : GCAllocForTenured;
 197 
 198     if (g1p->track_object_age(alloc_purpose)) {


 236       // We keep track of the next start index in the length field of
 237       // the to-space object. The actual length can be found in the
 238       // length field of the from-space object.
 239       arrayOop(obj)->set_length(0);
 240       oop* old_p = set_partial_array_mask(old);
 241       push_on_queue(old_p);
 242     } else {
 243       // No point in using the slower heap_region_containing() method,
 244       // given that we know obj is in the heap.
 245       _scanner.set_region(_g1h->heap_region_containing_raw(obj));
 246       obj->oop_iterate_backwards(&_scanner);
 247     }
 248   } else {
 249     undo_allocation(alloc_purpose, obj_ptr, word_sz);
 250     obj = forward_ptr;
 251   }
 252   return obj;
 253 }
 254 
 255 HeapWord* G1ParScanThreadState::allocate_slow(GCAllocPurpose purpose, size_t word_sz) {






 256   HeapWord* obj = NULL;
 257   size_t gclab_word_size = _g1h->desired_plab_sz(purpose);
 258   if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) {
 259     G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose);
 260     add_to_alloc_buffer_waste(alloc_buf->words_remaining());
 261     alloc_buf->retire(false /* end_of_gc */, false /* retain */);
 262 
 263     HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size);
 264     if (buf == NULL) {
 265       return NULL; // Let caller handle allocation failure.
 266     }
 267     // Otherwise.
 268     alloc_buf->set_word_size(gclab_word_size);
 269     alloc_buf->set_buf(buf);
 270 
 271     obj = alloc_buf->allocate(word_sz);
 272     assert(obj != NULL, "buffer was definitely big enough...");
 273   } else {
 274     obj = _g1h->par_allocate_during_gc(purpose, word_sz);
 275   }




 159   assert( (from_region->is_young() && young_index >  0) ||
 160          (!from_region->is_young() && young_index == 0), "invariant" );
 161   G1CollectorPolicy* g1p = _g1h->g1_policy();
 162   markOop m = old->mark();
 163   int age = m->has_displaced_mark_helper() ? m->displaced_mark_helper()->age()
 164                                            : m->age();
 165   GCAllocPurpose alloc_purpose = g1p->evacuation_destination(from_region, age,
 166                                                              word_sz);
 167   HeapWord* obj_ptr = allocate(alloc_purpose, word_sz);
 168 #ifndef PRODUCT
 169   // Should this evacuation fail?
 170   if (_g1h->evacuation_should_fail()) {
 171     if (obj_ptr != NULL) {
 172       undo_allocation(alloc_purpose, obj_ptr, word_sz);
 173       obj_ptr = NULL;
 174     }
 175   }
 176 #endif // !PRODUCT
 177 
 178   if (obj_ptr == NULL) {
 179     // The allocation failure may have been caused by attempted allocation of a
 180     // humongous object. Detect this and process appropriately.
 181     if (_g1h->isHumongous(word_sz)) {
 182       _g1h->set_humongous_is_live(old);
 183       return NULL;
 184     }
 185     // This will either forward-to-self, or detect that someone else has
 186     // installed a forwarding pointer.
 187     return _g1h->handle_evacuation_failure_par(this, old);
 188   }
 189 
 190   oop obj = oop(obj_ptr);
 191 
 192   // We're going to allocate linearly, so might as well prefetch ahead.
 193   Prefetch::write(obj_ptr, PrefetchCopyIntervalInBytes);
 194 
 195   oop forward_ptr = old->forward_to_atomic(obj);
 196   if (forward_ptr == NULL) {
 197     Copy::aligned_disjoint_words((HeapWord*) old, obj_ptr, word_sz);
 198 
 199     // alloc_purpose is just a hint to allocate() above, recheck the type of region
 200     // we actually allocated from and update alloc_purpose accordingly
 201     HeapRegion* to_region = _g1h->heap_region_containing_raw(obj_ptr);
 202     alloc_purpose = to_region->is_young() ? GCAllocForSurvived : GCAllocForTenured;
 203 
 204     if (g1p->track_object_age(alloc_purpose)) {


 242       // We keep track of the next start index in the length field of
 243       // the to-space object. The actual length can be found in the
 244       // length field of the from-space object.
 245       arrayOop(obj)->set_length(0);
 246       oop* old_p = set_partial_array_mask(old);
 247       push_on_queue(old_p);
 248     } else {
 249       // No point in using the slower heap_region_containing() method,
 250       // given that we know obj is in the heap.
 251       _scanner.set_region(_g1h->heap_region_containing_raw(obj));
 252       obj->oop_iterate_backwards(&_scanner);
 253     }
 254   } else {
 255     undo_allocation(alloc_purpose, obj_ptr, word_sz);
 256     obj = forward_ptr;
 257   }
 258   return obj;
 259 }
 260 
 261 HeapWord* G1ParScanThreadState::allocate_slow(GCAllocPurpose purpose, size_t word_sz) {
 262   // We may have reached the slow path because we tried to allocate memory for a
 263   // humongous object. This just indicates that that humongous object is live
 264   // though.
 265   if (_g1h->isHumongous(word_sz)) {
 266     return NULL;
 267   }
 268   HeapWord* obj = NULL;
 269   size_t gclab_word_size = _g1h->desired_plab_sz(purpose);
 270   if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) {
 271     G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose);
 272     add_to_alloc_buffer_waste(alloc_buf->words_remaining());
 273     alloc_buf->retire(false /* end_of_gc */, false /* retain */);
 274 
 275     HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size);
 276     if (buf == NULL) {
 277       return NULL; // Let caller handle allocation failure.
 278     }
 279     // Otherwise.
 280     alloc_buf->set_word_size(gclab_word_size);
 281     alloc_buf->set_buf(buf);
 282 
 283     obj = alloc_buf->allocate(word_sz);
 284     assert(obj != NULL, "buffer was definitely big enough...");
 285   } else {
 286     obj = _g1h->par_allocate_during_gc(purpose, word_sz);
 287   }