src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp
changeset 50882 80abf702eed8
parent 50578 e2a7f431f65c
child 51268 4ac20e5f96ce
equal deleted inserted replaced
50881:a21cad3fa448 50882:80abf702eed8
   183   print_stats("fill");
   183   print_stats("fill");
   184   assert(top <= start + new_size - alignment_reserve(), "size too small");
   184   assert(top <= start + new_size - alignment_reserve(), "size too small");
   185 
   185 
   186   initialize(start, top, start + new_size - alignment_reserve());
   186   initialize(start, top, start + new_size - alignment_reserve());
   187 
   187 
   188   if (ThreadHeapSampler::enabled()) {
       
   189     set_sample_end();
       
   190   }
       
   191 
       
   192   // Reset amount of internal fragmentation
   188   // Reset amount of internal fragmentation
   193   set_refill_waste_limit(initial_refill_waste_limit());
   189   set_refill_waste_limit(initial_refill_waste_limit());
   194 }
   190 }
   195 
   191 
   196 void ThreadLocalAllocBuffer::initialize(HeapWord* start,
   192 void ThreadLocalAllocBuffer::initialize(HeapWord* start,
   323 }
   319 }
   324 
   320 
   325 void ThreadLocalAllocBuffer::set_sample_end() {
   321 void ThreadLocalAllocBuffer::set_sample_end() {
   326   size_t heap_words_remaining = pointer_delta(_end, _top);
   322   size_t heap_words_remaining = pointer_delta(_end, _top);
   327   size_t bytes_until_sample = myThread()->heap_sampler().bytes_until_sample();
   323   size_t bytes_until_sample = myThread()->heap_sampler().bytes_until_sample();
   328   size_t words_until_sample = bytes_until_sample / HeapWordSize;;
   324   size_t words_until_sample = bytes_until_sample / HeapWordSize;
   329 
   325 
   330   if (heap_words_remaining > words_until_sample) {
   326   if (heap_words_remaining > words_until_sample) {
   331     HeapWord* new_end = _top + words_until_sample;
   327     HeapWord* new_end = _top + words_until_sample;
   332     set_end(new_end);
   328     set_end(new_end);
   333     _bytes_since_last_sample_point = bytes_until_sample;
   329     _bytes_since_last_sample_point = bytes_until_sample;
   334   } else {
   330   } else {
   335     _bytes_since_last_sample_point = heap_words_remaining * HeapWordSize;;
   331     _bytes_since_last_sample_point = heap_words_remaining * HeapWordSize;
   336   }
   332   }
   337 }
   333 }
   338 
   334 
   339 Thread* ThreadLocalAllocBuffer::myThread() {
   335 Thread* ThreadLocalAllocBuffer::myThread() {
   340   return (Thread*)(((char *)this) +
   336   return (Thread*)(((char *)this) +
   342                    in_bytes(Thread::tlab_start_offset()));
   338                    in_bytes(Thread::tlab_start_offset()));
   343 }
   339 }
   344 
   340 
   345 void ThreadLocalAllocBuffer::set_back_allocation_end() {
   341 void ThreadLocalAllocBuffer::set_back_allocation_end() {
   346   _end = _allocation_end;
   342   _end = _allocation_end;
   347 }
       
   348 
       
   349 HeapWord* ThreadLocalAllocBuffer::allocate_sampled_object(size_t size) {
       
   350   set_back_allocation_end();
       
   351   HeapWord* result = allocate(size);
       
   352 
       
   353   if (result) {
       
   354     myThread()->heap_sampler().check_for_sampling(result, size * HeapWordSize, _bytes_since_last_sample_point);
       
   355     set_sample_end();
       
   356   }
       
   357 
       
   358   return result;
       
   359 }
   343 }
   360 
   344 
   361 HeapWord* ThreadLocalAllocBuffer::hard_end() {
   345 HeapWord* ThreadLocalAllocBuffer::hard_end() {
   362   return _allocation_end + alignment_reserve();
   346   return _allocation_end + alignment_reserve();
   363 }
   347 }