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

Tue, 16 Feb 2016 21:42:29 +0000

author
poonam
date
Tue, 16 Feb 2016 21:42:29 +0000
changeset 8308
6acf14e730dd
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 9342
5792d995ed26
permissions
-rw-r--r--

8072725: Provide more granular levels for GC verification
Summary: Add option VerifySubSet to selectively verify the memory sub-systems
Reviewed-by: kevinw, jmasa

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

mercurial