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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9448
73d689add964
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP
aoqi@0 27
aoqi@0 28 #include "gc_interface/collectedHeap.hpp"
aoqi@0 29 #include "memory/threadLocalAllocBuffer.hpp"
aoqi@0 30 #include "runtime/atomic.hpp"
aoqi@0 31 #include "runtime/thread.hpp"
aoqi@0 32 #include "utilities/copy.hpp"
aoqi@0 33
aoqi@0 34 inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) {
aoqi@0 35 invariants();
aoqi@0 36 HeapWord* obj = top();
aoqi@0 37 if (pointer_delta(end(), obj) >= size) {
aoqi@0 38 // successful thread-local allocation
aoqi@0 39 #ifdef ASSERT
aoqi@0 40 // Skip mangling the space corresponding to the object header to
aoqi@0 41 // ensure that the returned space is not considered parsable by
aoqi@0 42 // any concurrent GC thread.
aoqi@0 43 size_t hdr_size = oopDesc::header_size();
aoqi@0 44 Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal);
aoqi@0 45 #endif // ASSERT
aoqi@0 46 // This addition is safe because we know that top is
aoqi@0 47 // at least size below end, so the add can't wrap.
aoqi@0 48 set_top(obj + size);
aoqi@0 49
aoqi@0 50 invariants();
aoqi@0 51 return obj;
aoqi@0 52 }
aoqi@0 53 return NULL;
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) {
aoqi@0 57 const size_t aligned_obj_size = align_object_size(obj_size);
aoqi@0 58
aoqi@0 59 // Compute the size for the new TLAB.
aoqi@0 60 // The "last" tlab may be smaller to reduce fragmentation.
aoqi@0 61 // unsafe_max_tlab_alloc is just a hint.
aoqi@0 62 const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(myThread()) /
aoqi@0 63 HeapWordSize;
aoqi@0 64 size_t new_tlab_size = MIN2(available_size, desired_size() + aligned_obj_size);
aoqi@0 65
aoqi@0 66 // Make sure there's enough room for object and filler int[].
aoqi@0 67 const size_t obj_plus_filler_size = aligned_obj_size + alignment_reserve();
aoqi@0 68 if (new_tlab_size < obj_plus_filler_size) {
aoqi@0 69 // If there isn't enough room for the allocation, return failure.
aoqi@0 70 if (PrintTLAB && Verbose) {
aoqi@0 71 gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")"
aoqi@0 72 " returns failure",
aoqi@0 73 obj_size);
aoqi@0 74 }
aoqi@0 75 return 0;
aoqi@0 76 }
aoqi@0 77 if (PrintTLAB && Verbose) {
aoqi@0 78 gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")"
aoqi@0 79 " returns " SIZE_FORMAT,
aoqi@0 80 obj_size, new_tlab_size);
aoqi@0 81 }
aoqi@0 82 return new_tlab_size;
aoqi@0 83 }
aoqi@0 84
aoqi@0 85
aoqi@0 86 void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) {
aoqi@0 87 // Raise size required to bypass TLAB next time. Why? Else there's
aoqi@0 88 // a risk that a thread that repeatedly allocates objects of one
aoqi@0 89 // size will get stuck on this slow path.
aoqi@0 90
aoqi@0 91 set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment());
aoqi@0 92
aoqi@0 93 _slow_allocations++;
aoqi@0 94
aoqi@0 95 if (PrintTLAB && Verbose) {
aoqi@0 96 Thread* thrd = myThread();
kevinw@9342 97 gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
kevinw@9342 98 " obj: " SIZE_FORMAT
kevinw@9342 99 " free: " SIZE_FORMAT
kevinw@9342 100 " waste: " SIZE_FORMAT "\n",
aoqi@0 101 "slow", p2i(thrd), thrd->osthread()->thread_id(),
aoqi@0 102 obj_size, free(), refill_waste_limit());
aoqi@0 103 }
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 #endif // SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP

mercurial