author | stefank |
Fri, 14 Feb 2014 09:29:56 +0100 | |
changeset 22883 | 5378704451dc |
parent 7408 | c04a5c989f26 |
child 24424 | 2658d7834c6e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4636
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4636
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4636
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 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" |
|
7408
c04a5c989f26
7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents:
7397
diff
changeset
|
31 |
#include "runtime/thread.hpp" |
7397 | 32 |
#include "utilities/copy.hpp" |
33 |
||
1 | 34 |
inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) { |
35 |
invariants(); |
|
36 |
HeapWord* obj = top(); |
|
37 |
if (pointer_delta(end(), obj) >= size) { |
|
38 |
// successful thread-local allocation |
|
4636
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
39 |
#ifdef ASSERT |
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
40 |
// Skip mangling the space corresponding to the object header to |
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
41 |
// ensure that the returned space is not considered parsable by |
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
42 |
// any concurrent GC thread. |
5694
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
4636
diff
changeset
|
43 |
size_t hdr_size = oopDesc::header_size(); |
4636
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
44 |
Copy::fill_to_words(obj + hdr_size, size - hdr_size, badHeapWordVal); |
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
45 |
#endif // ASSERT |
1 | 46 |
// This addition is safe because we know that top is |
47 |
// at least size below end, so the add can't wrap. |
|
48 |
set_top(obj + size); |
|
49 |
||
50 |
invariants(); |
|
51 |
return obj; |
|
52 |
} |
|
53 |
return NULL; |
|
54 |
} |
|
55 |
||
56 |
inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) { |
|
57 |
const size_t aligned_obj_size = align_object_size(obj_size); |
|
58 |
||
59 |
// Compute the size for the new TLAB. |
|
60 |
// The "last" tlab may be smaller to reduce fragmentation. |
|
61 |
// unsafe_max_tlab_alloc is just a hint. |
|
62 |
const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / |
|
63 |
HeapWordSize; |
|
64 |
size_t new_tlab_size = MIN2(available_size, desired_size() + aligned_obj_size); |
|
65 |
||
66 |
// Make sure there's enough room for object and filler int[]. |
|
67 |
const size_t obj_plus_filler_size = aligned_obj_size + alignment_reserve(); |
|
68 |
if (new_tlab_size < obj_plus_filler_size) { |
|
69 |
// If there isn't enough room for the allocation, return failure. |
|
70 |
if (PrintTLAB && Verbose) { |
|
71 |
gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" |
|
72 |
" returns failure", |
|
73 |
obj_size); |
|
74 |
} |
|
75 |
return 0; |
|
76 |
} |
|
77 |
if (PrintTLAB && Verbose) { |
|
78 |
gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" |
|
79 |
" returns " SIZE_FORMAT, |
|
80 |
obj_size, new_tlab_size); |
|
81 |
} |
|
82 |
return new_tlab_size; |
|
83 |
} |
|
84 |
||
85 |
||
86 |
void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) { |
|
87 |
// Raise size required to bypass TLAB next time. Why? Else there's |
|
88 |
// a risk that a thread that repeatedly allocates objects of one |
|
89 |
// size will get stuck on this slow path. |
|
90 |
||
91 |
set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment()); |
|
92 |
||
93 |
_slow_allocations++; |
|
94 |
||
95 |
if (PrintTLAB && Verbose) { |
|
96 |
Thread* thrd = myThread(); |
|
97 |
gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]" |
|
98 |
" obj: "SIZE_FORMAT |
|
99 |
" free: "SIZE_FORMAT |
|
100 |
" waste: "SIZE_FORMAT"\n", |
|
101 |
"slow", thrd, thrd->osthread()->thread_id(), |
|
102 |
obj_size, free(), refill_waste_limit()); |
|
103 |
} |
|
104 |
} |
|
7397 | 105 |
|
106 |
#endif // SHARE_VM_MEMORY_THREADLOCALALLOCBUFFER_INLINE_HPP |