author | mgronlun |
Tue, 03 Sep 2019 11:48:31 +0200 | |
branch | JEP-349-branch |
changeset 57987 | 23e3cd901cb6 |
parent 57983 | a57907813a83 |
child 58049 | 10ecdb5d3574 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
57360 | 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 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/javaClasses.inline.hpp" |
|
27 |
#include "jfr/recorder/jfrRecorder.hpp" |
|
28 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
|
29 |
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
|
30 |
#include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
|
31 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp" |
|
32 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
33 |
#include "jfr/recorder/storage/jfrMemorySpace.inline.hpp" |
|
34 |
#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp" |
|
35 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
36 |
#include "jfr/utilities/jfrBigEndian.hpp" |
|
57360 | 37 |
#include "jfr/utilities/jfrIterator.hpp" |
38 |
#include "jfr/utilities/jfrThreadIterator.hpp" |
|
50113 | 39 |
#include "jfr/utilities/jfrTypes.hpp" |
57360 | 40 |
#include "jfr/writers/jfrJavaEventWriter.hpp" |
50113 | 41 |
#include "logging/log.hpp" |
42 |
#include "memory/resourceArea.hpp" |
|
57360 | 43 |
#include "runtime/handles.inline.hpp" |
50113 | 44 |
#include "runtime/mutexLocker.hpp" |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50117
diff
changeset
|
45 |
#include "runtime/orderAccess.hpp" |
50117
fb66b2959eaf
8203251: Non-PCH build failed after JDK-8199712 (Flight Recorder)
shade
parents:
50113
diff
changeset
|
46 |
#include "runtime/os.inline.hpp" |
50113 | 47 |
#include "runtime/safepoint.hpp" |
48 |
||
49 |
typedef JfrCheckpointManager::Buffer* BufferPtr; |
|
50 |
||
51 |
static JfrCheckpointManager* _instance = NULL; |
|
52 |
||
53 |
JfrCheckpointManager& JfrCheckpointManager::instance() { |
|
54 |
return *_instance; |
|
55 |
} |
|
56 |
||
57 |
JfrCheckpointManager* JfrCheckpointManager::create(JfrChunkWriter& cw) { |
|
58 |
assert(_instance == NULL, "invariant"); |
|
59 |
_instance = new JfrCheckpointManager(cw); |
|
60 |
return _instance; |
|
61 |
} |
|
62 |
||
63 |
void JfrCheckpointManager::destroy() { |
|
64 |
assert(_instance != NULL, "invariant"); |
|
65 |
delete _instance; |
|
66 |
_instance = NULL; |
|
67 |
} |
|
68 |
||
69 |
JfrCheckpointManager::JfrCheckpointManager(JfrChunkWriter& cw) : |
|
70 |
_free_list_mspace(NULL), |
|
71 |
_epoch_transition_mspace(NULL), |
|
72 |
_lock(NULL), |
|
73 |
_service_thread(NULL), |
|
74 |
_chunkwriter(cw), |
|
75 |
_checkpoint_epoch_state(JfrTraceIdEpoch::epoch()) {} |
|
76 |
||
77 |
JfrCheckpointManager::~JfrCheckpointManager() { |
|
78 |
if (_free_list_mspace != NULL) { |
|
79 |
delete _free_list_mspace; |
|
80 |
} |
|
81 |
if (_epoch_transition_mspace != NULL) { |
|
82 |
delete _epoch_transition_mspace; |
|
83 |
} |
|
84 |
if (_lock != NULL) { |
|
85 |
delete _lock; |
|
86 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
87 |
JfrTypeManager::clear(); |
50113 | 88 |
} |
89 |
||
90 |
static const size_t unlimited_mspace_size = 0; |
|
91 |
static const size_t checkpoint_buffer_cache_count = 2; |
|
92 |
static const size_t checkpoint_buffer_size = 512 * K; |
|
93 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
94 |
static JfrCheckpointMspace* allocate_mspace(size_t size, size_t limit, size_t cache_count, JfrCheckpointManager* mgr) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
95 |
return create_mspace<JfrCheckpointMspace, JfrCheckpointManager>(size, limit, cache_count, mgr); |
50113 | 96 |
} |
97 |
||
98 |
bool JfrCheckpointManager::initialize() { |
|
99 |
assert(_free_list_mspace == NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
100 |
_free_list_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this); |
50113 | 101 |
if (_free_list_mspace == NULL) { |
102 |
return false; |
|
103 |
} |
|
104 |
assert(_epoch_transition_mspace == NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
105 |
_epoch_transition_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this); |
50113 | 106 |
if (_epoch_transition_mspace == NULL) { |
107 |
return false; |
|
108 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
109 |
assert(_lock == NULL, "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
110 |
_lock = new Mutex(Monitor::leaf - 1, "Checkpoint mutex", Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
111 |
if (_lock == NULL) { |
50113 | 112 |
return false; |
113 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
114 |
return JfrTypeManager::initialize(); |
50113 | 115 |
} |
116 |
||
117 |
void JfrCheckpointManager::register_service_thread(const Thread* thread) { |
|
118 |
_service_thread = thread; |
|
119 |
} |
|
120 |
||
121 |
void JfrCheckpointManager::register_full(BufferPtr t, Thread* thread) { |
|
122 |
// nothing here at the moment |
|
57360 | 123 |
assert(t != NULL, "invariant"); |
124 |
assert(t->acquired_by(thread), "invariant"); |
|
50113 | 125 |
assert(t->retired(), "invariant"); |
126 |
} |
|
127 |
||
128 |
void JfrCheckpointManager::lock() { |
|
129 |
assert(!_lock->owned_by_self(), "invariant"); |
|
130 |
_lock->lock_without_safepoint_check(); |
|
131 |
} |
|
132 |
||
133 |
void JfrCheckpointManager::unlock() { |
|
134 |
_lock->unlock(); |
|
135 |
} |
|
136 |
||
137 |
#ifdef ASSERT |
|
138 |
bool JfrCheckpointManager::is_locked() const { |
|
139 |
return _lock->owned_by_self(); |
|
140 |
} |
|
141 |
||
142 |
static void assert_free_lease(const BufferPtr buffer) { |
|
143 |
assert(buffer != NULL, "invariant"); |
|
144 |
assert(buffer->acquired_by_self(), "invariant"); |
|
145 |
assert(buffer->lease(), "invariant"); |
|
146 |
} |
|
147 |
||
148 |
static void assert_release(const BufferPtr buffer) { |
|
149 |
assert(buffer != NULL, "invariant"); |
|
150 |
assert(buffer->lease(), "invariant"); |
|
151 |
assert(buffer->acquired_by_self(), "invariant"); |
|
152 |
} |
|
153 |
#endif // ASSERT |
|
154 |
||
155 |
static BufferPtr lease_free(size_t size, JfrCheckpointMspace* mspace, size_t retry_count, Thread* thread) { |
|
156 |
static const size_t max_elem_size = mspace->min_elem_size(); // min is max |
|
157 |
BufferPtr buffer; |
|
158 |
if (size <= max_elem_size) { |
|
159 |
BufferPtr buffer = mspace_get_free_lease_with_retry(size, mspace, retry_count, thread); |
|
160 |
if (buffer != NULL) { |
|
161 |
DEBUG_ONLY(assert_free_lease(buffer);) |
|
162 |
return buffer; |
|
163 |
} |
|
164 |
} |
|
165 |
buffer = mspace_allocate_transient_lease_to_free(size, mspace, thread); |
|
166 |
DEBUG_ONLY(assert_free_lease(buffer);) |
|
167 |
return buffer; |
|
168 |
} |
|
169 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
170 |
bool JfrCheckpointManager::use_epoch_transition_mspace(const Thread* thread) const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
171 |
return _service_thread != thread && OrderAccess::load_acquire(&_checkpoint_epoch_state) != JfrTraceIdEpoch::epoch(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
172 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
173 |
|
50113 | 174 |
static const size_t lease_retry = 10; |
175 |
||
176 |
BufferPtr JfrCheckpointManager::lease_buffer(Thread* thread, size_t size /* 0 */) { |
|
177 |
JfrCheckpointManager& manager = instance(); |
|
178 |
if (manager.use_epoch_transition_mspace(thread)) { |
|
179 |
return lease_free(size, manager._epoch_transition_mspace, lease_retry, thread); |
|
180 |
} |
|
181 |
return lease_free(size, manager._free_list_mspace, lease_retry, thread); |
|
182 |
} |
|
183 |
||
57882 | 184 |
JfrCheckpointMspace* JfrCheckpointManager::lookup(BufferPtr old) const { |
185 |
assert(old != NULL, "invariant"); |
|
186 |
return _free_list_mspace->in_free_list(old) ? _free_list_mspace : _epoch_transition_mspace; |
|
187 |
} |
|
188 |
||
189 |
BufferPtr JfrCheckpointManager::lease_buffer(BufferPtr old, Thread* thread, size_t size /* 0 */) { |
|
190 |
assert(old != NULL, "invariant"); |
|
191 |
JfrCheckpointMspace* mspace = instance().lookup(old); |
|
192 |
assert(mspace != NULL, "invariant"); |
|
193 |
return lease_free(size, mspace, lease_retry, thread); |
|
194 |
} |
|
195 |
||
50113 | 196 |
/* |
57987 | 197 |
* If the buffer was a lease, release back. |
198 |
* |
|
199 |
* The buffer is effectively invalidated for the thread post-return, |
|
200 |
* and the caller should take means to ensure that it is not referenced. |
|
201 |
*/ |
|
50113 | 202 |
static void release(BufferPtr const buffer, Thread* thread) { |
203 |
DEBUG_ONLY(assert_release(buffer);) |
|
204 |
buffer->clear_lease(); |
|
205 |
buffer->release(); |
|
206 |
} |
|
207 |
||
208 |
BufferPtr JfrCheckpointManager::flush(BufferPtr old, size_t used, size_t requested, Thread* thread) { |
|
209 |
assert(old != NULL, "invariant"); |
|
210 |
assert(old->lease(), "invariant"); |
|
211 |
if (0 == requested) { |
|
212 |
// indicates a lease is being returned |
|
213 |
release(old, thread); |
|
214 |
return NULL; |
|
215 |
} |
|
216 |
// migration of in-flight information |
|
57882 | 217 |
BufferPtr const new_buffer = lease_buffer(old, thread, used + requested); |
50113 | 218 |
if (new_buffer != NULL) { |
219 |
migrate_outstanding_writes(old, new_buffer, used, requested); |
|
220 |
} |
|
221 |
release(old, thread); |
|
222 |
return new_buffer; // might be NULL |
|
223 |
} |
|
224 |
||
225 |
// offsets into the JfrCheckpointEntry |
|
226 |
static const juint starttime_offset = sizeof(jlong); |
|
227 |
static const juint duration_offset = starttime_offset + sizeof(jlong); |
|
57886
87f8a814310d
rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents:
57882
diff
changeset
|
228 |
static const juint checkpoint_type_offset = duration_offset + sizeof(jlong); |
87f8a814310d
rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents:
57882
diff
changeset
|
229 |
static const juint types_offset = checkpoint_type_offset + sizeof(juint); |
50113 | 230 |
static const juint payload_offset = types_offset + sizeof(juint); |
231 |
||
232 |
template <typename Return> |
|
233 |
static Return read_data(const u1* data) { |
|
234 |
return JfrBigEndian::read<Return>(data); |
|
235 |
} |
|
236 |
||
237 |
static jlong total_size(const u1* data) { |
|
238 |
return read_data<jlong>(data); |
|
239 |
} |
|
240 |
||
241 |
static jlong starttime(const u1* data) { |
|
242 |
return read_data<jlong>(data + starttime_offset); |
|
243 |
} |
|
244 |
||
245 |
static jlong duration(const u1* data) { |
|
246 |
return read_data<jlong>(data + duration_offset); |
|
247 |
} |
|
248 |
||
57886
87f8a814310d
rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents:
57882
diff
changeset
|
249 |
static u1 checkpoint_type(const u1* data) { |
87f8a814310d
rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents:
57882
diff
changeset
|
250 |
return read_data<u1>(data + checkpoint_type_offset); |
57882 | 251 |
} |
252 |
||
50113 | 253 |
static juint number_of_types(const u1* data) { |
254 |
return read_data<juint>(data + types_offset); |
|
255 |
} |
|
256 |
||
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
257 |
static void write_checkpoint_header(JfrChunkWriter& cw, int64_t delta_to_last_checkpoint, const u1* data) { |
50113 | 258 |
cw.reserve(sizeof(u4)); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
259 |
cw.write<u8>(EVENT_CHECKPOINT); |
57882 | 260 |
cw.write(starttime(data)); |
261 |
cw.write(duration(data)); |
|
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
262 |
cw.write(delta_to_last_checkpoint); |
57886
87f8a814310d
rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents:
57882
diff
changeset
|
263 |
cw.write(checkpoint_type(data)); |
57882 | 264 |
cw.write(number_of_types(data)); |
50113 | 265 |
} |
266 |
||
267 |
static void write_checkpoint_content(JfrChunkWriter& cw, const u1* data, size_t size) { |
|
268 |
assert(data != NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
269 |
cw.write_unbuffered(data + payload_offset, size - sizeof(JfrCheckpointEntry)); |
50113 | 270 |
} |
271 |
||
272 |
static size_t write_checkpoint_event(JfrChunkWriter& cw, const u1* data) { |
|
273 |
assert(data != NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
274 |
const int64_t event_begin = cw.current_offset(); |
57360 | 275 |
const int64_t last_checkpoint_event = cw.last_checkpoint_offset(); |
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
276 |
const int64_t delta_to_last_checkpoint = last_checkpoint_event == 0 ? 0 : last_checkpoint_event - event_begin; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
277 |
const int64_t checkpoint_size = total_size(data); |
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
278 |
write_checkpoint_header(cw, delta_to_last_checkpoint, data); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
279 |
write_checkpoint_content(cw, data, checkpoint_size); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
280 |
const int64_t event_size = cw.current_offset() - event_begin; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
281 |
cw.write_padded_at_offset<u4>(event_size, event_begin); |
57360 | 282 |
cw.set_last_checkpoint_offset(event_begin); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
283 |
return (size_t)checkpoint_size; |
50113 | 284 |
} |
285 |
||
286 |
static size_t write_checkpoints(JfrChunkWriter& cw, const u1* data, size_t size) { |
|
287 |
assert(cw.is_valid(), "invariant"); |
|
288 |
assert(data != NULL, "invariant"); |
|
289 |
assert(size > 0, "invariant"); |
|
290 |
const u1* const limit = data + size; |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
291 |
const u1* next = data; |
50113 | 292 |
size_t processed = 0; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
293 |
while (next < limit) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
294 |
const size_t checkpoint_size = write_checkpoint_event(cw, next); |
50113 | 295 |
processed += checkpoint_size; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
296 |
next += checkpoint_size; |
50113 | 297 |
} |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
298 |
assert(next == limit, "invariant"); |
50113 | 299 |
return processed; |
300 |
} |
|
301 |
||
302 |
template <typename T> |
|
303 |
class CheckpointWriteOp { |
|
304 |
private: |
|
305 |
JfrChunkWriter& _writer; |
|
306 |
size_t _processed; |
|
307 |
public: |
|
308 |
typedef T Type; |
|
309 |
CheckpointWriteOp(JfrChunkWriter& writer) : _writer(writer), _processed(0) {} |
|
310 |
bool write(Type* t, const u1* data, size_t size) { |
|
311 |
_processed += write_checkpoints(_writer, data, size); |
|
312 |
return true; |
|
313 |
} |
|
314 |
size_t processed() const { return _processed; } |
|
315 |
}; |
|
316 |
||
317 |
typedef CheckpointWriteOp<JfrCheckpointMspace::Type> WriteOperation; |
|
318 |
typedef ReleaseOp<JfrCheckpointMspace> CheckpointReleaseOperation; |
|
319 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
320 |
template <template <typename> class WriterHost, template <typename, typename> class CompositeOperation> |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
321 |
static size_t write_mspace(JfrCheckpointMspace* mspace, JfrChunkWriter& chunkwriter) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
322 |
assert(mspace != NULL, "invariant"); |
50113 | 323 |
WriteOperation wo(chunkwriter); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
324 |
WriterHost<WriteOperation> wh(wo); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
325 |
CheckpointReleaseOperation cro(mspace, Thread::current(), false); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
326 |
CompositeOperation<WriterHost<WriteOperation>, CheckpointReleaseOperation> co(&wh, &cro); |
50113 | 327 |
assert(mspace->is_full_empty(), "invariant"); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
328 |
process_free_list(co, mspace); |
50113 | 329 |
return wo.processed(); |
330 |
} |
|
331 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
332 |
void JfrCheckpointManager::synchronize_epoch() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
333 |
assert(_checkpoint_epoch_state != JfrTraceIdEpoch::epoch(), "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
334 |
OrderAccess::storestore(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
335 |
_checkpoint_epoch_state = JfrTraceIdEpoch::epoch(); |
57360 | 336 |
} |
337 |
||
50113 | 338 |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
339 |
size_t JfrCheckpointManager::write() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
340 |
const size_t processed = write_mspace<MutexedWriteOp, CompositeOperation>(_free_list_mspace, _chunkwriter); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
341 |
synchronize_epoch(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
342 |
return processed; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
343 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
344 |
|
57987 | 345 |
size_t JfrCheckpointManager::write_epoch_transition_mspace() { |
346 |
return write_mspace<ExclusiveOp, CompositeOperation>(_epoch_transition_mspace, _chunkwriter); |
|
347 |
} |
|
348 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
349 |
typedef MutexedWriteOp<WriteOperation> FlushOperation; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
350 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
351 |
size_t JfrCheckpointManager::flush() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
352 |
WriteOperation wo(_chunkwriter); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
353 |
FlushOperation fo(wo); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
354 |
assert(_free_list_mspace->is_full_empty(), "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
355 |
process_free_list(fo, _free_list_mspace); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
356 |
return wo.processed(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
357 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
358 |
|
57987 | 359 |
typedef DiscardOp<DefaultDiscarder<JfrBuffer> > DiscardOperation; |
360 |
size_t JfrCheckpointManager::clear() { |
|
361 |
DiscardOperation discarder(mutexed); // mutexed discard mode |
|
362 |
process_free_list(discarder, _free_list_mspace); |
|
363 |
process_free_list(discarder, _epoch_transition_mspace); |
|
364 |
synchronize_epoch(); |
|
365 |
return discarder.elements(); |
|
366 |
} |
|
367 |
||
57882 | 368 |
// Optimization for write_types() and write_threads() is to write |
369 |
// directly into the epoch transition mspace because we will immediately |
|
370 |
// serialize and reset this mspace post-write. |
|
371 |
static JfrBuffer* get_epoch_transition_buffer(JfrCheckpointMspace* mspace, Thread* t) { |
|
372 |
assert(mspace != NULL, "invariant"); |
|
373 |
JfrBuffer* const buffer = mspace->free_head(); |
|
374 |
assert(buffer != NULL, "invariant"); |
|
375 |
buffer->acquire(t); |
|
376 |
buffer->set_lease(); |
|
377 |
DEBUG_ONLY(assert_free_lease(buffer);) |
|
378 |
return buffer; |
|
379 |
} |
|
380 |
||
50113 | 381 |
size_t JfrCheckpointManager::write_types() { |
57360 | 382 |
ResourceMark rm; |
383 |
HandleMark hm; |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
384 |
Thread* const t = Thread::current(); |
57882 | 385 |
JfrCheckpointWriter writer(t, get_epoch_transition_buffer(_epoch_transition_mspace, t), STATICS); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
386 |
JfrTypeManager::write_types(writer); |
50113 | 387 |
return writer.used_size(); |
388 |
} |
|
389 |
||
57882 | 390 |
size_t JfrCheckpointManager::write_threads() { |
391 |
ResourceMark rm; |
|
392 |
HandleMark hm; |
|
393 |
Thread* const t = Thread::current(); |
|
394 |
JfrCheckpointWriter writer(t, get_epoch_transition_buffer(_epoch_transition_mspace, t), THREADS); |
|
395 |
JfrTypeManager::write_threads(writer); |
|
396 |
return writer.used_size(); |
|
397 |
} |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
398 |
size_t JfrCheckpointManager::write_constants() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
399 |
write_types(); |
57882 | 400 |
write_threads(); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
401 |
return write_epoch_transition_mspace(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
402 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
403 |
|
57360 | 404 |
class JfrNotifyClosure : public ThreadClosure { |
405 |
public: |
|
406 |
void do_thread(Thread* t) { |
|
407 |
assert(t != NULL, "invariant"); |
|
408 |
assert(t->is_Java_thread(), "invariant"); |
|
409 |
assert_locked_or_safepoint(Threads_lock); |
|
410 |
JfrJavaEventWriter::notify((JavaThread*)t); |
|
411 |
} |
|
412 |
}; |
|
413 |
||
414 |
void JfrCheckpointManager::notify_threads() { |
|
415 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
416 |
JfrNotifyClosure tc; |
|
417 |
JfrJavaThreadIterator iter; |
|
418 |
while (iter.has_next()) { |
|
419 |
tc.do_thread(iter.next()); |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
void JfrCheckpointManager::notify_types_on_rotation() { |
|
424 |
JfrTypeManager::notify_types_on_rotation(); |
|
50113 | 425 |
} |
426 |
||
427 |
void JfrCheckpointManager::write_type_set() { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
428 |
JfrTypeManager::write_type_set(); |
50113 | 429 |
} |
430 |
||
431 |
void JfrCheckpointManager::write_type_set_for_unloaded_classes() { |
|
52212
e6973df15152
8212663: Remove conservative at_safepoint assert when JFR writes type sets during class unloading
eosterlund
parents:
50703
diff
changeset
|
432 |
assert_locked_or_safepoint(ClassLoaderDataGraph_lock); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
433 |
JfrTypeManager::write_type_set_for_unloaded_classes(); |
50113 | 434 |
} |
435 |
||
57934 | 436 |
bool JfrCheckpointManager::is_type_set_required() { |
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
437 |
return JfrTraceIdEpoch::has_changed_tag_state(); |
57873 | 438 |
} |
439 |
||
57934 | 440 |
bool JfrCheckpointManager::is_constant_set_required() { |
441 |
return JfrTypeManager::is_new_constant_registered(); |
|
442 |
} |
|
443 |
||
57360 | 444 |
size_t JfrCheckpointManager::flush_type_set() { |
57872 | 445 |
const size_t elements = JfrTypeManager::flush_type_set(); |
446 |
flush(); |
|
447 |
return elements; |
|
50113 | 448 |
} |
449 |
||
57934 | 450 |
void JfrCheckpointManager::flush_constant_set() { |
451 |
flush(); |
|
452 |
} |
|
453 |
||
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
454 |
void JfrCheckpointManager::create_thread_blob(Thread* t) { |
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
57934
diff
changeset
|
455 |
JfrTypeManager::create_thread_blob(t); |
50113 | 456 |
} |
57360 | 457 |
|
458 |
void JfrCheckpointManager::write_thread_checkpoint(Thread* t) { |
|
459 |
JfrTypeManager::write_thread_checkpoint(t); |
|
460 |
} |
|
57987 | 461 |
|
462 |
void JfrCheckpointManager::shift_epoch() { |
|
463 |
debug_only(const u1 current_epoch = JfrTraceIdEpoch::current();) |
|
464 |
JfrTraceIdEpoch::shift_epoch(); |
|
465 |
assert(current_epoch != JfrTraceIdEpoch::current(), "invariant"); |
|
466 |
} |
|
467 |