src/share/vm/memory/threadLocalAllocBuffer.inline.hpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2009, 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  *
  23  */
  24 








  25 inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
  26   invariants();
  27   HeapWord* obj = top();
  28   if (pointer_delta(end(), obj) >= size) {
  29     // successful thread-local allocation
  30 #ifdef ASSERT
  31     // Skip mangling the space corresponding to the object header to
  32     // ensure that the returned space is not considered parsable by
  33     // any concurrent GC thread.
  34     size_t hdr_size = oopDesc::header_size();
  35     Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal);
  36 #endif // ASSERT
  37     // This addition is safe because we know that top is
  38     // at least size below end, so the add can't wrap.
  39     set_top(obj + size);
  40 
  41     invariants();
  42     return obj;
  43   }
  44   return NULL;


  76 
  77 void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) {
  78   // Raise size required to bypass TLAB next time. Why? Else there's
  79   // a risk that a thread that repeatedly allocates objects of one
  80   // size will get stuck on this slow path.
  81 
  82   set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment());
  83 
  84   _slow_allocations++;
  85 
  86   if (PrintTLAB && Verbose) {
  87     Thread* thrd = myThread();
  88     gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]"
  89                         " obj: "SIZE_FORMAT
  90                         " free: "SIZE_FORMAT
  91                         " waste: "SIZE_FORMAT"\n",
  92                         "slow", thrd, thrd->osthread()->thread_id(),
  93                         obj_size, free(), refill_waste_limit());
  94   }
  95 }


   1 /*
   2  * Copyright (c) 1999, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP
  26 #define SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP
  27 
  28 #include "gc_interface/collectedHeap.hpp"
  29 #include "memory/threadLocalAllocBuffer.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "utilities/copy.hpp"
  32 
  33 inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
  34   invariants();
  35   HeapWord* obj = top();
  36   if (pointer_delta(end(), obj) >= size) {
  37     // successful thread-local allocation
  38 #ifdef ASSERT
  39     // Skip mangling the space corresponding to the object header to
  40     // ensure that the returned space is not considered parsable by
  41     // any concurrent GC thread.
  42     size_t hdr_size = oopDesc::header_size();
  43     Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal);
  44 #endif // ASSERT
  45     // This addition is safe because we know that top is
  46     // at least size below end, so the add can't wrap.
  47     set_top(obj + size);
  48 
  49     invariants();
  50     return obj;
  51   }
  52   return NULL;


  84 
  85 void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) {
  86   // Raise size required to bypass TLAB next time. Why? Else there's
  87   // a risk that a thread that repeatedly allocates objects of one
  88   // size will get stuck on this slow path.
  89 
  90   set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment());
  91 
  92   _slow_allocations++;
  93 
  94   if (PrintTLAB && Verbose) {
  95     Thread* thrd = myThread();
  96     gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]"
  97                         " obj: "SIZE_FORMAT
  98                         " free: "SIZE_FORMAT
  99                         " waste: "SIZE_FORMAT"\n",
 100                         "slow", thrd, thrd->osthread()->thread_id(),
 101                         obj_size, free(), refill_waste_limit());
 102   }
 103 }
 104 
 105 #endif // SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP