author | mgronlun |
Sat, 14 Sep 2019 14:40:09 +0200 | |
changeset 58132 | caa25ab47aca |
parent 54964 | ec7d6d8effc7 |
child 58157 | 9dca61a7df19 |
child 58863 | c16ac7a2eba4 |
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"); |
|
144 |
assert(t->identity() == NULL, "invariant"); |
|
145 |
if (!should_populate_cache()) { |
|
146 |
remove_free(t); |
|
147 |
assert(!_free.in_list(t), "invariant"); |
|
148 |
deallocate(t); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
template <typename T, template <typename> class RetrievalType, typename Callback> |
|
153 |
template <typename IteratorCallback, typename IteratorType> |
|
154 |
inline void JfrMemorySpace<T, RetrievalType, Callback> |
|
155 |
::iterate(IteratorCallback& callback, bool full, jfr_iter_direction direction) { |
|
156 |
IteratorType iterator(full ? _full : _free, direction); |
|
157 |
while (iterator.has_next()) { |
|
158 |
callback.process(iterator.next()); |
|
159 |
} |
|
160 |
} |
|
161 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
162 |
template <typename Mspace, typename Callback> |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
if (mspace != NULL) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
166 |
mspace->initialize(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
167 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
168 |
return mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
169 |
} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
170 |
|
50113 | 171 |
template <typename Mspace> |
172 |
inline size_t size_adjustment(size_t size, Mspace* mspace) { |
|
173 |
assert(mspace != NULL, "invariant"); |
|
174 |
static const size_t min_elem_size = mspace->min_elem_size(); |
|
175 |
if (size < min_elem_size) { |
|
176 |
size = min_elem_size; |
|
177 |
} |
|
178 |
return size; |
|
179 |
} |
|
180 |
||
181 |
template <typename Mspace> |
|
182 |
inline typename Mspace::Type* mspace_allocate(size_t size, Mspace* mspace) { |
|
183 |
return mspace->allocate(size_adjustment(size, mspace)); |
|
184 |
} |
|
185 |
||
186 |
template <typename Mspace> |
|
187 |
inline typename Mspace::Type* mspace_allocate_acquired(size_t size, Mspace* mspace, Thread* thread) { |
|
188 |
typename Mspace::Type* const t = mspace_allocate(size, mspace); |
|
189 |
if (t == NULL) return NULL; |
|
190 |
t->acquire(thread); |
|
191 |
return t; |
|
192 |
} |
|
193 |
||
194 |
template <typename Mspace> |
|
195 |
inline typename Mspace::Type* mspace_allocate_transient(size_t size, Mspace* mspace, Thread* thread) { |
|
196 |
typename Mspace::Type* const t = mspace_allocate_acquired(size, mspace, thread); |
|
197 |
if (t == NULL) return NULL; |
|
198 |
assert(t->acquired_by_self(), "invariant"); |
|
199 |
t->set_transient(); |
|
200 |
return t; |
|
201 |
} |
|
202 |
||
203 |
template <typename Mspace> |
|
204 |
inline typename Mspace::Type* mspace_allocate_transient_lease(size_t size, Mspace* mspace, Thread* thread) { |
|
205 |
typename Mspace::Type* const t = mspace_allocate_transient(size, mspace, thread); |
|
206 |
if (t == NULL) return NULL; |
|
207 |
assert(t->acquired_by_self(), "invariant"); |
|
208 |
assert(t->transient(), "invaiant"); |
|
209 |
t->set_lease(); |
|
210 |
return t; |
|
211 |
} |
|
212 |
||
213 |
template <typename Mspace> |
|
214 |
inline typename Mspace::Type* mspace_allocate_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
215 |
assert(mspace->is_locked(), "invariant"); |
|
216 |
typename Mspace::Type* const t = mspace_allocate_acquired(size, mspace, thread); |
|
217 |
if (t == NULL) return NULL; |
|
218 |
mspace->insert_full_head(t); |
|
219 |
return t; |
|
220 |
} |
|
221 |
||
222 |
template <typename Mspace> |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
223 |
class MspaceLock { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
224 |
private: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
225 |
Mspace* _mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
226 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
227 |
MspaceLock(Mspace* mspace) : _mspace(mspace) { _mspace->lock(); } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
228 |
~MspaceLock() { _mspace->unlock(); } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
229 |
}; |
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 |
template <typename Mspace> |
50113 | 232 |
inline typename Mspace::Type* mspace_allocate_transient_to_full(size_t size, Mspace* mspace, Thread* thread) { |
233 |
typename Mspace::Type* const t = mspace_allocate_transient(size, mspace, thread); |
|
234 |
if (t == NULL) return NULL; |
|
235 |
MspaceLock<Mspace> lock(mspace); |
|
236 |
mspace->insert_full_head(t); |
|
237 |
return t; |
|
238 |
} |
|
239 |
||
240 |
template <typename Mspace> |
|
241 |
inline typename Mspace::Type* mspace_allocate_transient_lease_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
242 |
typename Mspace::Type* const t = mspace_allocate_transient_lease(size, mspace, thread); |
|
243 |
if (t == NULL) return NULL; |
|
244 |
assert(t->acquired_by_self(), "invariant"); |
|
245 |
assert(t->transient(), "invaiant"); |
|
246 |
assert(t->lease(), "invariant"); |
|
247 |
MspaceLock<Mspace> lock(mspace); |
|
248 |
mspace->insert_full_head(t); |
|
249 |
return t; |
|
250 |
} |
|
251 |
||
252 |
template <typename Mspace> |
|
253 |
inline typename Mspace::Type* mspace_allocate_transient_lease_to_free(size_t size, Mspace* mspace, Thread* thread) { |
|
254 |
typename Mspace::Type* const t = mspace_allocate_transient_lease(size, mspace, thread); |
|
255 |
if (t == NULL) return NULL; |
|
256 |
assert(t->acquired_by_self(), "invariant"); |
|
257 |
assert(t->transient(), "invaiant"); |
|
258 |
assert(t->lease(), "invariant"); |
|
259 |
MspaceLock<Mspace> lock(mspace); |
|
260 |
mspace->insert_free_head(t); |
|
261 |
return t; |
|
262 |
} |
|
263 |
||
264 |
template <typename Mspace> |
|
265 |
inline typename Mspace::Type* mspace_get_free(size_t size, Mspace* mspace, Thread* thread) { |
|
266 |
return mspace->get(size, thread); |
|
267 |
} |
|
268 |
||
269 |
template <typename Mspace> |
|
270 |
inline typename Mspace::Type* mspace_get_free_with_retry(size_t size, Mspace* mspace, size_t retry_count, Thread* thread) { |
|
271 |
assert(size <= mspace->min_elem_size(), "invariant"); |
|
272 |
for (size_t i = 0; i < retry_count; ++i) { |
|
273 |
typename Mspace::Type* const t = mspace_get_free(size, mspace, thread); |
|
274 |
if (t != NULL) { |
|
275 |
return t; |
|
276 |
} |
|
277 |
} |
|
278 |
return NULL; |
|
279 |
} |
|
280 |
||
281 |
template <typename Mspace> |
|
282 |
inline typename Mspace::Type* mspace_get_free_with_detach(size_t size, Mspace* mspace, Thread* thread) { |
|
283 |
typename Mspace::Type* t = mspace_get_free(size, mspace, thread); |
|
284 |
if (t != NULL) { |
|
285 |
mspace->remove_free(t); |
|
286 |
} |
|
287 |
return t; |
|
288 |
} |
|
289 |
||
290 |
template <typename Mspace> |
|
291 |
inline typename Mspace::Type* mspace_get_free_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
292 |
assert(size <= mspace->min_elem_size(), "invariant"); |
|
293 |
assert(mspace->is_locked(), "invariant"); |
|
294 |
typename Mspace::Type* t = mspace_get_free(size, mspace, thread); |
|
295 |
if (t == NULL) { |
|
296 |
return NULL; |
|
297 |
} |
|
298 |
assert(t->acquired_by_self(), "invariant"); |
|
299 |
move_to_head(t, mspace->free(), mspace->full()); |
|
300 |
return t; |
|
301 |
} |
|
302 |
||
303 |
template <typename Mspace> |
|
304 |
inline typename Mspace::Type* mspace_get_to_full(size_t size, Mspace* mspace, Thread* thread) { |
|
305 |
size = size_adjustment(size, mspace); |
|
306 |
MspaceLock<Mspace> lock(mspace); |
|
307 |
if (size <= mspace->min_elem_size()) { |
|
308 |
typename Mspace::Type* const t = mspace_get_free_to_full(size, mspace, thread); |
|
309 |
if (t != NULL) { |
|
310 |
return t; |
|
311 |
} |
|
312 |
} |
|
313 |
return mspace_allocate_to_full(size, mspace, thread); |
|
314 |
} |
|
315 |
||
316 |
template <typename Mspace> |
|
317 |
inline typename Mspace::Type* mspace_get_free_lease_with_retry(size_t size, Mspace* mspace, size_t retry_count, Thread* thread) { |
|
318 |
typename Mspace::Type* t = mspace_get_free_with_retry(size, mspace, retry_count, thread); |
|
319 |
if (t != NULL) { |
|
320 |
t->set_lease(); |
|
321 |
} |
|
322 |
return t; |
|
323 |
} |
|
324 |
||
325 |
template <typename Mspace> |
|
326 |
inline typename Mspace::Type* mspace_get_lease(size_t size, Mspace* mspace, Thread* thread) { |
|
327 |
typename Mspace::Type* t; |
|
328 |
t = mspace_get_free_lease(size, mspace, thread); |
|
329 |
if (t != NULL) { |
|
330 |
assert(t->acquired_by_self(), "invariant"); |
|
331 |
assert(t->lease(), "invariant"); |
|
332 |
return t; |
|
333 |
} |
|
334 |
t = mspace_allocate_transient_to_full(size, mspace, thread); |
|
335 |
if (t != NULL) { |
|
336 |
t->set_lease(); |
|
337 |
} |
|
338 |
return t; |
|
339 |
} |
|
340 |
||
341 |
template <typename Mspace> |
|
342 |
inline void mspace_release_full(typename Mspace::Type* t, Mspace* mspace) { |
|
343 |
assert(t != NULL, "invariant"); |
|
344 |
assert(t->unflushed_size() == 0, "invariant"); |
|
345 |
assert(mspace != NULL, "invariant"); |
|
346 |
assert(mspace->is_locked(), "invariant"); |
|
347 |
mspace->release_full(t); |
|
348 |
} |
|
349 |
||
350 |
template <typename Mspace> |
|
351 |
inline void mspace_release_free(typename Mspace::Type* t, Mspace* mspace) { |
|
352 |
assert(t != NULL, "invariant"); |
|
353 |
assert(t->unflushed_size() == 0, "invariant"); |
|
354 |
assert(mspace != NULL, "invariant"); |
|
355 |
assert(mspace->is_locked(), "invariant"); |
|
356 |
mspace->release_free(t); |
|
357 |
} |
|
358 |
||
359 |
template <typename Mspace> |
|
360 |
inline void mspace_release_full_critical(typename Mspace::Type* t, Mspace* mspace) { |
|
361 |
MspaceLock<Mspace> lock(mspace); |
|
362 |
mspace_release_full(t, mspace); |
|
363 |
} |
|
364 |
||
365 |
template <typename Mspace> |
|
366 |
inline void mspace_release_free_critical(typename Mspace::Type* t, Mspace* mspace) { |
|
367 |
MspaceLock<Mspace> lock(mspace); |
|
368 |
mspace_release_free(t, mspace); |
|
369 |
} |
|
370 |
||
371 |
template <typename List> |
|
372 |
inline void move_to_head(typename List::Node* t, List& from, List& to) { |
|
373 |
assert(from.in_list(t), "invariant"); |
|
374 |
to.prepend(from.remove(t)); |
|
375 |
} |
|
376 |
||
377 |
template <typename Processor, typename Mspace, typename Iterator> |
|
378 |
inline void process_free_list_iterator_control(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
379 |
mspace->template iterate<Processor, Iterator>(processor, false, direction); |
|
380 |
} |
|
381 |
||
382 |
template <typename Processor, typename Mspace, typename Iterator> |
|
383 |
inline void process_full_list_iterator_control(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
384 |
mspace->template iterate<Processor, Iterator>(processor, true, direction); |
|
385 |
} |
|
386 |
||
387 |
template <typename Processor, typename Mspace> |
|
388 |
inline void process_full_list(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
389 |
assert(mspace != NULL, "invariant"); |
|
390 |
if (mspace->is_full_empty()) return; |
|
391 |
process_full_list_iterator_control<Processor, Mspace, typename Mspace::Iterator>(processor, mspace, direction); |
|
392 |
} |
|
393 |
||
394 |
template <typename Processor, typename Mspace> |
|
395 |
inline void process_free_list(Processor& processor, Mspace* mspace, jfr_iter_direction direction = forward) { |
|
396 |
assert(mspace != NULL, "invariant"); |
|
397 |
assert(mspace->has_free(), "invariant"); |
|
398 |
process_free_list_iterator_control<Processor, Mspace, typename Mspace::Iterator>(processor, mspace, direction); |
|
399 |
} |
|
400 |
||
401 |
template <typename Mspace> |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
402 |
class ReleaseOp : public StackObj { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
403 |
private: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
404 |
Mspace* _mspace; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
405 |
Thread* _thread; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
406 |
bool _release_full; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
407 |
public: |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
408 |
typedef typename Mspace::Type Type; |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
409 |
ReleaseOp(Mspace* mspace, Thread* thread, bool release_full = true) : |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
410 |
_mspace(mspace), _thread(thread), _release_full(release_full) {} |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
411 |
bool process(Type* t); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
412 |
size_t processed() const { return 0; } |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
54964
diff
changeset
|
413 |
}; |
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 |
template <typename Mspace> |
50113 | 416 |
inline bool ReleaseOp<Mspace>::process(typename Mspace::Type* t) { |
417 |
assert(t != NULL, "invariant"); |
|
54964 | 418 |
// assumes some means of exclusive access to t |
419 |
if (t->transient()) { |
|
420 |
if (_release_full) { |
|
421 |
mspace_release_full_critical(t, _mspace); |
|
422 |
} else { |
|
423 |
mspace_release_free_critical(t, _mspace); |
|
50113 | 424 |
} |
54964 | 425 |
return true; |
50113 | 426 |
} |
54964 | 427 |
t->reinitialize(); |
428 |
assert(t->empty(), "invariant"); |
|
429 |
assert(!t->retired(), "invariant"); |
|
430 |
t->release(); // publish |
|
50113 | 431 |
return true; |
432 |
} |
|
433 |
||
434 |
#ifdef ASSERT |
|
435 |
template <typename T> |
|
436 |
inline void assert_migration_state(const T* old, const T* new_buffer, size_t used, size_t requested) { |
|
437 |
assert(old != NULL, "invariant"); |
|
438 |
assert(new_buffer != NULL, "invariant"); |
|
439 |
assert(old->pos() >= old->start(), "invariant"); |
|
440 |
assert(old->pos() + used <= old->end(), "invariant"); |
|
441 |
assert(new_buffer->free_size() >= (used + requested), "invariant"); |
|
442 |
} |
|
443 |
#endif // ASSERT |
|
444 |
||
445 |
template <typename T> |
|
446 |
inline void migrate_outstanding_writes(const T* old, T* new_buffer, size_t used, size_t requested) { |
|
447 |
DEBUG_ONLY(assert_migration_state(old, new_buffer, used, requested);) |
|
448 |
if (used > 0) { |
|
449 |
memcpy(new_buffer->pos(), old->pos(), used); |
|
450 |
} |
|
451 |
} |
|
452 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
453 |
#endif // SHARE_JFR_RECORDER_STORAGE_JFRMEMORYSPACE_INLINE_HPP |