author | stuefe |
Wed, 05 Jun 2019 07:25:09 +0200 | |
changeset 55217 | bb3359bcf534 |
parent 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51742
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51742
diff
changeset
|
25 |
#ifndef SHARE_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51742
diff
changeset
|
26 |
#define SHARE_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP |
7397 | 27 |
|
30764 | 28 |
#include "gc/shared/collectedHeap.hpp" |
29 |
#include "gc/shared/threadLocalAllocBuffer.hpp" |
|
54786 | 30 |
#include "memory/universe.hpp" |
35061 | 31 |
#include "logging/log.hpp" |
7408
c04a5c989f26
7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents:
7397
diff
changeset
|
32 |
#include "runtime/thread.hpp" |
7397 | 33 |
#include "utilities/copy.hpp" |
34 |
||
1 | 35 |
inline HeapWord* ThreadLocalAllocBuffer::allocate(size_t size) { |
36 |
invariants(); |
|
37 |
HeapWord* obj = top(); |
|
38 |
if (pointer_delta(end(), obj) >= size) { |
|
39 |
// 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
|
40 |
#ifdef ASSERT |
90e004691873
6902115: G1:assert(ignore_max_completed||thread->is_Java_thread()||SafepointSynchronize::is_at_safepoint())
johnc
parents:
1
diff
changeset
|
41 |
// 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
|
42 |
// 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
|
43 |
// 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
|
44 |
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
|
45 |
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
|
46 |
#endif // ASSERT |
1 | 47 |
// This addition is safe because we know that top is |
48 |
// at least size below end, so the add can't wrap. |
|
49 |
set_top(obj + size); |
|
50 |
||
51 |
invariants(); |
|
52 |
return obj; |
|
53 |
} |
|
54 |
return NULL; |
|
55 |
} |
|
56 |
||
57 |
inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) { |
|
58 |
// Compute the size for the new TLAB. |
|
59 |
// The "last" tlab may be smaller to reduce fragmentation. |
|
60 |
// unsafe_max_tlab_alloc is just a hint. |
|
51742
3dd95a83791b
8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents:
50866
diff
changeset
|
61 |
const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(thread()) / HeapWordSize; |
49945 | 62 |
size_t new_tlab_size = MIN3(available_size, desired_size() + align_object_size(obj_size), max_size()); |
1 | 63 |
|
64 |
// Make sure there's enough room for object and filler int[]. |
|
49945 | 65 |
if (new_tlab_size < compute_min_size(obj_size)) { |
1 | 66 |
// If there isn't enough room for the allocation, return failure. |
35061 | 67 |
log_trace(gc, tlab)("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ") returns failure", |
68 |
obj_size); |
|
1 | 69 |
return 0; |
70 |
} |
|
35061 | 71 |
log_trace(gc, tlab)("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ") returns " SIZE_FORMAT, |
72 |
obj_size, new_tlab_size); |
|
1 | 73 |
return new_tlab_size; |
74 |
} |
|
75 |
||
49945 | 76 |
inline size_t ThreadLocalAllocBuffer::compute_min_size(size_t obj_size) { |
77 |
const size_t aligned_obj_size = align_object_size(obj_size); |
|
78 |
const size_t size_with_reserve = aligned_obj_size + alignment_reserve(); |
|
50070
c036b84c6bbf
8202662: JFR tests fails: Could not find leak with class
sjohanss
parents:
49945
diff
changeset
|
79 |
return MAX2(size_with_reserve, heap_word_size(MinTLABSize)); |
49945 | 80 |
} |
1 | 81 |
|
82 |
void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) { |
|
83 |
// Raise size required to bypass TLAB next time. Why? Else there's |
|
84 |
// a risk that a thread that repeatedly allocates objects of one |
|
85 |
// size will get stuck on this slow path. |
|
86 |
||
87 |
set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment()); |
|
88 |
||
89 |
_slow_allocations++; |
|
90 |
||
35061 | 91 |
log_develop_trace(gc, tlab)("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" |
92 |
" obj: " SIZE_FORMAT |
|
93 |
" free: " SIZE_FORMAT |
|
94 |
" waste: " SIZE_FORMAT, |
|
51742
3dd95a83791b
8210710: Rename ThreadLocalAllocBuffer::myThread() to thread()
pliden
parents:
50866
diff
changeset
|
95 |
"slow", p2i(thread()), thread()->osthread()->thread_id(), |
35061 | 96 |
obj_size, free(), refill_waste_limit()); |
1 | 97 |
} |
7397 | 98 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51742
diff
changeset
|
99 |
#endif // SHARE_GC_SHARED_THREADLOCALALLOCBUFFER_INLINE_HPP |