author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58291 | a013100f7a35 |
permissions | -rw-r--r-- |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
1 |
/* |
54659 | 2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
4 |
* |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
8 |
* |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
13 |
* accompanied this code). |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
14 |
* |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
18 |
* |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
21 |
* questions. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
22 |
* |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
23 |
*/ |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
24 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
26 |
#include "classfile/javaClasses.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
27 |
#include "gc/shared/allocTracer.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
28 |
#include "gc/shared/collectedHeap.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
29 |
#include "gc/shared/memAllocator.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
30 |
#include "gc/shared/threadLocalAllocBuffer.inline.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
31 |
#include "memory/universe.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
32 |
#include "oops/arrayOop.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
33 |
#include "oops/oop.inline.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
34 |
#include "prims/jvmtiExport.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
35 |
#include "runtime/sharedRuntime.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
36 |
#include "runtime/handles.inline.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
37 |
#include "runtime/thread.inline.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
38 |
#include "services/lowMemoryDetector.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
39 |
#include "utilities/align.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
40 |
#include "utilities/copy.hpp" |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
41 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
42 |
class MemAllocator::Allocation: StackObj { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
43 |
friend class MemAllocator; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
44 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
45 |
const MemAllocator& _allocator; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
46 |
Thread* _thread; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
47 |
oop* _obj_ptr; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
48 |
bool _overhead_limit_exceeded; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
49 |
bool _allocated_outside_tlab; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
50 |
size_t _allocated_tlab_size; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
51 |
bool _tlab_end_reset_for_sample; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
52 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
53 |
bool check_out_of_memory(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
54 |
void verify_before(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
55 |
void verify_after(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
56 |
void notify_allocation(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
57 |
void notify_allocation_jvmti_allocation_event(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
58 |
void notify_allocation_jvmti_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
59 |
void notify_allocation_low_memory_detector(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
60 |
void notify_allocation_jfr_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
61 |
void notify_allocation_dtrace_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
62 |
void check_for_bad_heap_word_value() const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
63 |
#ifdef ASSERT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
64 |
void check_for_valid_allocation_state() const; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
65 |
#endif |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
66 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
67 |
class PreserveObj; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
68 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
69 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
70 |
Allocation(const MemAllocator& allocator, oop* obj_ptr) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
71 |
: _allocator(allocator), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
72 |
_thread(Thread::current()), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
73 |
_obj_ptr(obj_ptr), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
74 |
_overhead_limit_exceeded(false), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
75 |
_allocated_outside_tlab(false), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
76 |
_allocated_tlab_size(0), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
77 |
_tlab_end_reset_for_sample(false) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
78 |
{ |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
79 |
verify_before(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
80 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
81 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
82 |
~Allocation() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
83 |
if (!check_out_of_memory()) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
84 |
verify_after(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
85 |
notify_allocation(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
86 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
87 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
88 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
89 |
oop obj() const { return *_obj_ptr; } |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
90 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
91 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
92 |
class MemAllocator::Allocation::PreserveObj: StackObj { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
93 |
HandleMark _handle_mark; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
94 |
Handle _handle; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
95 |
oop* const _obj_ptr; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
96 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
97 |
public: |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
98 |
PreserveObj(Thread* thread, oop* obj_ptr) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
99 |
: _handle_mark(thread), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
100 |
_handle(thread, *obj_ptr), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
101 |
_obj_ptr(obj_ptr) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
102 |
{ |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
103 |
*obj_ptr = NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
104 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
105 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
106 |
~PreserveObj() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
107 |
*_obj_ptr = _handle(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
108 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
109 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
110 |
oop operator()() const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
111 |
return _handle(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
112 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
113 |
}; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
114 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
115 |
bool MemAllocator::Allocation::check_out_of_memory() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
116 |
Thread* THREAD = _thread; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
117 |
assert(!HAS_PENDING_EXCEPTION, "Unexpected exception, will result in uninitialized storage"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
118 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
119 |
if (obj() != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
120 |
return false; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
121 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
122 |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
123 |
const char* message = _overhead_limit_exceeded ? "GC overhead limit exceeded" : "Java heap space"; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
124 |
if (!THREAD->in_retryable_allocation()) { |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
125 |
// -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
126 |
report_java_out_of_memory(message); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
127 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
128 |
if (JvmtiExport::should_post_resource_exhausted()) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
129 |
JvmtiExport::post_resource_exhausted( |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
130 |
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
131 |
message); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
132 |
} |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
133 |
oop exception = _overhead_limit_exceeded ? |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
134 |
Universe::out_of_memory_error_gc_overhead_limit() : |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
135 |
Universe::out_of_memory_error_java_heap(); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
136 |
THROW_OOP_(exception, true); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
137 |
} else { |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51817
diff
changeset
|
138 |
THROW_OOP_(Universe::out_of_memory_error_retry(), true); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
139 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
140 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
141 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
142 |
void MemAllocator::Allocation::verify_before() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
143 |
// Clear unhandled oops for memory allocation. Memory allocation might |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
144 |
// not take out a lock if from tlab, so clear here. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
145 |
Thread* THREAD = _thread; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
146 |
assert(!HAS_PENDING_EXCEPTION, "Should not allocate with exception pending"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
147 |
debug_only(check_for_valid_allocation_state()); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
148 |
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
149 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
150 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
151 |
void MemAllocator::Allocation::verify_after() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
152 |
NOT_PRODUCT(check_for_bad_heap_word_value();) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
153 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
154 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
155 |
void MemAllocator::Allocation::check_for_bad_heap_word_value() const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
156 |
MemRegion obj_range = _allocator.obj_memory_range(obj()); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
157 |
HeapWord* addr = obj_range.start(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
158 |
size_t size = obj_range.word_size(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
159 |
if (CheckMemoryInitialization && ZapUnusedHeapArea) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
160 |
for (size_t slot = 0; slot < size; slot += 1) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
161 |
assert((*(intptr_t*) (addr + slot)) != ((intptr_t) badHeapWordVal), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
162 |
"Found badHeapWordValue in post-allocation check"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
163 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
164 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
165 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
166 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
167 |
#ifdef ASSERT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
168 |
void MemAllocator::Allocation::check_for_valid_allocation_state() const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
169 |
// How to choose between a pending exception and a potential |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
170 |
// OutOfMemoryError? Don't allow pending exceptions. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
171 |
// This is a VM policy failure, so how do we exhaustively test it? |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
172 |
assert(!_thread->has_pending_exception(), |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
173 |
"shouldn't be allocating with pending exception"); |
58291
a013100f7a35
8213150: Add verification for locking by VMThread
coleenp
parents:
57850
diff
changeset
|
174 |
// Allocation of an oop can always invoke a safepoint. |
a013100f7a35
8213150: Add verification for locking by VMThread
coleenp
parents:
57850
diff
changeset
|
175 |
_thread->check_for_valid_safepoint_state(); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
176 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
177 |
#endif |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
178 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
179 |
void MemAllocator::Allocation::notify_allocation_jvmti_sampler() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
180 |
// support for JVMTI VMObjectAlloc event (no-op if not enabled) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
181 |
JvmtiExport::vm_object_alloc_event_collector(obj()); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
182 |
|
52131
e9727e6b5fc1
8211980: Remove ThreadHeapSampler enable/disable/enabled methods
jcbeyler
parents:
52077
diff
changeset
|
183 |
if (!JvmtiExport::should_post_sampled_object_alloc()) { |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
184 |
// Sampling disabled |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
185 |
return; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
186 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
187 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
188 |
if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
189 |
// Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
190 |
// or expands it due to taking a sampler induced slow path. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
191 |
return; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
192 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
193 |
|
54659 | 194 |
// If we want to be sampling, protect the allocated object with a Handle |
195 |
// before doing the callback. The callback is done in the destructor of |
|
196 |
// the JvmtiSampledObjectAllocEventCollector. |
|
197 |
size_t bytes_since_last = 0; |
|
198 |
||
199 |
{ |
|
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
200 |
PreserveObj obj_h(_thread, _obj_ptr); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
201 |
JvmtiSampledObjectAllocEventCollector collector; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
202 |
size_t size_in_bytes = _allocator._word_size * HeapWordSize; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
203 |
ThreadLocalAllocBuffer& tlab = _thread->tlab(); |
54659 | 204 |
|
205 |
if (!_allocated_outside_tlab) { |
|
206 |
bytes_since_last = tlab.bytes_since_last_sample_point(); |
|
207 |
} |
|
208 |
||
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
209 |
_thread->heap_sampler().check_for_sampling(obj_h(), size_in_bytes, bytes_since_last); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
210 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
211 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
212 |
if (_tlab_end_reset_for_sample || _allocated_tlab_size != 0) { |
54659 | 213 |
// Tell tlab to forget bytes_since_last if we passed it to the heap sampler. |
214 |
_thread->tlab().set_sample_end(bytes_since_last != 0); |
|
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
215 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
216 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
217 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
218 |
void MemAllocator::Allocation::notify_allocation_low_memory_detector() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
219 |
// support low memory notifications (no-op if not enabled) |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
220 |
LowMemoryDetector::detect_low_memory_for_collected_pools(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
221 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
222 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
223 |
void MemAllocator::Allocation::notify_allocation_jfr_sampler() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
224 |
HeapWord* mem = (HeapWord*)obj(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
225 |
size_t size_in_bytes = _allocator._word_size * HeapWordSize; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
226 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
227 |
if (_allocated_outside_tlab) { |
57850 | 228 |
AllocTracer::send_allocation_outside_tlab(obj()->klass(), mem, size_in_bytes, _thread); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
229 |
} else if (_allocated_tlab_size != 0) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
230 |
// TLAB was refilled |
57850 | 231 |
AllocTracer::send_allocation_in_new_tlab(obj()->klass(), mem, _allocated_tlab_size * HeapWordSize, |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
232 |
size_in_bytes, _thread); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
233 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
234 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
235 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
236 |
void MemAllocator::Allocation::notify_allocation_dtrace_sampler() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
237 |
if (DTraceAllocProbes) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
238 |
// support for Dtrace object alloc event (no-op most of the time) |
57850 | 239 |
Klass* klass = obj()->klass(); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
240 |
size_t word_size = _allocator._word_size; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
241 |
if (klass != NULL && klass->name() != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
242 |
SharedRuntime::dtrace_object_alloc(obj(), (int)word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
243 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
244 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
245 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
246 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
247 |
void MemAllocator::Allocation::notify_allocation() { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
248 |
notify_allocation_low_memory_detector(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
249 |
notify_allocation_jfr_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
250 |
notify_allocation_dtrace_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
251 |
notify_allocation_jvmti_sampler(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
252 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
253 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
254 |
HeapWord* MemAllocator::allocate_outside_tlab(Allocation& allocation) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
255 |
allocation._allocated_outside_tlab = true; |
54784
31b27600b5db
8223622: Move Universe usage out of memAllocator.hpp
stefank
parents:
54659
diff
changeset
|
256 |
HeapWord* mem = Universe::heap()->mem_allocate(_word_size, &allocation._overhead_limit_exceeded); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
257 |
if (mem == NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
258 |
return mem; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
259 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
260 |
|
54784
31b27600b5db
8223622: Move Universe usage out of memAllocator.hpp
stefank
parents:
54659
diff
changeset
|
261 |
NOT_PRODUCT(Universe::heap()->check_for_non_bad_heap_word_value(mem, _word_size)); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
262 |
size_t size_in_bytes = _word_size * HeapWordSize; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
263 |
_thread->incr_allocated_bytes(size_in_bytes); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
264 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
265 |
return mem; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
266 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
267 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
268 |
HeapWord* MemAllocator::allocate_inside_tlab(Allocation& allocation) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
269 |
assert(UseTLAB, "should use UseTLAB"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
270 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
271 |
// Try allocating from an existing TLAB. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
272 |
HeapWord* mem = _thread->tlab().allocate(_word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
273 |
if (mem != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
274 |
return mem; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
275 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
276 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
277 |
// Try refilling the TLAB and allocating the object in it. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
278 |
return allocate_inside_tlab_slow(allocation); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
279 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
280 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
281 |
HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
282 |
HeapWord* mem = NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
283 |
ThreadLocalAllocBuffer& tlab = _thread->tlab(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
284 |
|
52131
e9727e6b5fc1
8211980: Remove ThreadHeapSampler enable/disable/enabled methods
jcbeyler
parents:
52077
diff
changeset
|
285 |
if (JvmtiExport::should_post_sampled_object_alloc()) { |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
286 |
tlab.set_back_allocation_end(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
287 |
mem = tlab.allocate(_word_size); |
54659 | 288 |
|
289 |
// We set back the allocation sample point to try to allocate this, reset it |
|
290 |
// when done. |
|
291 |
allocation._tlab_end_reset_for_sample = true; |
|
292 |
||
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
293 |
if (mem != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
294 |
return mem; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
295 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
296 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
297 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
298 |
// Retain tlab and allocate object in shared space if |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
299 |
// the amount free in the tlab is too large to discard. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
300 |
if (tlab.free() > tlab.refill_waste_limit()) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
301 |
tlab.record_slow_allocation(_word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
302 |
return NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
303 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
304 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
305 |
// Discard tlab and allocate a new one. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
306 |
// To minimize fragmentation, the last TLAB may be smaller than the rest. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
307 |
size_t new_tlab_size = tlab.compute_size(_word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
308 |
|
51817
46eac084082d
8210857: Allow retiring TLABs and collecting statistics in parallel
pliden
parents:
50882
diff
changeset
|
309 |
tlab.retire_before_allocation(); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
310 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
311 |
if (new_tlab_size == 0) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
312 |
return NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
313 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
314 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
315 |
// Allocate a new TLAB requesting new_tlab_size. Any size |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
316 |
// between minimal and new_tlab_size is accepted. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
317 |
size_t min_tlab_size = ThreadLocalAllocBuffer::compute_min_size(_word_size); |
54784
31b27600b5db
8223622: Move Universe usage out of memAllocator.hpp
stefank
parents:
54659
diff
changeset
|
318 |
mem = Universe::heap()->allocate_new_tlab(min_tlab_size, new_tlab_size, &allocation._allocated_tlab_size); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
319 |
if (mem == NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
320 |
assert(allocation._allocated_tlab_size == 0, |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
321 |
"Allocation failed, but actual size was updated. min: " SIZE_FORMAT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
322 |
", desired: " SIZE_FORMAT ", actual: " SIZE_FORMAT, |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
323 |
min_tlab_size, new_tlab_size, allocation._allocated_tlab_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
324 |
return NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
325 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
326 |
assert(allocation._allocated_tlab_size != 0, "Allocation succeeded but actual size not updated. mem at: " |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
327 |
PTR_FORMAT " min: " SIZE_FORMAT ", desired: " SIZE_FORMAT, |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
328 |
p2i(mem), min_tlab_size, new_tlab_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
329 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
330 |
if (ZeroTLAB) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
331 |
// ..and clear it. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
332 |
Copy::zero_to_words(mem, allocation._allocated_tlab_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
333 |
} else { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
334 |
// ...and zap just allocated object. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
335 |
#ifdef ASSERT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
336 |
// Skip mangling the space corresponding to the object header to |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
337 |
// ensure that the returned space is not considered parsable by |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
338 |
// any concurrent GC thread. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
339 |
size_t hdr_size = oopDesc::header_size(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
340 |
Copy::fill_to_words(mem + hdr_size, allocation._allocated_tlab_size - hdr_size, badHeapWordVal); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
341 |
#endif // ASSERT |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
342 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
343 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
344 |
tlab.fill(mem, mem + _word_size, allocation._allocated_tlab_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
345 |
return mem; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
346 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
347 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
348 |
HeapWord* MemAllocator::mem_allocate(Allocation& allocation) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
349 |
if (UseTLAB) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
350 |
HeapWord* result = allocate_inside_tlab(allocation); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
351 |
if (result != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
352 |
return result; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
353 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
354 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
355 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
356 |
return allocate_outside_tlab(allocation); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
357 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
358 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
359 |
oop MemAllocator::allocate() const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
360 |
oop obj = NULL; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
361 |
{ |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
362 |
Allocation allocation(*this, &obj); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
363 |
HeapWord* mem = mem_allocate(allocation); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
364 |
if (mem != NULL) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
365 |
obj = initialize(mem); |
55734
51f5b4c29626
8227766: CheckUnhandledOops is broken in MemAllocator
coleenp
parents:
54784
diff
changeset
|
366 |
} else { |
51f5b4c29626
8227766: CheckUnhandledOops is broken in MemAllocator
coleenp
parents:
54784
diff
changeset
|
367 |
// The unhandled oop detector will poison local variable obj, |
51f5b4c29626
8227766: CheckUnhandledOops is broken in MemAllocator
coleenp
parents:
54784
diff
changeset
|
368 |
// so reset it to NULL if mem is NULL. |
51f5b4c29626
8227766: CheckUnhandledOops is broken in MemAllocator
coleenp
parents:
54784
diff
changeset
|
369 |
obj = NULL; |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
370 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
371 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
372 |
return obj; |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
373 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
374 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
375 |
void MemAllocator::mem_clear(HeapWord* mem) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
376 |
assert(mem != NULL, "cannot initialize NULL object"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
377 |
const size_t hs = oopDesc::header_size(); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
378 |
assert(_word_size >= hs, "unexpected object size"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
379 |
oopDesc::set_klass_gap(mem, 0); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
380 |
Copy::fill_to_aligned_words(mem + hs, _word_size - hs); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
381 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
382 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
383 |
oop MemAllocator::finish(HeapWord* mem) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
384 |
assert(mem != NULL, "NULL object pointer"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
385 |
if (UseBiasedLocking) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
386 |
oopDesc::set_mark_raw(mem, _klass->prototype_header()); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
387 |
} else { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
388 |
// May be bootstrapping |
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
57745
diff
changeset
|
389 |
oopDesc::set_mark_raw(mem, markWord::prototype()); |
50882
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
390 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
391 |
// Need a release store to ensure array/class length, mark word, and |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
392 |
// object zeroing are visible before setting the klass non-NULL, for |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
393 |
// concurrent collectors. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
394 |
oopDesc::release_set_klass(mem, _klass); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
395 |
return oop(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
396 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
397 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
398 |
oop ObjAllocator::initialize(HeapWord* mem) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
399 |
mem_clear(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
400 |
return finish(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
401 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
402 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
403 |
MemRegion ObjArrayAllocator::obj_memory_range(oop obj) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
404 |
if (_do_zero) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
405 |
return MemAllocator::obj_memory_range(obj); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
406 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
407 |
ArrayKlass* array_klass = ArrayKlass::cast(_klass); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
408 |
const size_t hs = arrayOopDesc::header_size(array_klass->element_type()); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
409 |
return MemRegion(((HeapWord*)obj) + hs, _word_size - hs); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
410 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
411 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
412 |
oop ObjArrayAllocator::initialize(HeapWord* mem) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
413 |
// Set array length before setting the _klass field because a |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
414 |
// non-NULL klass field indicates that the object is parsable by |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
415 |
// concurrent GC. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
416 |
assert(_length >= 0, "length should be non-negative"); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
417 |
if (_do_zero) { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
418 |
mem_clear(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
419 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
420 |
arrayOopDesc::set_length(mem, _length); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
421 |
return finish(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
422 |
} |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
423 |
|
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
424 |
oop ClassAllocator::initialize(HeapWord* mem) const { |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
425 |
// Set oop_size field before setting the _klass field because a |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
426 |
// non-NULL _klass field indicates that the object is parsable by |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
427 |
// concurrent GC. |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
428 |
assert(_word_size > 0, "oop_size must be positive."); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
429 |
mem_clear(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
430 |
java_lang_Class::set_oop_size(mem, (int)_word_size); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
431 |
return finish(mem); |
80abf702eed8
8205683: Refactor heap allocation to separate concerns
eosterlund
parents:
diff
changeset
|
432 |
} |