author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
25 |
#ifndef SHARE_JFR_RECORDER_STORAGE_JFRMEMORYSPACE_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
26 |
#define SHARE_JFR_RECORDER_STORAGE_JFRMEMORYSPACE_INLINE_HPP |
50113 | 27 |
|
28 |
#include "jfr/recorder/storage/jfrMemorySpace.hpp" |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
29 |
#include "runtime/os.hpp" |
50113 | 30 |
|
31 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
32 |
JfrMemorySpace<T, RetrievalType, Callback>:: |
|
33 |
JfrMemorySpace(size_t min_elem_size, size_t limit_size, size_t cache_count, Callback* callback) : |
|
34 |
_free(), |
|
35 |
_full(), |
|
36 |
_min_elem_size(min_elem_size), |
|
37 |
_limit_size(limit_size), |
|
38 |
_cache_count(cache_count), |
|
39 |
_callback(callback) {} |
|
40 |
||
41 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
42 |
JfrMemorySpace<T, RetrievalType, Callback>::~JfrMemorySpace() { |
|
43 |
Iterator full_iter(_full); |
|
44 |
while (full_iter.has_next()) { |
|
45 |
Type* t = full_iter.next(); |
|
46 |
_full.remove(t); |
|
47 |
deallocate(t); |
|
48 |
} |
|
49 |
Iterator free_iter(_free); |
|
50 |
while (free_iter.has_next()) { |
|
51 |
Type* t = free_iter.next(); |
|
52 |
_free.remove(t); |
|
53 |
deallocate(t); |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
58 |
bool JfrMemorySpace<T, RetrievalType, Callback>::initialize() { |
|
59 |
assert(_min_elem_size % os::vm_page_size() == 0, "invariant"); |
|
60 |
assert(_limit_size % os::vm_page_size() == 0, "invariant"); |
|
61 |
// pre-allocate cache elements |
|
62 |
for (size_t i = 0; i < _cache_count; ++i) { |
|
63 |
Type* const t = allocate(_min_elem_size); |
|
64 |
if (t == NULL) { |
|
65 |
return false; |
|
66 |
} |
|
67 |
insert_free_head(t); |
|
68 |
} |
|
69 |
assert(_free.count() == _cache_count, "invariant"); |
|
70 |
return true; |
|
71 |
} |
|
72 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
73 |
// allocations are even multiples of the mspace min size |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
74 |
static inline size_t align_allocation_size(size_t requested_size, size_t min_elem_size) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
75 |
assert((int)min_elem_size % os::vm_page_size() == 0, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
76 |
u8 alloc_size_bytes = min_elem_size; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
77 |
while (requested_size > alloc_size_bytes) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
78 |
alloc_size_bytes <<= 1; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
79 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
80 |
assert((int)alloc_size_bytes % os::vm_page_size() == 0, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
81 |
return (size_t)alloc_size_bytes; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
82 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
83 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
84 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
85 |
inline T* JfrMemorySpace<T, RetrievalType, Callback>::allocate(size_t size) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
86 |
const size_t aligned_size_bytes = align_allocation_size(size, _min_elem_size); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
87 |
void* const allocation = JfrCHeapObj::new_array<u1>(aligned_size_bytes + sizeof(T)); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
88 |
if (allocation == NULL) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
89 |
return NULL; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
90 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
91 |
T* const t = new (allocation) T; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
92 |
assert(t != NULL, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
93 |
if (!t->initialize(sizeof(T), aligned_size_bytes)) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
94 |
JfrCHeapObj::free(t, aligned_size_bytes + sizeof(T)); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
95 |
return NULL; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
96 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
97 |
return t; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
98 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
99 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
100 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
101 |
inline void JfrMemorySpace<T, RetrievalType, Callback>::deallocate(T* t) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
102 |
assert(t != NULL, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
103 |
assert(!_free.in_list(t), "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
104 |
assert(!_full.in_list(t), "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
105 |
assert(t != NULL, "invariant"); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
106 |
JfrCHeapObj::free(t, t->total_size()); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
107 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
108 |
|
50113 | 109 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
110 |
inline void JfrMemorySpace<T, RetrievalType, Callback>::release_full(T* t) { |
|
111 |
assert(is_locked(), "invariant"); |
|
112 |
assert(t != NULL, "invariant"); |
|
113 |
assert(_full.in_list(t), "invariant"); |
|
114 |
remove_full(t); |
|
115 |
assert(!_full.in_list(t), "invariant"); |
|
116 |
if (t->transient()) { |
|
117 |
deallocate(t); |
|
118 |
return; |
|
119 |
} |
|
120 |
assert(t->empty(), "invariant"); |
|
121 |
assert(!t->retired(), "invariant"); |
|
122 |
assert(t->identity() == NULL, "invariant"); |
|
123 |
if (should_populate_cache()) { |
|
124 |
assert(!_free.in_list(t), "invariant"); |
|
125 |
insert_free_head(t); |
|
126 |
} else { |
|
127 |
deallocate(t); |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
132 |
inline void JfrMemorySpace<T, RetrievalType, Callback>::release_free(T* t) { |
|
133 |
assert(is_locked(), "invariant"); |
|
134 |
assert(t != NULL, "invariant"); |
|
135 |
assert(_free.in_list(t), "invariant"); |
|
136 |
if (t->transient()) { |
|
137 |
remove_free(t); |
|
138 |
assert(!_free.in_list(t), "invariant"); |
|
139 |
deallocate(t); |
|
140 |
return; |
|
141 |
} |
|
142 |
assert(t->empty(), "invariant"); |
|
143 |
assert(!t->retired(), "invariant"); |
|
58863 | 144 |
assert(!t->excluded(), "invariant"); |
50113 | 145 |
assert(t->identity() == NULL, "invariant"); |
146 |
if (!should_populate_cache()) { |
|
147 |
remove_free(t); |
|
148 |
assert(!_free.in_list(t), "invariant"); |
|
149 |
deallocate(t); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
154 |
template <typename IteratorCallback, typename IteratorType> |
|
155 |
inline void JfrMemorySpace<T, RetrievalType, Callback> |
|
156 |
::iterate(IteratorCallback& callback, bool full, jfr_iter_direction direction) { |
|
157 |
IteratorType iterator(full ? _full : _free, direction); |
|
158 |
while (iterator.has_next()) { |
|
159 |
callback.process(iterator.next()); |
|
160 |
} |
|
161 |
} |
|
162 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
163 |
template <typename Mspace, typename Callback> |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
164 |
static inline Mspace* create_mspace(size_t buffer_size, size_t limit, size_t cache_count, Callback* cb) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
165 |
Mspace* const mspace = new Mspace(buffer_size, limit, cache_count, cb); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
166 |
if (mspace != NULL) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
167 |
mspace->initialize(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
168 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
169 |
return mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
170 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
171 |
|
50113 | 172 |
template <typename Mspace> |
173 |
inline size_t size_adjustment(size_t size, Mspace* mspace) { |
|
174 |
assert(mspace != NULL, "invariant"); |
|
175 |
static const size_t min_elem_size = mspace->min_elem_size(); |
|
176 |
if (size < min_elem_size) { |
|
177 |
size = min_elem_size; |
|
178 |
} |
|
179 |
return size; |
|
180 |
} |
|
181 |
||
182 |
template <typename Mspace> |
|
183 |
inline typename Mspace::Type* mspace_allocate(size_t size, Mspace* mspace) { |
|
184 |
return mspace->allocate(size_adjustment(size, mspace)); |
|
185 |
} |
|
186 |
||
187 |
template <typename Mspace> |
|
188 |
inline typename Mspace::Type* mspace_allocate_acquired(size_t size, Mspace* mspace, Thread* thread) { |
|
189 |
typename Mspace::Type* const t = mspace_allocate(size, mspace); |
|
190 |
if (t == NULL) return NULL; |
|
191 |
t->acquire(thread); |
|
192 |
return t; |
|
193 |
} |
|
194 |
||
195 |
template <typename Mspace> |
|
196 |
inline typename Mspace::Type* mspace_allocate_transient(size_t size, Mspace* mspace, Thread* thread) { |
|
197 |
typename Mspace::Type* const t = mspace_allocate_acquired(size, mspace, thread); |
|
198 |
if (t == NULL) return NULL; |
|
199 |
assert(t->acquired_by_self(), "invariant"); |
|
200 |
t->set_transient(); |
|
201 |
return t; |
|
202 |
} |
|
203 |
||
204 |
template <typename Mspace> |
|
205 |
inline typename Mspace::Type* mspace_allocate_transient_lease(size_t size, Mspace* mspace, Thread* thread) { |
|
206 |
typename Mspace::Type* const t = mspace_allocate_transient(size, mspace, thread); |
|
207 |
if (t == NULL) return NULL; |
|
208 |
assert(t->acquired_by_self(), "invariant"); |
|
209 |
assert(t->transient(), "invaiant"); |
|
210 |
t->set_lease(); |
|
211 |
return t; |
|
212 |
} |
|
213 |
||
214 |
template <typename Mspace> |
|
215 |
inline typename Mspace::Type* mspace_allocate_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
216 |
assert(mspace->is_locked(), "invariant"); |
|
217 |
typename Mspace::Type* const t = mspace_allocate_acquired(size, mspace, thread); |
|
218 |
if (t == NULL) return NULL; |
|
219 |
mspace->insert_full_head(t); |
|
220 |
return t; |
|
221 |
} |
|
222 |
||
223 |
template <typename Mspace> |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
224 |
class MspaceLock { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
225 |
private: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
226 |
Mspace* _mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
227 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
228 |
MspaceLock(Mspace* mspace) : _mspace(mspace) { _mspace->lock(); } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
229 |
~MspaceLock() { _mspace->unlock(); } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
230 |
}; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
231 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
232 |
template <typename Mspace> |
50113 | 233 |
inline typename Mspace::Type* mspace_allocate_transient_to_full(size_t size, Mspace* mspace, Thread* thread) { |
234 |
typename Mspace::Type* const t = mspace_allocate_transient(size, mspace, thread); |
|
235 |
if (t == NULL) return NULL; |
|
236 |
MspaceLock<Mspace> lock(mspace); |
|
237 |
mspace->insert_full_head(t); |
|
238 |
return t; |
|
239 |
} |
|
240 |
||
241 |
template <typename Mspace> |
|
242 |
inline typename Mspace::Type* mspace_allocate_transient_lease_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
243 |
typename Mspace::Type* const t = mspace_allocate_transient_lease(size, mspace, thread); |
|
244 |
if (t == NULL) return NULL; |
|
245 |
assert(t->acquired_by_self(), "invariant"); |
|
246 |
assert(t->transient(), "invaiant"); |
|
247 |
assert(t->lease(), "invariant"); |
|
248 |
MspaceLock<Mspace> lock(mspace); |
|
249 |
mspace->insert_full_head(t); |
|
250 |
return t; |
|
251 |
} |
|
252 |
||
253 |
template <typename Mspace> |
|
254 |
inline typename Mspace::Type* mspace_allocate_transient_lease_to_free(size_t size, Mspace* mspace, Thread* thread) { |
|
255 |
typename Mspace::Type* const t = mspace_allocate_transient_lease(size, mspace, thread); |
|
256 |
if (t == NULL) return NULL; |
|
257 |
assert(t->acquired_by_self(), "invariant"); |
|
258 |
assert(t->transient(), "invaiant"); |
|
259 |
assert(t->lease(), "invariant"); |
|
260 |
MspaceLock<Mspace> lock(mspace); |
|
261 |
mspace->insert_free_head(t); |
|
262 |
return t; |
|
263 |
} |
|
264 |
||
265 |
template <typename Mspace> |
|
266 |
inline typename Mspace::Type* mspace_get_free(size_t size, Mspace* mspace, Thread* thread) { |
|
267 |
return mspace->get(size, thread); |
|
268 |
} |
|
269 |
||
270 |
template <typename Mspace> |
|
271 |
inline typename Mspace::Type* mspace_get_free_with_retry(size_t size, Mspace* mspace, size_t retry_count, Thread* thread) { |
|
272 |
assert(size <= mspace->min_elem_size(), "invariant"); |
|
273 |
for (size_t i = 0; i < retry_count; ++i) { |
|
274 |
typename Mspace::Type* const t = mspace_get_free(size, mspace, thread); |
|
275 |
if (t != NULL) { |
|
276 |
return t; |
|
277 |
} |
|
278 |
} |
|
279 |
return NULL; |
|
280 |
} |
|
281 |
||
282 |
template <typename Mspace> |
|
283 |
inline typename Mspace::Type* mspace_get_free_with_detach(size_t size, Mspace* mspace, Thread* thread) { |
|
284 |
typename Mspace::Type* t = mspace_get_free(size, mspace, thread); |
|
285 |
if (t != NULL) { |
|
286 |
mspace->remove_free(t); |
|
287 |
} |
|
288 |
return t; |
|
289 |
} |
|
290 |
||
291 |
template <typename Mspace> |
|
292 |
inline typename Mspace::Type* mspace_get_free_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
293 |
assert(size <= mspace->min_elem_size(), "invariant"); |
|
294 |
assert(mspace->is_locked(), "invariant"); |
|
295 |
typename Mspace::Type* t = mspace_get_free(size, mspace, thread); |
|
296 |
if (t == NULL) { |
|
297 |
return NULL; |
|
298 |
} |
|
299 |
assert(t->acquired_by_self(), "invariant"); |
|
300 |
move_to_head(t, mspace->free(), mspace->full()); |
|
301 |
return t; |
|
302 |
} |
|
303 |
||
304 |
template <typename Mspace> |
|
305 |
inline typename Mspace::Type* mspace_get_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
306 |
size = size_adjustment(size, mspace); |
|
307 |
MspaceLock<Mspace> lock(mspace); |
|
308 |
if (size <= mspace->min_elem_size()) { |
|
309 |
typename Mspace::Type* const t = mspace_get_free_to_full(size, mspace, thread); |
|
310 |
if (t != NULL) { |
|
311 |
return t; |
|
312 |
} |
|
313 |
} |
|
314 |
return mspace_allocate_to_full(size, mspace, thread); |
|
315 |
} |
|
316 |
||
317 |
template <typename Mspace> |
|
318 |
inline typename Mspace::Type* mspace_get_free_lease_with_retry(size_t size, Mspace* mspace, size_t retry_count, Thread* thread) { |
|
319 |
typename Mspace::Type* t = mspace_get_free_with_retry(size, mspace, retry_count, thread); |
|
320 |
if (t != NULL) { |
|
321 |
t->set_lease(); |
|
322 |
} |
|
323 |
return t; |
|
324 |
} |
|
325 |
||
326 |
template <typename Mspace> |
|
327 |
inline typename Mspace::Type* mspace_get_lease(size_t size, Mspace* mspace, Thread* thread) { |
|
328 |
typename Mspace::Type* t; |
|
329 |
t = mspace_get_free_lease(size, mspace, thread); |
|
330 |
if (t != NULL) { |
|
331 |
assert(t->acquired_by_self(), "invariant"); |
|
332 |
assert(t->lease(), "invariant"); |
|
333 |
return t; |
|
334 |
} |
|
335 |
t = mspace_allocate_transient_to_full(size, mspace, thread); |
|
336 |
if (t != NULL) { |
|
337 |
t->set_lease(); |
|
338 |
} |
|
339 |
return t; |
|
340 |
} |
|
341 |
||
342 |
template <typename Mspace> |
|
343 |
inline void mspace_release_full(typename Mspace::Type* t, Mspace* mspace) { |
|
344 |
assert(t != NULL, "invariant"); |
|
345 |
assert(t->unflushed_size() == 0, "invariant"); |
|
346 |
assert(mspace != NULL, "invariant"); |
|
347 |
assert(mspace->is_locked(), "invariant"); |
|
348 |
mspace->release_full(t); |
|
349 |
} |
|
350 |
||
351 |
template <typename Mspace> |
|
352 |
inline void mspace_release_free(typename Mspace::Type* t, Mspace* mspace) { |
|
353 |
assert(t != NULL, "invariant"); |
|
354 |
assert(t->unflushed_size() == 0, "invariant"); |
|
355 |
assert(mspace != NULL, "invariant"); |
|
356 |
assert(mspace->is_locked(), "invariant"); |
|
357 |
mspace->release_free(t); |
|
358 |
} |
|
359 |
||
360 |
template <typename Mspace> |
|
361 |
inline void mspace_release_full_critical(typename Mspace::Type* t, Mspace* mspace) { |
|
362 |
MspaceLock<Mspace> lock(mspace); |
|
363 |
mspace_release_full(t, mspace); |
|
364 |
} |
|
365 |
||
366 |
template <typename Mspace> |
|
367 |
inline void mspace_release_free_critical(typename Mspace::Type* t, Mspace* mspace) { |
|
368 |
MspaceLock<Mspace> lock(mspace); |
|
369 |
mspace_release_free(t, mspace); |
|
370 |
} |
|
371 |
||
372 |
template <typename List> |
|
373 |
inline void move_to_head(typename List::Node* t, List& from, List& to) { |
|
374 |
assert(from.in_list(t), "invariant"); |
|
375 |
to.prepend(from.remove(t)); |
|
376 |
} |
|
377 |
||
378 |
template <typename Processor, typename Mspace, typename Iterator> |
|
379 |
inline void process_free_list_iterator_control(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
380 |
mspace->template iterate<Processor, Iterator>(processor, false, direction); |
|
381 |
} |
|
382 |
||
383 |
template <typename Processor, typename Mspace, typename Iterator> |
|
384 |
inline void process_full_list_iterator_control(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
385 |
mspace->template iterate<Processor, Iterator>(processor, true, direction); |
|
386 |
} |
|
387 |
||
388 |
template <typename Processor, typename Mspace> |
|
389 |
inline void process_full_list(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
390 |
assert(mspace != NULL, "invariant"); |
|
391 |
if (mspace->is_full_empty()) return; |
|
392 |
process_full_list_iterator_control<Processor, Mspace, typename Mspace::Iterator>(processor, mspace, direction); |
|
393 |
} |
|
394 |
||
395 |
template <typename Processor, typename Mspace> |
|
396 |
inline void process_free_list(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
397 |
assert(mspace != NULL, "invariant"); |
|
398 |
assert(mspace->has_free(), "invariant"); |
|
399 |
process_free_list_iterator_control<Processor, Mspace, typename Mspace::Iterator>(processor, mspace, direction); |
|
400 |
} |
|
401 |
||
402 |
template <typename Mspace> |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
403 |
class ReleaseOp : public StackObj { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
404 |
private: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
405 |
Mspace* _mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
406 |
Thread* _thread; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
407 |
bool _release_full; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
408 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
409 |
typedef typename Mspace::Type Type; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
410 |
ReleaseOp(Mspace* mspace, Thread* thread, bool release_full = true) : |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
411 |
_mspace(mspace), _thread(thread), _release_full(release_full) {} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
412 |
bool process(Type* t); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
413 |
size_t processed() const { return 0; } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
414 |
}; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
415 |
|
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
416 |
template <typename Mspace> |
50113 | 417 |
inline bool ReleaseOp<Mspace>::process(typename Mspace::Type* t) { |
418 |
assert(t != NULL, "invariant"); |
|
54964 | 419 |
// assumes some means of exclusive access to t |
420 |
if (t->transient()) { |
|
421 |
if (_release_full) { |
|
422 |
mspace_release_full_critical(t, _mspace); |
|
423 |
} else { |
|
424 |
mspace_release_free_critical(t, _mspace); |
|
50113 | 425 |
} |
54964 | 426 |
return true; |
50113 | 427 |
} |
54964 | 428 |
t->reinitialize(); |
429 |
assert(t->empty(), "invariant"); |
|
430 |
assert(!t->retired(), "invariant"); |
|
431 |
t->release(); // publish |
|
50113 | 432 |
return true; |
433 |
} |
|
434 |
||
435 |
#ifdef ASSERT |
|
436 |
template <typename T> |
|
437 |
inline void assert_migration_state(const T* old, const T* new_buffer, size_t used, size_t requested) { |
|
438 |
assert(old != NULL, "invariant"); |
|
439 |
assert(new_buffer != NULL, "invariant"); |
|
440 |
assert(old->pos() >= old->start(), "invariant"); |
|
441 |
assert(old->pos() + used <= old->end(), "invariant"); |
|
442 |
assert(new_buffer->free_size() >= (used + requested), "invariant"); |
|
443 |
} |
|
444 |
#endif // ASSERT |
|
445 |
||
446 |
template <typename T> |
|
447 |
inline void migrate_outstanding_writes(const T* old, T* new_buffer, size_t used, size_t requested) { |
|
448 |
DEBUG_ONLY(assert_migration_state(old, new_buffer, used, requested);) |
|
449 |
if (used > 0) { |
|
450 |
memcpy(new_buffer->pos(), old->pos(), used); |
|
451 |
} |
|
452 |
} |
|
453 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
454 |
#endif // SHARE_JFR_RECORDER_STORAGE_JFRMEMORYSPACE_INLINE_HPP |