< prev index next >

src/share/vm/gc/g1/g1Allocator.cpp

Print this page
rev 8849 : imported patch 8003237-no-wait-for-free-list
rev 8850 : imported patch jon-fast-evac-failure
rev 8851 : imported patch bengt-jon-more-naming
rev 8854 : imported patch 8073013-add-detailed-information-about-plab-memory-usage
rev 8855 : imported patch jon-review-statistics
rev 8866 : imported patch 8067339-PLAB-reallocation-might-result-in-failure-to-allocate
rev 8867 : [mq]: bengt-refactoring


 215 }
 216 
 217 G1PLABAllocator::G1PLABAllocator(G1Allocator* allocator) :
 218   _g1h(G1CollectedHeap::heap()),
 219   _allocator(allocator),
 220   _survivor_alignment_bytes(calc_survivor_alignment_bytes()) {
 221   for (size_t i = 0; i < ARRAY_SIZE(_direct_allocated); i++) {
 222     _direct_allocated[i] = 0;
 223   }
 224 }
 225 
 226 bool G1PLABAllocator::may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const {
 227   return (allocation_word_sz * 100 < buffer_size * ParallelGCBufferWastePct);
 228 }
 229 
 230 HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(InCSetState dest,
 231                                                        size_t word_sz,
 232                                                        AllocationContext_t context,
 233                                                        bool* plab_refill_failed) {
 234   size_t plab_word_size = G1CollectedHeap::heap()->desired_plab_sz(dest);
 235   size_t required_in_plab = word_sz + PLAB::alignment_reserve();
 236 
 237   // Only get a new PLAB if the allocation fits and it would not waste more than
 238   // ParallelGCBufferWastePct in the existing buffer.
 239   if ((required_in_plab <= plab_word_size) &&
 240     may_throw_away_buffer(required_in_plab, plab_word_size)) {
 241 
 242     G1PLAB* alloc_buf = alloc_buffer(dest, context);
 243     alloc_buf->retire();
 244 
 245     HeapWord* buf = _allocator->par_allocate_during_gc(dest, plab_word_size, context);
 246     if (buf != NULL) {
 247       // Otherwise.
 248       alloc_buf->set_word_size(plab_word_size);
 249       alloc_buf->set_buf(buf);
 250 
 251       HeapWord* const obj = alloc_buf->allocate(word_sz);
 252       assert(obj != NULL, err_msg("PLAB should have been big enough, tried to allocate "
 253                                   SIZE_FORMAT " with alignment reserve " SIZE_FORMAT " PLAB size " SIZE_FORMAT,
 254                                   word_sz, PLAB::alignment_reserve(), plab_word_size));
 255       return obj;
 256     }
 257     // Otherwise.
 258     *plab_refill_failed = true;
 259   }
 260   // Try direct allocation.
 261   HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, context);
 262   if (result != NULL) {
 263     _direct_allocated[dest.value()] += word_sz;
 264   }
 265   return result;
 266 }
 267 
 268 void G1PLABAllocator::undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) {
 269   alloc_buffer(dest, context)->undo_allocation(obj, word_sz);
 270 }
 271 
 272 G1DefaultPLABAllocator::G1DefaultPLABAllocator(G1Allocator* allocator) :
 273   G1PLABAllocator(allocator),
 274   _surviving_alloc_buffer(_g1h->desired_plab_sz(InCSetState::Young)),




 215 }
 216 
 217 G1PLABAllocator::G1PLABAllocator(G1Allocator* allocator) :
 218   _g1h(G1CollectedHeap::heap()),
 219   _allocator(allocator),
 220   _survivor_alignment_bytes(calc_survivor_alignment_bytes()) {
 221   for (size_t i = 0; i < ARRAY_SIZE(_direct_allocated); i++) {
 222     _direct_allocated[i] = 0;
 223   }
 224 }
 225 
 226 bool G1PLABAllocator::may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const {
 227   return (allocation_word_sz * 100 < buffer_size * ParallelGCBufferWastePct);
 228 }
 229 
 230 HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(InCSetState dest,
 231                                                        size_t word_sz,
 232                                                        AllocationContext_t context,
 233                                                        bool* plab_refill_failed) {
 234   size_t plab_word_size = G1CollectedHeap::heap()->desired_plab_sz(dest);
 235   size_t required_in_plab = PLAB::size_required_for_allocation(word_sz);
 236 
 237   // Only get a new PLAB if the allocation fits and it would not waste more than
 238   // ParallelGCBufferWastePct in the existing buffer.
 239   if ((required_in_plab <= plab_word_size) &&
 240     may_throw_away_buffer(required_in_plab, plab_word_size)) {
 241 
 242     G1PLAB* alloc_buf = alloc_buffer(dest, context);
 243     alloc_buf->retire();
 244 
 245     HeapWord* buf = _allocator->par_allocate_during_gc(dest, plab_word_size, context);
 246     if (buf != NULL) {
 247       // Otherwise.
 248       alloc_buf->set_buf(buf, plab_word_size);

 249 
 250       HeapWord* const obj = alloc_buf->allocate(word_sz);
 251       assert(obj != NULL, err_msg("PLAB should have been big enough, tried to allocate "
 252                                   SIZE_FORMAT " requiring " SIZE_FORMAT " PLAB size " SIZE_FORMAT,
 253                                   word_sz, required_in_plab, plab_word_size));
 254       return obj;
 255     }
 256     // Otherwise.
 257     *plab_refill_failed = true;
 258   }
 259   // Try direct allocation.
 260   HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, context);
 261   if (result != NULL) {
 262     _direct_allocated[dest.value()] += word_sz;
 263   }
 264   return result;
 265 }
 266 
 267 void G1PLABAllocator::undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) {
 268   alloc_buffer(dest, context)->undo_allocation(obj, word_sz);
 269 }
 270 
 271 G1DefaultPLABAllocator::G1DefaultPLABAllocator(G1Allocator* allocator) :
 272   G1PLABAllocator(allocator),
 273   _surviving_alloc_buffer(_g1h->desired_plab_sz(InCSetState::Young)),


< prev index next >