duke@435: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP stefank@2314: #define SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP stefank@2314: stefank@2314: #include "gc_interface/collectedHeap.hpp" stefank@2314: #include "memory/threadLocalAllocBuffer.hpp" stefank@2314: #include "runtime/atomic.hpp" stefank@2325: #include "runtime/thread.hpp" stefank@2314: #include "utilities/copy.hpp" stefank@2314: duke@435: inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) { duke@435: invariants(); duke@435: HeapWord* obj = top(); duke@435: if (pointer_delta(end(), obj) >= size) { duke@435: // successful thread-local allocation johnc@1600: #ifdef ASSERT johnc@1600: // Skip mangling the space corresponding to the object header to johnc@1600: // ensure that the returned space is not considered parsable by johnc@1600: // any concurrent GC thread. kvn@1926: size_t hdr_size = oopDesc::header_size(); johnc@1600: Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal); johnc@1600: #endif // ASSERT duke@435: // This addition is safe because we know that top is duke@435: // at least size below end, so the add can't wrap. duke@435: set_top(obj + size); duke@435: duke@435: invariants(); duke@435: return obj; duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) { duke@435: const size_t aligned_obj_size = align_object_size(obj_size); duke@435: duke@435: // Compute the size for the new TLAB. duke@435: // The "last" tlab may be smaller to reduce fragmentation. duke@435: // unsafe_max_tlab_alloc is just a hint. duke@435: const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / duke@435: HeapWordSize; duke@435: size_t new_tlab_size = MIN2(available_size, desired_size() + aligned_obj_size); duke@435: duke@435: // Make sure there's enough room for object and filler int[]. duke@435: const size_t obj_plus_filler_size = aligned_obj_size + alignment_reserve(); duke@435: if (new_tlab_size < obj_plus_filler_size) { duke@435: // If there isn't enough room for the allocation, return failure. duke@435: if (PrintTLAB && Verbose) { duke@435: gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" duke@435: " returns failure", duke@435: obj_size); duke@435: } duke@435: return 0; duke@435: } duke@435: if (PrintTLAB && Verbose) { duke@435: gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" duke@435: " returns " SIZE_FORMAT, duke@435: obj_size, new_tlab_size); duke@435: } duke@435: return new_tlab_size; duke@435: } duke@435: duke@435: duke@435: void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) { duke@435: // Raise size required to bypass TLAB next time. Why? Else there's duke@435: // a risk that a thread that repeatedly allocates objects of one duke@435: // size will get stuck on this slow path. duke@435: duke@435: set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment()); duke@435: duke@435: _slow_allocations++; duke@435: duke@435: if (PrintTLAB && Verbose) { duke@435: Thread* thrd = myThread(); duke@435: gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]" duke@435: " obj: "SIZE_FORMAT duke@435: " free: "SIZE_FORMAT duke@435: " waste: "SIZE_FORMAT"\n", duke@435: "slow", thrd, thrd->osthread()->thread_id(), duke@435: obj_size, free(), refill_waste_limit()); duke@435: } duke@435: } stefank@2314: stefank@2314: #endif // SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP