author | mgronlun |
Thu, 29 Aug 2019 12:53:05 +0200 | |
branch | JEP-349-branch |
changeset 57934 | 9c150f2b1fea |
parent 57887 | a9cc3698a55c |
child 57987 | 23e3cd901cb6 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53897
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 |
||
25 |
#include "precompiled.hpp" |
|
57360 | 26 |
#include "jfrfiles/jfrEventClasses.hpp" |
50113 | 27 |
#include "jfr/jni/jfrJavaSupport.hpp" |
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
|
28 |
#include "jfr/leakprofiler/leakProfiler.hpp" |
50113 | 29 |
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
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
|
30 |
#include "jfr/leakprofiler/sampling/objectSampler.hpp" |
50113 | 31 |
#include "jfr/recorder/jfrRecorder.hpp" |
32 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
|
33 |
#include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp" |
|
53014
339d2fbe8675
8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
52877
diff
changeset
|
34 |
#include "jfr/recorder/repository/jfrChunkRotation.hpp" |
50113 | 35 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
36 |
#include "jfr/recorder/repository/jfrRepository.hpp" |
|
37 |
#include "jfr/recorder/service/jfrPostBox.hpp" |
|
38 |
#include "jfr/recorder/service/jfrRecorderService.hpp" |
|
39 |
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" |
|
40 |
#include "jfr/recorder/storage/jfrStorage.hpp" |
|
41 |
#include "jfr/recorder/storage/jfrStorageControl.hpp" |
|
42 |
#include "jfr/recorder/stringpool/jfrStringPool.hpp" |
|
43 |
#include "jfr/utilities/jfrAllocation.hpp" |
|
44 |
#include "jfr/utilities/jfrTime.hpp" |
|
45 |
#include "jfr/writers/jfrJavaEventWriter.hpp" |
|
46 |
#include "jfr/utilities/jfrTypes.hpp" |
|
47 |
#include "logging/log.hpp" |
|
48 |
#include "memory/resourceArea.hpp" |
|
49 |
#include "runtime/atomic.hpp" |
|
50 |
#include "runtime/handles.inline.hpp" |
|
51 |
#include "runtime/mutexLocker.hpp" |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50113
diff
changeset
|
52 |
#include "runtime/orderAccess.hpp" |
50113 | 53 |
#include "runtime/os.hpp" |
54 |
#include "runtime/safepoint.hpp" |
|
55 |
#include "runtime/thread.inline.hpp" |
|
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
51334
diff
changeset
|
56 |
#include "runtime/vmOperations.hpp" |
50113 | 57 |
#include "runtime/vmThread.hpp" |
58 |
||
59 |
// set data iff *dest == NULL |
|
60 |
static bool try_set(void* const data, void** dest, bool clear) { |
|
61 |
assert(data != NULL, "invariant"); |
|
62 |
const void* const current = OrderAccess::load_acquire(dest); |
|
63 |
if (current != NULL) { |
|
64 |
if (current != data) { |
|
65 |
// already set |
|
66 |
return false; |
|
67 |
} |
|
68 |
assert(current == data, "invariant"); |
|
69 |
if (!clear) { |
|
70 |
// recursion disallowed |
|
71 |
return false; |
|
72 |
} |
|
73 |
} |
|
74 |
return Atomic::cmpxchg(clear ? NULL : data, dest, current) == current; |
|
75 |
} |
|
76 |
||
77 |
static void* rotation_thread = NULL; |
|
78 |
static const int rotation_try_limit = 1000; |
|
79 |
static const int rotation_retry_sleep_millis = 10; |
|
80 |
||
57360 | 81 |
// incremented on each flushpoint |
82 |
static u8 flushpoint_id = 0; |
|
83 |
||
50113 | 84 |
class RotationLock : public StackObj { |
85 |
private: |
|
86 |
Thread* const _thread; |
|
87 |
bool _acquired; |
|
88 |
||
89 |
void log(bool recursion) { |
|
90 |
assert(!_acquired, "invariant"); |
|
91 |
const char* error_msg = NULL; |
|
92 |
if (recursion) { |
|
93 |
error_msg = "Unable to issue rotation due to recursive calls."; |
|
94 |
} |
|
95 |
else { |
|
96 |
error_msg = "Unable to issue rotation due to wait timeout."; |
|
97 |
} |
|
98 |
log_info(jfr)( // For user, should not be "jfr, system" |
|
99 |
"%s", error_msg); |
|
100 |
} |
|
101 |
public: |
|
102 |
RotationLock(Thread* thread) : _thread(thread), _acquired(false) { |
|
103 |
assert(_thread != NULL, "invariant"); |
|
104 |
if (_thread == rotation_thread) { |
|
105 |
// recursion not supported |
|
106 |
log(true); |
|
107 |
return; |
|
108 |
} |
|
109 |
||
110 |
// limited to not spin indefinitely |
|
111 |
for (int i = 0; i < rotation_try_limit; ++i) { |
|
112 |
if (try_set(_thread, &rotation_thread, false)) { |
|
113 |
_acquired = true; |
|
114 |
assert(_thread == rotation_thread, "invariant"); |
|
115 |
return; |
|
116 |
} |
|
117 |
if (_thread->is_Java_thread()) { |
|
118 |
// in order to allow the system to move to a safepoint |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53897
diff
changeset
|
119 |
MutexLocker msg_lock(JfrMsg_lock); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53897
diff
changeset
|
120 |
JfrMsg_lock->wait(rotation_retry_sleep_millis); |
50113 | 121 |
} |
122 |
else { |
|
123 |
os::naked_short_sleep(rotation_retry_sleep_millis); |
|
124 |
} |
|
125 |
} |
|
126 |
log(false); |
|
127 |
} |
|
128 |
||
129 |
~RotationLock() { |
|
130 |
assert(_thread != NULL, "invariant"); |
|
131 |
if (_acquired) { |
|
132 |
assert(_thread == rotation_thread, "invariant"); |
|
133 |
while (!try_set(_thread, &rotation_thread, true)); |
|
134 |
} |
|
135 |
} |
|
136 |
bool not_acquired() const { return !_acquired; } |
|
137 |
}; |
|
138 |
||
57360 | 139 |
template <typename E, typename Instance, size_t(Instance::*func)()> |
140 |
class ServiceFunctor { |
|
141 |
private: |
|
142 |
Instance& _instance; |
|
143 |
u4 _elements; |
|
144 |
public: |
|
145 |
typedef E EventType; |
|
146 |
ServiceFunctor(Instance& instance) : _instance(instance), _elements(0) {} |
|
147 |
bool process() { |
|
148 |
_elements = (u4)(_instance.*func)(); |
|
149 |
return true; |
|
150 |
} |
|
151 |
u4 elements() const { return _elements; } |
|
152 |
}; |
|
153 |
||
154 |
template <typename ContentFunctor> |
|
155 |
class WriteSubsystem : public StackObj { |
|
156 |
protected: |
|
157 |
const JfrTicks _start_time; |
|
158 |
JfrTicks _end_time; |
|
159 |
JfrChunkWriter& _cw; |
|
160 |
ContentFunctor& _content_functor; |
|
161 |
const int64_t _start_offset; |
|
162 |
public: |
|
163 |
typedef typename ContentFunctor::EventType EventType; |
|
164 |
||
165 |
WriteSubsystem(JfrChunkWriter& cw, ContentFunctor& functor) : |
|
166 |
_start_time(JfrTicks::now()), |
|
167 |
_end_time(), |
|
168 |
_cw(cw), |
|
169 |
_content_functor(functor), |
|
170 |
_start_offset(_cw.current_offset()) { |
|
171 |
assert(_cw.is_valid(), "invariant"); |
|
172 |
} |
|
173 |
||
174 |
bool process() { |
|
175 |
// invocation |
|
176 |
_content_functor.process(); |
|
177 |
_end_time = JfrTicks::now(); |
|
178 |
return 0 != _content_functor.elements(); |
|
179 |
} |
|
180 |
||
181 |
const JfrTicks& start_time() const { |
|
182 |
return _start_time; |
|
183 |
} |
|
184 |
||
185 |
const JfrTicks& end_time() const { |
|
186 |
return _end_time; |
|
187 |
} |
|
188 |
||
189 |
int64_t start_offset() const { |
|
190 |
return _start_offset; |
|
191 |
} |
|
192 |
||
193 |
int64_t end_offset() const { |
|
194 |
return current_offset(); |
|
195 |
} |
|
196 |
||
197 |
int64_t current_offset() const { |
|
198 |
return _cw.current_offset(); |
|
199 |
} |
|
200 |
||
201 |
u4 elements() const { |
|
202 |
return (u4) _content_functor.elements(); |
|
203 |
} |
|
204 |
||
205 |
u4 size() const { |
|
206 |
return (u4)(end_offset() - start_offset()); |
|
207 |
} |
|
208 |
||
209 |
static bool is_event_enabled() { |
|
210 |
return EventType::is_enabled(); |
|
211 |
} |
|
212 |
||
213 |
static u8 event_id() { |
|
214 |
return EventType::eventId; |
|
215 |
} |
|
216 |
||
217 |
void write_elements(int64_t offset) { |
|
218 |
_cw.write_padded_at_offset<u4>(elements(), offset); |
|
219 |
} |
|
220 |
||
221 |
void write_size() { |
|
222 |
_cw.write_padded_at_offset<u4>(size(), start_offset()); |
|
223 |
} |
|
224 |
||
225 |
void set_last_checkpoint() { |
|
226 |
_cw.set_last_checkpoint_offset(start_offset()); |
|
227 |
} |
|
228 |
||
229 |
void rewind() { |
|
230 |
_cw.seek(start_offset()); |
|
231 |
} |
|
232 |
||
233 |
}; |
|
234 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
235 |
static int64_t write_checkpoint_event_prologue(JfrChunkWriter& cw, u8 type_id) { |
57360 | 236 |
const int64_t last_cp_offset = cw.last_checkpoint_offset(); |
237 |
const int64_t last_cp_relative_offset = 0 == last_cp_offset ? 0 : last_cp_offset - cw.current_offset(); |
|
50113 | 238 |
cw.reserve(sizeof(u4)); |
239 |
cw.write<u8>(EVENT_CHECKPOINT); |
|
240 |
cw.write(JfrTicks::now()); |
|
57360 | 241 |
cw.write<int64_t>((int64_t)0); |
242 |
cw.write(last_cp_relative_offset); // write last checkpoint offset delta |
|
50113 | 243 |
cw.write<bool>(false); // flushpoint |
57360 | 244 |
cw.write<u4>((u4)1); // nof types in this checkpoint |
245 |
cw.write<u8>(type_id); |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
246 |
const int64_t number_of_elements_offset = cw.current_offset(); |
50113 | 247 |
cw.reserve(sizeof(u4)); |
248 |
return number_of_elements_offset; |
|
249 |
} |
|
250 |
||
251 |
template <typename ContentFunctor> |
|
57360 | 252 |
class WriteSubsystemCheckpointEvent : public WriteSubsystem<ContentFunctor> { |
50113 | 253 |
private: |
57360 | 254 |
const u8 _type_id; |
50113 | 255 |
public: |
57360 | 256 |
WriteSubsystemCheckpointEvent(JfrChunkWriter& cw, ContentFunctor& functor, u8 type_id) : |
257 |
WriteSubsystem<ContentFunctor>(cw, functor), _type_id(type_id) {} |
|
258 |
||
50113 | 259 |
bool process() { |
57360 | 260 |
const int64_t num_elements_offset = write_checkpoint_event_prologue(this->_cw, _type_id); |
261 |
if (!WriteSubsystem<ContentFunctor>::process()) { |
|
50113 | 262 |
// nothing to do, rewind writer to start |
57360 | 263 |
this->rewind(); |
264 |
assert(this->current_offset() == this->start_offset(), "invariant"); |
|
265 |
return false; |
|
50113 | 266 |
} |
57360 | 267 |
assert(this->elements() > 0, "invariant"); |
268 |
assert(this->current_offset() > num_elements_offset, "invariant"); |
|
269 |
this->write_elements(num_elements_offset); |
|
270 |
this->write_size(); |
|
271 |
this->set_last_checkpoint(); |
|
50113 | 272 |
return true; |
273 |
} |
|
274 |
}; |
|
275 |
||
57360 | 276 |
template <typename Functor> |
277 |
static void write_flush_event(Functor& f) { |
|
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
|
278 |
if (Functor::is_event_enabled()) { |
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 |
typename Functor::EventType e(UNTIMED); |
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 |
e.set_starttime(f.start_time()); |
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 |
e.set_endtime(f.end_time()); |
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
|
282 |
e.set_flushId(flushpoint_id); |
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 |
e.set_elements(f.elements()); |
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
|
284 |
e.set_size(f.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
|
285 |
e.commit(); |
50113 | 286 |
} |
57360 | 287 |
} |
288 |
||
289 |
template <typename Functor> |
|
290 |
static u4 invoke(Functor& f) { |
|
291 |
f.process(); |
|
292 |
return f.elements(); |
|
293 |
} |
|
294 |
||
295 |
template <typename Functor> |
|
296 |
static u4 invoke_with_flush_event(Functor& f) { |
|
297 |
const u4 elements = invoke(f); |
|
57872 | 298 |
write_flush_event(f); |
57360 | 299 |
return elements; |
300 |
} |
|
50113 | 301 |
|
302 |
template <typename Instance, void(Instance::*func)()> |
|
303 |
class JfrVMOperation : public VM_Operation { |
|
304 |
private: |
|
305 |
Instance& _instance; |
|
306 |
public: |
|
307 |
JfrVMOperation(Instance& instance) : _instance(instance) {} |
|
308 |
void doit() { (_instance.*func)(); } |
|
309 |
VMOp_Type type() const { return VMOp_JFRCheckpoint; } |
|
310 |
Mode evaluation_mode() const { return _safepoint; } // default |
|
311 |
}; |
|
312 |
||
57360 | 313 |
class FlushStackTraceRepository : public StackObj { |
50113 | 314 |
private: |
315 |
JfrStackTraceRepository& _repo; |
|
316 |
JfrChunkWriter& _cw; |
|
57360 | 317 |
size_t _elements; |
50113 | 318 |
bool _clear; |
319 |
||
320 |
public: |
|
57360 | 321 |
typedef EventFlushStacktrace EventType; |
322 |
FlushStackTraceRepository(JfrStackTraceRepository& repo, JfrChunkWriter& cw, bool clear) : |
|
323 |
_repo(repo), _cw(cw), _elements(0), _clear(clear) {} |
|
50113 | 324 |
bool process() { |
57360 | 325 |
_elements = _repo.write(_cw, _clear); |
50113 | 326 |
return true; |
327 |
} |
|
57360 | 328 |
size_t elements() const { return _elements; } |
329 |
void reset() { _elements = 0; } |
|
330 |
}; |
|
331 |
||
332 |
class FlushMetadataEvent : public StackObj { |
|
333 |
private: |
|
334 |
JfrChunkWriter& _cw; |
|
335 |
public: |
|
336 |
typedef EventFlushMetadata EventType; |
|
337 |
FlushMetadataEvent(JfrChunkWriter& cw) : _cw(cw) {} |
|
338 |
bool process() { |
|
339 |
JfrMetadataEvent::write(_cw); |
|
340 |
return true; |
|
341 |
} |
|
342 |
size_t elements() const { return 1; } |
|
50113 | 343 |
}; |
344 |
||
345 |
static bool recording = false; |
|
346 |
||
347 |
static void set_recording_state(bool is_recording) { |
|
348 |
OrderAccess::storestore(); |
|
349 |
recording = is_recording; |
|
350 |
} |
|
351 |
||
352 |
bool JfrRecorderService::is_recording() { |
|
353 |
return recording; |
|
354 |
} |
|
355 |
||
356 |
JfrRecorderService::JfrRecorderService() : |
|
357 |
_checkpoint_manager(JfrCheckpointManager::instance()), |
|
358 |
_chunkwriter(JfrRepository::chunkwriter()), |
|
359 |
_repository(JfrRepository::instance()), |
|
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50429
diff
changeset
|
360 |
_stack_trace_repository(JfrStackTraceRepository::instance()), |
50113 | 361 |
_storage(JfrStorage::instance()), |
362 |
_string_pool(JfrStringPool::instance()) {} |
|
363 |
||
364 |
void JfrRecorderService::start() { |
|
365 |
RotationLock rl(Thread::current()); |
|
366 |
if (rl.not_acquired()) { |
|
367 |
return; |
|
368 |
} |
|
369 |
log_debug(jfr, system)("Request to START recording"); |
|
370 |
assert(!is_recording(), "invariant"); |
|
371 |
clear(); |
|
372 |
set_recording_state(true); |
|
373 |
assert(is_recording(), "invariant"); |
|
374 |
open_new_chunk(); |
|
375 |
log_debug(jfr, system)("Recording STARTED"); |
|
376 |
} |
|
377 |
||
378 |
void JfrRecorderService::clear() { |
|
379 |
ResourceMark rm; |
|
380 |
HandleMark hm; |
|
381 |
pre_safepoint_clear(); |
|
382 |
invoke_safepoint_clear(); |
|
383 |
post_safepoint_clear(); |
|
384 |
} |
|
385 |
||
386 |
void JfrRecorderService::pre_safepoint_clear() { |
|
387 |
_stack_trace_repository.clear(); |
|
388 |
_string_pool.clear(); |
|
389 |
_storage.clear(); |
|
390 |
} |
|
391 |
||
392 |
void JfrRecorderService::invoke_safepoint_clear() { |
|
393 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_clear> safepoint_task(*this); |
|
394 |
VMThread::execute(&safepoint_task); |
|
395 |
} |
|
396 |
||
397 |
// |
|
398 |
// safepoint clear sequence |
|
399 |
// |
|
400 |
// clear stacktrace repository -> |
|
401 |
// clear string pool -> |
|
402 |
// clear storage -> |
|
403 |
// shift epoch -> |
|
404 |
// update time |
|
405 |
// |
|
406 |
void JfrRecorderService::safepoint_clear() { |
|
407 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
408 |
_stack_trace_repository.clear(); |
|
409 |
_string_pool.clear(); |
|
410 |
_storage.clear(); |
|
411 |
_checkpoint_manager.shift_epoch(); |
|
57887 | 412 |
_chunkwriter.set_time_stamp(); |
50113 | 413 |
} |
414 |
||
415 |
void JfrRecorderService::post_safepoint_clear() { |
|
416 |
_checkpoint_manager.clear(); |
|
417 |
} |
|
418 |
||
419 |
static void stop() { |
|
420 |
assert(JfrRecorderService::is_recording(), "invariant"); |
|
421 |
log_debug(jfr, system)("Recording STOPPED"); |
|
422 |
set_recording_state(false); |
|
423 |
assert(!JfrRecorderService::is_recording(), "invariant"); |
|
424 |
} |
|
425 |
||
426 |
void JfrRecorderService::rotate(int msgs) { |
|
427 |
RotationLock rl(Thread::current()); |
|
428 |
if (rl.not_acquired()) { |
|
429 |
return; |
|
430 |
} |
|
431 |
static bool vm_error = false; |
|
432 |
if (msgs & MSGBIT(MSG_VM_ERROR)) { |
|
433 |
vm_error = true; |
|
434 |
prepare_for_vm_error_rotation(); |
|
435 |
} |
|
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
|
436 |
if (!_storage.control().to_disk()) { |
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
|
437 |
in_memory_rotation(); |
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
|
438 |
} else if (vm_error) { |
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
|
439 |
vm_error_rotation(); |
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
|
440 |
} else { |
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
|
441 |
chunk_rotation(); |
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
|
442 |
} |
50113 | 443 |
if (msgs & (MSGBIT(MSG_STOP))) { |
444 |
stop(); |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
void JfrRecorderService::prepare_for_vm_error_rotation() { |
|
449 |
if (!_chunkwriter.is_valid()) { |
|
450 |
open_new_chunk(true); |
|
451 |
} |
|
452 |
_checkpoint_manager.register_service_thread(Thread::current()); |
|
453 |
} |
|
454 |
||
455 |
void JfrRecorderService::open_new_chunk(bool vm_error) { |
|
53014
339d2fbe8675
8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
52877
diff
changeset
|
456 |
JfrChunkRotation::on_rotation(); |
57360 | 457 |
const bool valid_chunk = _repository.open_chunk(vm_error); |
458 |
_storage.control().set_to_disk(valid_chunk); |
|
459 |
if (valid_chunk) { |
|
460 |
_checkpoint_manager.write_constants(); |
|
50113 | 461 |
} |
462 |
} |
|
463 |
||
464 |
void JfrRecorderService::in_memory_rotation() { |
|
465 |
// currently running an in-memory recording |
|
57360 | 466 |
assert(!_storage.control().to_disk(), "invariant"); |
50113 | 467 |
open_new_chunk(); |
468 |
if (_chunkwriter.is_valid()) { |
|
469 |
// dump all in-memory buffer data to the newly created chunk |
|
470 |
serialize_storage_from_in_memory_recording(); |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
void JfrRecorderService::serialize_storage_from_in_memory_recording() { |
|
475 |
_storage.write(); |
|
476 |
} |
|
477 |
||
478 |
void JfrRecorderService::chunk_rotation() { |
|
479 |
finalize_current_chunk(); |
|
480 |
open_new_chunk(); |
|
481 |
} |
|
482 |
||
483 |
void JfrRecorderService::finalize_current_chunk() { |
|
484 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
485 |
write(); |
|
486 |
} |
|
487 |
||
488 |
void JfrRecorderService::write() { |
|
489 |
ResourceMark rm; |
|
490 |
HandleMark hm; |
|
491 |
pre_safepoint_write(); |
|
492 |
invoke_safepoint_write(); |
|
493 |
post_safepoint_write(); |
|
494 |
} |
|
495 |
||
57360 | 496 |
typedef ServiceFunctor<EventFlushStringPool, JfrStringPool, &JfrStringPool::write> FlushStringPoolFunctor; |
497 |
typedef ServiceFunctor<EventFlushStringPool, JfrStringPool, &JfrStringPool::write_at_safepoint> FlushStringPoolSafepointFunctor; |
|
498 |
typedef WriteSubsystemCheckpointEvent<FlushStackTraceRepository> FlushStackTraceCheckpoint; |
|
499 |
typedef WriteSubsystemCheckpointEvent<FlushStringPoolFunctor> FlushStringPoolCheckpoint; |
|
500 |
typedef WriteSubsystemCheckpointEvent<FlushStringPoolSafepointFunctor> FlushStringPoolCheckpointSafepoint; |
|
501 |
||
502 |
static u4 flush_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter, bool clear) { |
|
503 |
FlushStackTraceRepository flush_stacktrace_repo(stack_trace_repo, chunkwriter, clear); |
|
504 |
FlushStackTraceCheckpoint flush_stack_trace_checkpoint(chunkwriter, flush_stacktrace_repo, TYPE_STACKTRACE); |
|
505 |
return invoke_with_flush_event(flush_stack_trace_checkpoint); |
|
506 |
} |
|
507 |
||
508 |
static u4 flush_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter) { |
|
509 |
return flush_stacktrace(stack_trace_repo, chunkwriter, false); |
|
510 |
} |
|
511 |
||
512 |
static u4 flush_stacktrace_checkpoint(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter, bool clear) { |
|
513 |
FlushStackTraceRepository flush_stacktrace_repo(stack_trace_repo, chunkwriter, clear); |
|
514 |
FlushStackTraceCheckpoint flush_stack_trace_checkpoint(chunkwriter, flush_stacktrace_repo, TYPE_STACKTRACE); |
|
515 |
return invoke(flush_stack_trace_checkpoint); |
|
516 |
} |
|
517 |
||
518 |
static u4 flush_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
519 |
FlushStringPoolFunctor flush_string_pool(string_pool); |
|
520 |
FlushStringPoolCheckpoint flush_string_pool_checkpoint(chunkwriter, flush_string_pool, TYPE_STRING); |
|
521 |
return invoke_with_flush_event(flush_string_pool_checkpoint); |
|
522 |
} |
|
50113 | 523 |
|
57360 | 524 |
static u4 flush_stringpool_checkpoint(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
525 |
FlushStringPoolFunctor flush_string_pool(string_pool); |
|
526 |
FlushStringPoolCheckpoint flush_string_pool_checkpoint(chunkwriter, flush_string_pool, TYPE_STRING); |
|
527 |
return invoke(flush_string_pool_checkpoint); |
|
528 |
} |
|
529 |
||
530 |
static u4 flush_stringpool_checkpoint_safepoint(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
531 |
FlushStringPoolSafepointFunctor flush_string_pool(string_pool); |
|
532 |
FlushStringPoolCheckpointSafepoint flush_string_pool_checkpoint(chunkwriter, flush_string_pool, TYPE_STRING); |
|
533 |
return invoke(flush_string_pool_checkpoint); |
|
534 |
} |
|
535 |
||
536 |
typedef ServiceFunctor<EventFlushTypeSet, JfrCheckpointManager, &JfrCheckpointManager::flush_type_set> FlushTypeSetFunctor; |
|
537 |
typedef WriteSubsystem<FlushTypeSetFunctor> FlushTypeSet; |
|
538 |
||
539 |
static u4 flush_typeset(JfrCheckpointManager& checkpoint_manager, JfrChunkWriter& chunkwriter) { |
|
540 |
FlushTypeSetFunctor flush_type_set(checkpoint_manager); |
|
541 |
FlushTypeSet fts(chunkwriter, flush_type_set); |
|
542 |
return invoke_with_flush_event(fts); |
|
543 |
} |
|
544 |
||
545 |
typedef WriteSubsystem<FlushMetadataEvent> FlushMetadata; |
|
546 |
||
547 |
static u4 flush_metadata_event(JfrChunkWriter& chunkwriter) { |
|
548 |
assert(chunkwriter.is_valid(), "invariant"); |
|
549 |
FlushMetadataEvent fme(chunkwriter); |
|
550 |
FlushMetadata fm(chunkwriter, fme); |
|
551 |
return invoke_with_flush_event(fm); |
|
552 |
} |
|
553 |
||
554 |
static u4 flush_metadata_event_checkpoint(JfrChunkWriter& chunkwriter) { |
|
555 |
assert(chunkwriter.is_valid(), "invariant"); |
|
556 |
FlushMetadataEvent wme(chunkwriter); |
|
557 |
FlushMetadata wm(chunkwriter, wme); |
|
558 |
return invoke(wm); |
|
50113 | 559 |
} |
560 |
||
57360 | 561 |
static JfrBuffer* thread_local_buffer() { |
562 |
return Thread::current()->jfr_thread_local()->native_buffer(); |
|
563 |
} |
|
564 |
||
565 |
static void reset_buffer(JfrBuffer* buffer) { |
|
566 |
assert(buffer != NULL, "invariant"); |
|
567 |
assert(buffer == thread_local_buffer(), "invariant"); |
|
568 |
buffer->set_pos(const_cast<u1*>(buffer->top())); |
|
569 |
assert(buffer->empty(), "invariant"); |
|
570 |
} |
|
571 |
||
572 |
static void reset_thread_local_buffer() { |
|
573 |
reset_buffer(thread_local_buffer()); |
|
574 |
} |
|
575 |
||
576 |
static void write_thread_local_buffer(JfrChunkWriter& chunkwriter) { |
|
577 |
JfrBuffer * const buffer = thread_local_buffer(); |
|
578 |
assert(buffer != NULL, "invariant"); |
|
579 |
if (!buffer->empty()) { |
|
580 |
chunkwriter.write_unbuffered(buffer->top(), buffer->pos() - buffer->top()); |
|
581 |
reset_buffer(buffer); |
|
582 |
} |
|
583 |
assert(buffer->empty(), "invariant"); |
|
584 |
} |
|
585 |
||
586 |
typedef ServiceFunctor<EventFlushStorage, JfrStorage, &JfrStorage::write> FlushStorageFunctor; |
|
587 |
typedef WriteSubsystem<FlushStorageFunctor> FlushStorage; |
|
588 |
||
589 |
static size_t flush_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) { |
|
590 |
assert(chunkwriter.is_valid(), "invariant"); |
|
591 |
FlushStorageFunctor fsf(storage); |
|
592 |
FlushStorage fs(chunkwriter, fsf); |
|
593 |
return invoke_with_flush_event(fs); |
|
50113 | 594 |
} |
595 |
||
57360 | 596 |
typedef ServiceFunctor<EventFlush, JfrRecorderService, &JfrRecorderService::flush> FlushFunctor; |
597 |
typedef WriteSubsystem<FlushFunctor> Flush; |
|
598 |
||
599 |
static bool write_metadata_in_flushpoint = false; |
|
600 |
||
601 |
size_t JfrRecorderService::flush() { |
|
602 |
size_t total_elements = 0; |
|
603 |
if (write_metadata_in_flushpoint) { |
|
604 |
total_elements = flush_metadata_event(_chunkwriter); |
|
605 |
} |
|
606 |
const size_t storage_elements = flush_storage(_storage, _chunkwriter); |
|
607 |
if (0 == storage_elements) { |
|
608 |
return total_elements; |
|
609 |
} |
|
610 |
total_elements += storage_elements; |
|
57872 | 611 |
if (_stack_trace_repository.is_modified()) { |
612 |
total_elements += flush_stacktrace(_stack_trace_repository, _chunkwriter); |
|
613 |
} |
|
614 |
if (_string_pool.is_modified()) { |
|
57360 | 615 |
total_elements += flush_stringpool(_string_pool, _chunkwriter); |
616 |
} |
|
57934 | 617 |
if (_checkpoint_manager.is_type_set_required()) { |
57873 | 618 |
total_elements += flush_typeset(_checkpoint_manager, _chunkwriter); |
57934 | 619 |
} else if (_checkpoint_manager.is_constant_set_required()) { |
620 |
// don't tally this, it is only in order to flush the waiting constants |
|
621 |
_checkpoint_manager.flush_constant_set(); |
|
57873 | 622 |
} |
57360 | 623 |
return total_elements; |
624 |
} |
|
625 |
||
626 |
void JfrRecorderService::flush(int msgs) { |
|
627 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
628 |
ResourceMark rm; |
|
629 |
HandleMark hm; |
|
57872 | 630 |
write_metadata_in_flushpoint = (msgs & MSGBIT(MSG_FLUSHPOINT_METADATA)); |
57360 | 631 |
++flushpoint_id; |
57872 | 632 |
reset_thread_local_buffer(); |
57360 | 633 |
FlushFunctor flushpoint(*this); |
634 |
Flush fl(_chunkwriter, flushpoint); |
|
635 |
invoke_with_flush_event(fl); |
|
636 |
write_thread_local_buffer(_chunkwriter); |
|
637 |
_repository.flush_chunk(); |
|
50113 | 638 |
} |
639 |
||
640 |
// |
|
641 |
// pre-safepoint write sequence |
|
642 |
// |
|
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
|
643 |
// write stack trace checkpoint -> |
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
|
644 |
// write string pool checkpoint -> |
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
|
645 |
// notify about pending rotation -> |
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
|
646 |
// write storage |
50113 | 647 |
// |
648 |
void JfrRecorderService::pre_safepoint_write() { |
|
649 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
57872 | 650 |
if (_stack_trace_repository.is_modified()) { |
651 |
flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, false); |
|
652 |
} |
|
653 |
if (_string_pool.is_modified()) { |
|
57360 | 654 |
flush_stringpool_checkpoint(_string_pool, _chunkwriter); |
655 |
} |
|
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
|
656 |
if (LeakProfiler::is_running()) { |
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
|
657 |
// Exclusive access to the object sampler instance. |
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
|
658 |
// The sampler is released (unlocked) later in post_safepoint_write. |
57934 | 659 |
ObjectSampleCheckpoint::on_rotation(ObjectSampler::acquire(), _stack_trace_repository); |
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
|
660 |
} |
57360 | 661 |
_checkpoint_manager.notify_types_on_rotation(); |
50113 | 662 |
_storage.write(); |
663 |
} |
|
664 |
||
665 |
void JfrRecorderService::invoke_safepoint_write() { |
|
666 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_write> safepoint_task(*this); |
|
667 |
VMThread::execute(&safepoint_task); |
|
668 |
} |
|
669 |
||
670 |
// |
|
671 |
// safepoint write sequence |
|
672 |
// |
|
57360 | 673 |
// write object sample stacktraces -> |
674 |
// write stacktrace repository -> |
|
675 |
// write string pool -> |
|
676 |
// write storage -> |
|
677 |
// notify java threads -> |
|
678 |
// shift_epoch -> |
|
679 |
// update time |
|
50113 | 680 |
// |
681 |
void JfrRecorderService::safepoint_write() { |
|
682 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
57360 | 683 |
flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, true); |
57872 | 684 |
if (_string_pool.is_modified()) { |
57360 | 685 |
flush_stringpool_checkpoint_safepoint(_string_pool, _chunkwriter); |
686 |
} |
|
50113 | 687 |
_storage.write_at_safepoint(); |
57360 | 688 |
_checkpoint_manager.notify_threads(); |
50113 | 689 |
_checkpoint_manager.shift_epoch(); |
57887 | 690 |
_chunkwriter.set_time_stamp(); |
50113 | 691 |
} |
692 |
||
693 |
// |
|
694 |
// post-safepoint write sequence |
|
695 |
// |
|
57360 | 696 |
// write type set -> |
697 |
// write checkpoints -> |
|
698 |
// write metadata event -> |
|
699 |
// close chunk |
|
50113 | 700 |
// |
701 |
void JfrRecorderService::post_safepoint_write() { |
|
702 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
703 |
// During the safepoint tasks just completed, the system transitioned to a new epoch. |
|
704 |
// Type tagging is epoch relative which entails we are able to write out the |
|
705 |
// already tagged artifacts for the previous epoch. We can accomplish this concurrently |
|
706 |
// with threads now tagging artifacts in relation to the new, now updated, epoch and remain outside of a safepoint. |
|
707 |
_checkpoint_manager.write_type_set(); |
|
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
|
708 |
if (LeakProfiler::is_running()) { |
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
|
709 |
// The object sampler instance was exclusively acquired and locked in pre_safepoint_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
|
710 |
// Note: There is a dependency on write_type_set() above, ensure the release is subsequent. |
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
|
711 |
ObjectSampler::release(); |
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
|
712 |
} |
50113 | 713 |
// serialize any outstanding checkpoint memory |
714 |
_checkpoint_manager.write(); |
|
715 |
// serialize the metadata descriptor event and close out the chunk |
|
57360 | 716 |
flush_metadata_event_checkpoint(_chunkwriter); |
717 |
_repository.close_chunk(); |
|
50113 | 718 |
} |
719 |
||
720 |
void JfrRecorderService::vm_error_rotation() { |
|
721 |
if (_chunkwriter.is_valid()) { |
|
722 |
finalize_current_chunk_on_vm_error(); |
|
723 |
assert(!_chunkwriter.is_valid(), "invariant"); |
|
724 |
_repository.on_vm_error(); |
|
725 |
} |
|
726 |
} |
|
727 |
||
728 |
void JfrRecorderService::finalize_current_chunk_on_vm_error() { |
|
729 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
730 |
pre_safepoint_write(); |
|
731 |
// Do not attempt safepoint dependent operations during emergency dump. |
|
732 |
// Optimistically write tagged artifacts. |
|
733 |
_checkpoint_manager.shift_epoch(); |
|
734 |
// update time |
|
57887 | 735 |
_chunkwriter.set_time_stamp(); |
50113 | 736 |
post_safepoint_write(); |
737 |
} |
|
738 |
||
739 |
void JfrRecorderService::process_full_buffers() { |
|
740 |
if (_chunkwriter.is_valid()) { |
|
741 |
_storage.write_full(); |
|
742 |
} |
|
743 |
} |
|
744 |
||
745 |
void JfrRecorderService::scavenge() { |
|
746 |
_storage.scavenge(); |
|
747 |
} |
|
748 |
||
749 |
void JfrRecorderService::evaluate_chunk_size_for_rotation() { |
|
53014
339d2fbe8675
8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
52877
diff
changeset
|
750 |
JfrChunkRotation::evaluate(_chunkwriter); |
50113 | 751 |
} |