threadLocalAllocBuffer.inline.hpp revision 8413:92457dfb91bd
192108Sphk/* 292108Sphk * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 392108Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 492108Sphk * 592108Sphk * This code is free software; you can redistribute it and/or modify it 692108Sphk * under the terms of the GNU General Public License version 2 only, as 792108Sphk * published by the Free Software Foundation. 892108Sphk * 992108Sphk * This code is distributed in the hope that it will be useful, but WITHOUT 1092108Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1192108Sphk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1292108Sphk * version 2 for more details (a copy is included in the LICENSE file that 1392108Sphk * accompanied this code). 1492108Sphk * 1592108Sphk * You should have received a copy of the GNU General Public License version 1692108Sphk * 2 along with this work; if not, write to the Free Software Foundation, 1792108Sphk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1892108Sphk * 1992108Sphk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2092108Sphk * or visit www.oracle.com if you need additional information or have any 2192108Sphk * questions. 2292108Sphk * 2392108Sphk */ 2492108Sphk 2592108Sphk#ifndef SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP 2692108Sphk#define SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP 2792108Sphk 2892108Sphk#include "gc/shared/collectedHeap.hpp" 2992108Sphk#include "gc/shared/threadLocalAllocBuffer.hpp" 3092108Sphk#include "runtime/thread.hpp" 3192108Sphk#include "utilities/copy.hpp" 3292108Sphk 3392108Sphkinline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) { 3492108Sphk invariants(); 3592108Sphk HeapWord* obj = top(); 36116196Sobrien if (pointer_delta(end(), obj) >= size) { 37116196Sobrien // successful thread-local allocation 38116196Sobrien#ifdef ASSERT 3992108Sphk // Skip mangling the space corresponding to the object header to 4092108Sphk // ensure that the returned space is not considered parsable by 4192108Sphk // any concurrent GC thread. 4292108Sphk size_t hdr_size = oopDesc::header_size(); 4392108Sphk Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal); 44223089Sgibbs#endif // ASSERT 4592108Sphk // This addition is safe because we know that top is 46238886Smav // at least size below end, so the add can't wrap. 4792108Sphk set_top(obj + size); 4892108Sphk 49130712Sphk invariants(); 5092108Sphk return obj; 5192108Sphk } 5292108Sphk return NULL; 5392108Sphk} 54114216Skan 5592108Sphkinline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) { 5695323Sphk const size_t aligned_obj_size = align_object_size(obj_size); 57223089Sgibbs 5892108Sphk // Compute the size for the new TLAB. 59223089Sgibbs // The "last" tlab may be smaller to reduce fragmentation. 60223089Sgibbs // unsafe_max_tlab_alloc is just a hint. 61223089Sgibbs const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / 62223089Sgibbs HeapWordSize; 63223089Sgibbs size_t new_tlab_size = MIN2(available_size, desired_size() + aligned_obj_size); 6492108Sphk 6592108Sphk // Make sure there's enough room for object and filler int[]. 6692108Sphk const size_t obj_plus_filler_size = aligned_obj_size + alignment_reserve(); 6792108Sphk if (new_tlab_size < obj_plus_filler_size) { 6892108Sphk // If there isn't enough room for the allocation, return failure. 6992108Sphk if (PrintTLAB && Verbose) { 70126080Sphk gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" 71111815Sphk " returns failure", 72111815Sphk obj_size); 73111815Sphk } 74111815Sphk return 0; 75111815Sphk } 76111815Sphk if (PrintTLAB && Verbose) { 77111815Sphk gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" 78126080Sphk " returns " SIZE_FORMAT, 7992108Sphk obj_size, new_tlab_size); 8092108Sphk } 8192108Sphk return new_tlab_size; 8292108Sphk} 83223089Sgibbs 8492108Sphk 8593248Sphkvoid ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) { 86112552Sphk // Raise size required to bypass TLAB next time. Why? Else there's 87133318Sphk // a risk that a thread that repeatedly allocates objects of one 88112552Sphk // size will get stuck on this slow path. 89133314Sphk 90223089Sgibbs set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment()); 9192108Sphk 9292108Sphk _slow_allocations++; 93115960Sphk 94105947Sphk if (PrintTLAB && Verbose) { 95105947Sphk Thread* thrd = myThread(); 96105947Sphk gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]" 97115960Sphk " obj: "SIZE_FORMAT 98105947Sphk " free: "SIZE_FORMAT 99115960Sphk " waste: "SIZE_FORMAT"\n", 100115960Sphk "slow", p2i(thrd), thrd->osthread()->thread_id(), 101115960Sphk obj_size, free(), refill_waste_limit()); 102115960Sphk } 103105947Sphk} 104105947Sphk 105105947Sphk#endif // SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP 106223089Sgibbs