< prev index next >

src/share/vm/memory/threadLocalAllocBuffer.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 183   set_refill_waste_limit(initial_refill_waste_limit());
 184 }
 185 
 186 void ThreadLocalAllocBuffer::initialize(HeapWord* start,
 187                                         HeapWord* top,
 188                                         HeapWord* end) {
 189   set_start(start);
 190   set_top(top);
 191   set_pf_top(top);
 192   set_end(end);
 193   invariants();
 194 }
 195 
 196 void ThreadLocalAllocBuffer::initialize() {
 197   initialize(NULL,                    // start
 198              NULL,                    // top
 199              NULL);                   // end
 200 
 201   set_desired_size(initial_desired_size());
 202 
 203   // Following check is needed because at startup the main (primordial)
 204   // thread is initialized before the heap is.  The initialization for
 205   // this thread is redone in startup_initialization below.
 206   if (Universe::heap() != NULL) {
 207     size_t capacity   = Universe::heap()->tlab_capacity(myThread()) / HeapWordSize;
 208     double alloc_frac = desired_size() * target_refills() / (double) capacity;
 209     _allocation_fraction.sample(alloc_frac);
 210   }
 211 
 212   set_refill_waste_limit(initial_refill_waste_limit());
 213 
 214   initialize_statistics();
 215 }
 216 
 217 void ThreadLocalAllocBuffer::startup_initialization() {
 218 
 219   // Assuming each thread's active tlab is, on average,
 220   // 1/2 full at a GC
 221   _target_refills = 100 / (2 * TLABWasteTargetPercent);
 222   _target_refills = MAX2(_target_refills, (unsigned)1U);
 223 
 224   _global_stats = new GlobalTLABStats();
 225 
 226   // During jvm startup, the main (primordial) thread is initialized
 227   // before the heap is initialized.  So reinitialize it now.
 228   guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
 229   Thread::current()->tlab().initialize();
 230 
 231   if (PrintTLAB && Verbose) {
 232     gclog_or_tty->print("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT "\n",
 233                         min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
 234   }
 235 }
 236 
 237 size_t ThreadLocalAllocBuffer::initial_desired_size() {
 238   size_t init_sz = 0;
 239 
 240   if (TLABSize > 0) {
 241     init_sz = TLABSize / HeapWordSize;
 242   } else if (global_stats() != NULL) {
 243     // Initial size is a function of the average number of allocating threads.
 244     unsigned nof_threads = global_stats()->allocating_threads_avg();
 245 
 246     init_sz  = (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize) /


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 183   set_refill_waste_limit(initial_refill_waste_limit());
 184 }
 185 
 186 void ThreadLocalAllocBuffer::initialize(HeapWord* start,
 187                                         HeapWord* top,
 188                                         HeapWord* end) {
 189   set_start(start);
 190   set_top(top);
 191   set_pf_top(top);
 192   set_end(end);
 193   invariants();
 194 }
 195 
 196 void ThreadLocalAllocBuffer::initialize() {
 197   initialize(NULL,                    // start
 198              NULL,                    // top
 199              NULL);                   // end
 200 
 201   set_desired_size(initial_desired_size());
 202 
 203   // Following check is needed because at startup the main
 204   // thread is initialized before the heap is.  The initialization for
 205   // this thread is redone in startup_initialization below.
 206   if (Universe::heap() != NULL) {
 207     size_t capacity   = Universe::heap()->tlab_capacity(myThread()) / HeapWordSize;
 208     double alloc_frac = desired_size() * target_refills() / (double) capacity;
 209     _allocation_fraction.sample(alloc_frac);
 210   }
 211 
 212   set_refill_waste_limit(initial_refill_waste_limit());
 213 
 214   initialize_statistics();
 215 }
 216 
 217 void ThreadLocalAllocBuffer::startup_initialization() {
 218 
 219   // Assuming each thread's active tlab is, on average,
 220   // 1/2 full at a GC
 221   _target_refills = 100 / (2 * TLABWasteTargetPercent);
 222   _target_refills = MAX2(_target_refills, (unsigned)1U);
 223 
 224   _global_stats = new GlobalTLABStats();
 225 
 226   // During jvm startup, the main thread is initialized
 227   // before the heap is initialized.  So reinitialize it now.
 228   guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
 229   Thread::current()->tlab().initialize();
 230 
 231   if (PrintTLAB && Verbose) {
 232     gclog_or_tty->print("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT "\n",
 233                         min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
 234   }
 235 }
 236 
 237 size_t ThreadLocalAllocBuffer::initial_desired_size() {
 238   size_t init_sz = 0;
 239 
 240   if (TLABSize > 0) {
 241     init_sz = TLABSize / HeapWordSize;
 242   } else if (global_stats() != NULL) {
 243     // Initial size is a function of the average number of allocating threads.
 244     unsigned nof_threads = global_stats()->allocating_threads_avg();
 245 
 246     init_sz  = (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize) /


< prev index next >