< prev index next >

src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp

Print this page
rev 56881 : imported patch 8233702-function-to-clamp-value-to-range


 115   if (end() != NULL) {
 116     invariants();
 117     thread()->incr_allocated_bytes(used_bytes());
 118     insert_filler();
 119     initialize(NULL, NULL, NULL);
 120   }
 121 }
 122 
 123 void ThreadLocalAllocBuffer::retire_before_allocation() {
 124   _slow_refill_waste += (unsigned int)remaining();
 125   retire();
 126 }
 127 
 128 void ThreadLocalAllocBuffer::resize() {
 129   // Compute the next tlab size using expected allocation amount
 130   assert(ResizeTLAB, "Should not call this otherwise");
 131   size_t alloc = (size_t)(_allocation_fraction.average() *
 132                           (Universe::heap()->tlab_capacity(thread()) / HeapWordSize));
 133   size_t new_size = alloc / _target_refills;
 134 
 135   new_size = MIN2(MAX2(new_size, min_size()), max_size());
 136 
 137   size_t aligned_new_size = align_object_size(new_size);
 138 
 139   log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
 140                       " refills %d  alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
 141                       p2i(thread()), thread()->osthread()->thread_id(),
 142                       _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
 143 
 144   set_desired_size(aligned_new_size);
 145   set_refill_waste_limit(initial_refill_waste_limit());
 146 }
 147 
 148 void ThreadLocalAllocBuffer::reset_statistics() {
 149   _number_of_refills = 0;
 150   _fast_refill_waste = 0;
 151   _slow_refill_waste = 0;
 152   _gc_waste          = 0;
 153   _slow_allocations  = 0;
 154   _allocated_size    = 0;
 155 }


 234   guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
 235   Thread::current()->tlab().initialize();
 236 
 237   log_develop_trace(gc, tlab)("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT,
 238                                min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
 239 }
 240 
 241 size_t ThreadLocalAllocBuffer::initial_desired_size() {
 242   size_t init_sz = 0;
 243 
 244   if (TLABSize > 0) {
 245     init_sz = TLABSize / HeapWordSize;
 246   } else {
 247     // Initial size is a function of the average number of allocating threads.
 248     unsigned int nof_threads = ThreadLocalAllocStats::allocating_threads_avg();
 249 
 250     init_sz  = (Universe::heap()->tlab_capacity(thread()) / HeapWordSize) /
 251                       (nof_threads * target_refills());
 252     init_sz = align_object_size(init_sz);
 253   }
 254   init_sz = MIN2(MAX2(init_sz, min_size()), max_size());
 255   return init_sz;
 256 }
 257 
 258 void ThreadLocalAllocBuffer::print_stats(const char* tag) {
 259   Log(gc, tlab) log;
 260   if (!log.is_trace()) {
 261     return;
 262   }
 263 
 264   Thread* thrd = thread();
 265   size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste;
 266   double waste_percent = percent_of(waste, _allocated_size);
 267   size_t tlab_used  = Universe::heap()->tlab_used(thrd);
 268   log.trace("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
 269             " desired_size: " SIZE_FORMAT "KB"
 270             " slow allocs: %d  refill waste: " SIZE_FORMAT "B"
 271             " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB"
 272             " slow: %dB fast: %dB",
 273             tag, p2i(thrd), thrd->osthread()->thread_id(),
 274             _desired_size / (K / HeapWordSize),




 115   if (end() != NULL) {
 116     invariants();
 117     thread()->incr_allocated_bytes(used_bytes());
 118     insert_filler();
 119     initialize(NULL, NULL, NULL);
 120   }
 121 }
 122 
 123 void ThreadLocalAllocBuffer::retire_before_allocation() {
 124   _slow_refill_waste += (unsigned int)remaining();
 125   retire();
 126 }
 127 
 128 void ThreadLocalAllocBuffer::resize() {
 129   // Compute the next tlab size using expected allocation amount
 130   assert(ResizeTLAB, "Should not call this otherwise");
 131   size_t alloc = (size_t)(_allocation_fraction.average() *
 132                           (Universe::heap()->tlab_capacity(thread()) / HeapWordSize));
 133   size_t new_size = alloc / _target_refills;
 134 
 135   new_size = clamp(new_size, min_size(), max_size());
 136 
 137   size_t aligned_new_size = align_object_size(new_size);
 138 
 139   log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
 140                       " refills %d  alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
 141                       p2i(thread()), thread()->osthread()->thread_id(),
 142                       _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
 143 
 144   set_desired_size(aligned_new_size);
 145   set_refill_waste_limit(initial_refill_waste_limit());
 146 }
 147 
 148 void ThreadLocalAllocBuffer::reset_statistics() {
 149   _number_of_refills = 0;
 150   _fast_refill_waste = 0;
 151   _slow_refill_waste = 0;
 152   _gc_waste          = 0;
 153   _slow_allocations  = 0;
 154   _allocated_size    = 0;
 155 }


 234   guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
 235   Thread::current()->tlab().initialize();
 236 
 237   log_develop_trace(gc, tlab)("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT,
 238                                min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
 239 }
 240 
 241 size_t ThreadLocalAllocBuffer::initial_desired_size() {
 242   size_t init_sz = 0;
 243 
 244   if (TLABSize > 0) {
 245     init_sz = TLABSize / HeapWordSize;
 246   } else {
 247     // Initial size is a function of the average number of allocating threads.
 248     unsigned int nof_threads = ThreadLocalAllocStats::allocating_threads_avg();
 249 
 250     init_sz  = (Universe::heap()->tlab_capacity(thread()) / HeapWordSize) /
 251                       (nof_threads * target_refills());
 252     init_sz = align_object_size(init_sz);
 253   }
 254   init_sz = clamp(init_sz, min_size(), max_size());
 255   return init_sz;
 256 }
 257 
 258 void ThreadLocalAllocBuffer::print_stats(const char* tag) {
 259   Log(gc, tlab) log;
 260   if (!log.is_trace()) {
 261     return;
 262   }
 263 
 264   Thread* thrd = thread();
 265   size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste;
 266   double waste_percent = percent_of(waste, _allocated_size);
 267   size_t tlab_used  = Universe::heap()->tlab_used(thrd);
 268   log.trace("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
 269             " desired_size: " SIZE_FORMAT "KB"
 270             " slow allocs: %d  refill waste: " SIZE_FORMAT "B"
 271             " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB"
 272             " slow: %dB fast: %dB",
 273             tag, p2i(thrd), thrd->osthread()->thread_id(),
 274             _desired_size / (K / HeapWordSize),


< prev index next >