author | rehn |
Fri, 29 Nov 2019 12:09:25 +0100 | |
changeset 59325 | 3636bab5e81e |
parent 59290 | 97d13893ec3c |
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" |
|
58863 | 26 |
#include "jfrfiles/jfrEventClasses.hpp" |
50113 | 27 |
#include "jfr/jni/jfrJavaSupport.hpp" |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
28 |
#include "jfr/leakprofiler/leakProfiler.hpp" |
50113 | 29 |
#include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
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/handles.inline.hpp" |
|
50 |
#include "runtime/mutexLocker.hpp" |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50113
diff
changeset
|
51 |
#include "runtime/orderAccess.hpp" |
50113 | 52 |
#include "runtime/os.hpp" |
53 |
#include "runtime/safepoint.hpp" |
|
54 |
#include "runtime/thread.inline.hpp" |
|
52877
9e041366c764
8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents:
51334
diff
changeset
|
55 |
#include "runtime/vmOperations.hpp" |
50113 | 56 |
#include "runtime/vmThread.hpp" |
57 |
||
58863 | 58 |
// incremented on each flushpoint |
59 |
static u8 flushpoint_id = 0; |
|
60 |
||
61 |
template <typename E, typename Instance, size_t(Instance::*func)()> |
|
62 |
class Content { |
|
63 |
private: |
|
64 |
Instance& _instance; |
|
65 |
u4 _elements; |
|
66 |
public: |
|
67 |
typedef E EventType; |
|
68 |
Content(Instance& instance) : _instance(instance), _elements(0) {} |
|
69 |
bool process() { |
|
70 |
_elements = (u4)(_instance.*func)(); |
|
71 |
return true; |
|
50113 | 72 |
} |
58863 | 73 |
u4 elements() const { return _elements; } |
74 |
}; |
|
50113 | 75 |
|
58863 | 76 |
template <typename Content> |
77 |
class WriteContent : public StackObj { |
|
78 |
protected: |
|
79 |
const JfrTicks _start_time; |
|
80 |
JfrTicks _end_time; |
|
81 |
JfrChunkWriter& _cw; |
|
82 |
Content& _content; |
|
83 |
const int64_t _start_offset; |
|
50113 | 84 |
public: |
58863 | 85 |
typedef typename Content::EventType EventType; |
50113 | 86 |
|
58863 | 87 |
WriteContent(JfrChunkWriter& cw, Content& content) : |
88 |
_start_time(JfrTicks::now()), |
|
89 |
_end_time(), |
|
90 |
_cw(cw), |
|
91 |
_content(content), |
|
92 |
_start_offset(_cw.current_offset()) { |
|
93 |
assert(_cw.is_valid(), "invariant"); |
|
94 |
} |
|
95 |
||
96 |
bool process() { |
|
97 |
// invocation |
|
98 |
_content.process(); |
|
99 |
_end_time = JfrTicks::now(); |
|
100 |
return 0 != _content.elements(); |
|
50113 | 101 |
} |
102 |
||
58863 | 103 |
const JfrTicks& start_time() const { |
104 |
return _start_time; |
|
105 |
} |
|
106 |
||
107 |
const JfrTicks& end_time() const { |
|
108 |
return _end_time; |
|
109 |
} |
|
110 |
||
111 |
int64_t start_offset() const { |
|
112 |
return _start_offset; |
|
113 |
} |
|
114 |
||
115 |
int64_t end_offset() const { |
|
116 |
return current_offset(); |
|
117 |
} |
|
118 |
||
119 |
int64_t current_offset() const { |
|
120 |
return _cw.current_offset(); |
|
121 |
} |
|
122 |
||
123 |
u4 elements() const { |
|
124 |
return (u4) _content.elements(); |
|
50113 | 125 |
} |
58863 | 126 |
|
127 |
u4 size() const { |
|
128 |
return (u4)(end_offset() - start_offset()); |
|
129 |
} |
|
130 |
||
131 |
static bool is_event_enabled() { |
|
132 |
return EventType::is_enabled(); |
|
133 |
} |
|
134 |
||
135 |
static u8 event_id() { |
|
136 |
return EventType::eventId; |
|
137 |
} |
|
138 |
||
139 |
void write_elements(int64_t offset) { |
|
140 |
_cw.write_padded_at_offset<u4>(elements(), offset); |
|
141 |
} |
|
142 |
||
143 |
void write_size() { |
|
144 |
_cw.write_padded_at_offset<u4>(size(), start_offset()); |
|
145 |
} |
|
146 |
||
147 |
void set_last_checkpoint() { |
|
148 |
_cw.set_last_checkpoint_offset(start_offset()); |
|
149 |
} |
|
150 |
||
151 |
void rewind() { |
|
152 |
_cw.seek(start_offset()); |
|
153 |
} |
|
50113 | 154 |
}; |
155 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
156 |
static int64_t write_checkpoint_event_prologue(JfrChunkWriter& cw, u8 type_id) { |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
157 |
const int64_t last_cp_offset = cw.last_checkpoint_offset(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
158 |
const int64_t delta_to_last_checkpoint = 0 == last_cp_offset ? 0 : last_cp_offset - cw.current_offset(); |
50113 | 159 |
cw.reserve(sizeof(u4)); |
160 |
cw.write<u8>(EVENT_CHECKPOINT); |
|
161 |
cw.write(JfrTicks::now()); |
|
58863 | 162 |
cw.write<u8>(0); // duration |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
163 |
cw.write(delta_to_last_checkpoint); |
58863 | 164 |
cw.write<u4>(GENERIC); // checkpoint type |
165 |
cw.write<u4>(1); // nof types in this checkpoint |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
166 |
cw.write(type_id); |
58863 | 167 |
return cw.reserve(sizeof(u4)); |
50113 | 168 |
} |
169 |
||
58863 | 170 |
template <typename Content> |
171 |
class WriteCheckpointEvent : public WriteContent<Content> { |
|
50113 | 172 |
private: |
58863 | 173 |
const u8 _type_id; |
50113 | 174 |
public: |
58863 | 175 |
WriteCheckpointEvent(JfrChunkWriter& cw, Content& content, u8 type_id) : |
176 |
WriteContent<Content>(cw, content), _type_id(type_id) {} |
|
177 |
||
50113 | 178 |
bool process() { |
58863 | 179 |
const int64_t num_elements_offset = write_checkpoint_event_prologue(this->_cw, _type_id); |
180 |
if (!WriteContent<Content>::process()) { |
|
50113 | 181 |
// nothing to do, rewind writer to start |
58863 | 182 |
this->rewind(); |
183 |
assert(this->current_offset() == this->start_offset(), "invariant"); |
|
184 |
return false; |
|
50113 | 185 |
} |
58863 | 186 |
assert(this->elements() > 0, "invariant"); |
187 |
assert(this->current_offset() > num_elements_offset, "invariant"); |
|
188 |
this->write_elements(num_elements_offset); |
|
189 |
this->write_size(); |
|
190 |
this->set_last_checkpoint(); |
|
50113 | 191 |
return true; |
192 |
} |
|
193 |
}; |
|
194 |
||
58863 | 195 |
template <typename Functor> |
196 |
static u4 invoke(Functor& f) { |
|
197 |
f.process(); |
|
198 |
return f.elements(); |
|
199 |
} |
|
200 |
||
201 |
template <typename Functor> |
|
202 |
static void write_flush_event(Functor& f) { |
|
203 |
if (Functor::is_event_enabled()) { |
|
204 |
typename Functor::EventType e(UNTIMED); |
|
205 |
e.set_starttime(f.start_time()); |
|
206 |
e.set_endtime(f.end_time()); |
|
207 |
e.set_flushId(flushpoint_id); |
|
208 |
e.set_elements(f.elements()); |
|
209 |
e.set_size(f.size()); |
|
210 |
e.commit(); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
template <typename Functor> |
|
215 |
static u4 invoke_with_flush_event(Functor& f) { |
|
216 |
const u4 elements = invoke(f); |
|
217 |
write_flush_event(f); |
|
218 |
return elements; |
|
219 |
} |
|
220 |
||
221 |
class StackTraceRepository : public StackObj { |
|
50113 | 222 |
private: |
58863 | 223 |
JfrStackTraceRepository& _repo; |
224 |
JfrChunkWriter& _cw; |
|
225 |
size_t _elements; |
|
226 |
bool _clear; |
|
227 |
||
50113 | 228 |
public: |
58863 | 229 |
typedef EventFlushStacktrace EventType; |
230 |
StackTraceRepository(JfrStackTraceRepository& repo, JfrChunkWriter& cw, bool clear) : |
|
231 |
_repo(repo), _cw(cw), _elements(0), _clear(clear) {} |
|
50113 | 232 |
bool process() { |
58863 | 233 |
_elements = _repo.write(_cw, _clear); |
50113 | 234 |
return true; |
235 |
} |
|
58863 | 236 |
size_t elements() const { return _elements; } |
237 |
void reset() { _elements = 0; } |
|
50113 | 238 |
}; |
239 |
||
58863 | 240 |
typedef WriteCheckpointEvent<StackTraceRepository> WriteStackTrace; |
241 |
||
242 |
static u4 flush_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter) { |
|
243 |
StackTraceRepository str(stack_trace_repo, chunkwriter, false); |
|
244 |
WriteStackTrace wst(chunkwriter, str, TYPE_STACKTRACE); |
|
245 |
return invoke_with_flush_event(wst); |
|
246 |
} |
|
247 |
||
248 |
static u4 write_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter, bool clear) { |
|
249 |
StackTraceRepository str(stack_trace_repo, chunkwriter, clear); |
|
250 |
WriteStackTrace wst(chunkwriter, str, TYPE_STACKTRACE); |
|
251 |
return invoke(wst); |
|
252 |
} |
|
253 |
||
254 |
typedef Content<EventFlushStorage, JfrStorage, &JfrStorage::write> Storage; |
|
255 |
typedef WriteContent<Storage> WriteStorage; |
|
256 |
||
257 |
static size_t flush_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) { |
|
258 |
assert(chunkwriter.is_valid(), "invariant"); |
|
259 |
Storage fsf(storage); |
|
260 |
WriteStorage fs(chunkwriter, fsf); |
|
261 |
return invoke_with_flush_event(fs); |
|
262 |
} |
|
263 |
||
264 |
static size_t write_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) { |
|
265 |
assert(chunkwriter.is_valid(), "invariant"); |
|
266 |
Storage fsf(storage); |
|
267 |
WriteStorage fs(chunkwriter, fsf); |
|
268 |
return invoke(fs); |
|
269 |
} |
|
270 |
||
271 |
typedef Content<EventFlushStringPool, JfrStringPool, &JfrStringPool::write> StringPool; |
|
272 |
typedef Content<EventFlushStringPool, JfrStringPool, &JfrStringPool::write_at_safepoint> StringPoolSafepoint; |
|
273 |
typedef WriteCheckpointEvent<StringPool> WriteStringPool; |
|
274 |
typedef WriteCheckpointEvent<StringPoolSafepoint> WriteStringPoolSafepoint; |
|
275 |
||
276 |
static u4 flush_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
277 |
StringPool sp(string_pool); |
|
278 |
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING); |
|
279 |
return invoke_with_flush_event(wsp); |
|
280 |
} |
|
281 |
||
282 |
static u4 write_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
283 |
StringPool sp(string_pool); |
|
284 |
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING); |
|
285 |
return invoke(wsp); |
|
286 |
} |
|
287 |
||
288 |
static u4 write_stringpool_safepoint(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
289 |
StringPoolSafepoint sps(string_pool); |
|
290 |
WriteStringPoolSafepoint wsps(chunkwriter, sps, TYPE_STRING); |
|
291 |
return invoke(wsps); |
|
292 |
} |
|
293 |
||
294 |
typedef Content<EventFlushTypeSet, JfrCheckpointManager, &JfrCheckpointManager::flush_type_set> FlushTypeSetFunctor; |
|
295 |
typedef WriteContent<FlushTypeSetFunctor> FlushTypeSet; |
|
296 |
||
297 |
static u4 flush_typeset(JfrCheckpointManager& checkpoint_manager, JfrChunkWriter& chunkwriter) { |
|
298 |
FlushTypeSetFunctor flush_type_set(checkpoint_manager); |
|
299 |
FlushTypeSet fts(chunkwriter, flush_type_set); |
|
300 |
return invoke_with_flush_event(fts); |
|
301 |
} |
|
302 |
||
303 |
class MetadataEvent : public StackObj { |
|
304 |
private: |
|
305 |
JfrChunkWriter& _cw; |
|
306 |
public: |
|
307 |
typedef EventFlushMetadata EventType; |
|
308 |
MetadataEvent(JfrChunkWriter& cw) : _cw(cw) {} |
|
309 |
bool process() { |
|
310 |
JfrMetadataEvent::write(_cw); |
|
311 |
return true; |
|
312 |
} |
|
313 |
size_t elements() const { return 1; } |
|
314 |
}; |
|
315 |
||
316 |
typedef WriteContent<MetadataEvent> WriteMetadata; |
|
317 |
||
318 |
static u4 flush_metadata(JfrChunkWriter& chunkwriter) { |
|
319 |
assert(chunkwriter.is_valid(), "invariant"); |
|
320 |
MetadataEvent me(chunkwriter); |
|
321 |
WriteMetadata wm(chunkwriter, me); |
|
322 |
return invoke_with_flush_event(wm); |
|
323 |
} |
|
324 |
||
325 |
static u4 write_metadata(JfrChunkWriter& chunkwriter) { |
|
326 |
assert(chunkwriter.is_valid(), "invariant"); |
|
327 |
MetadataEvent me(chunkwriter); |
|
328 |
WriteMetadata wm(chunkwriter, me); |
|
329 |
return invoke(wm); |
|
330 |
} |
|
331 |
||
50113 | 332 |
template <typename Instance, void(Instance::*func)()> |
333 |
class JfrVMOperation : public VM_Operation { |
|
334 |
private: |
|
335 |
Instance& _instance; |
|
336 |
public: |
|
337 |
JfrVMOperation(Instance& instance) : _instance(instance) {} |
|
338 |
void doit() { (_instance.*func)(); } |
|
339 |
VMOp_Type type() const { return VMOp_JFRCheckpoint; } |
|
340 |
}; |
|
341 |
||
58863 | 342 |
JfrRecorderService::JfrRecorderService() : |
343 |
_checkpoint_manager(JfrCheckpointManager::instance()), |
|
344 |
_chunkwriter(JfrRepository::chunkwriter()), |
|
345 |
_repository(JfrRepository::instance()), |
|
346 |
_stack_trace_repository(JfrStackTraceRepository::instance()), |
|
347 |
_storage(JfrStorage::instance()), |
|
348 |
_string_pool(JfrStringPool::instance()) {} |
|
50113 | 349 |
|
350 |
static bool recording = false; |
|
351 |
||
352 |
static void set_recording_state(bool is_recording) { |
|
353 |
OrderAccess::storestore(); |
|
354 |
recording = is_recording; |
|
355 |
} |
|
356 |
||
357 |
bool JfrRecorderService::is_recording() { |
|
358 |
return recording; |
|
359 |
} |
|
360 |
||
361 |
void JfrRecorderService::start() { |
|
58863 | 362 |
MutexLocker lock(JfrStream_lock); |
50113 | 363 |
log_debug(jfr, system)("Request to START recording"); |
364 |
assert(!is_recording(), "invariant"); |
|
365 |
clear(); |
|
366 |
set_recording_state(true); |
|
367 |
assert(is_recording(), "invariant"); |
|
368 |
open_new_chunk(); |
|
369 |
log_debug(jfr, system)("Recording STARTED"); |
|
370 |
} |
|
371 |
||
372 |
void JfrRecorderService::clear() { |
|
373 |
ResourceMark rm; |
|
374 |
HandleMark hm; |
|
375 |
pre_safepoint_clear(); |
|
376 |
invoke_safepoint_clear(); |
|
377 |
post_safepoint_clear(); |
|
378 |
} |
|
379 |
||
380 |
void JfrRecorderService::pre_safepoint_clear() { |
|
381 |
_string_pool.clear(); |
|
382 |
_storage.clear(); |
|
58863 | 383 |
_stack_trace_repository.clear(); |
50113 | 384 |
} |
385 |
||
386 |
void JfrRecorderService::invoke_safepoint_clear() { |
|
387 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_clear> safepoint_task(*this); |
|
388 |
VMThread::execute(&safepoint_task); |
|
389 |
} |
|
390 |
||
391 |
void JfrRecorderService::safepoint_clear() { |
|
392 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
393 |
_string_pool.clear(); |
|
394 |
_storage.clear(); |
|
395 |
_checkpoint_manager.shift_epoch(); |
|
58863 | 396 |
_chunkwriter.set_time_stamp(); |
397 |
_stack_trace_repository.clear(); |
|
50113 | 398 |
} |
399 |
||
400 |
void JfrRecorderService::post_safepoint_clear() { |
|
401 |
_checkpoint_manager.clear(); |
|
402 |
} |
|
403 |
||
58863 | 404 |
void JfrRecorderService::open_new_chunk(bool vm_error) { |
405 |
JfrChunkRotation::on_rotation(); |
|
406 |
const bool valid_chunk = _repository.open_chunk(vm_error); |
|
407 |
_storage.control().set_to_disk(valid_chunk); |
|
408 |
if (valid_chunk) { |
|
409 |
_checkpoint_manager.write_static_type_set_and_threads(); |
|
410 |
} |
|
411 |
} |
|
412 |
||
50113 | 413 |
static void stop() { |
414 |
assert(JfrRecorderService::is_recording(), "invariant"); |
|
415 |
log_debug(jfr, system)("Recording STOPPED"); |
|
416 |
set_recording_state(false); |
|
417 |
assert(!JfrRecorderService::is_recording(), "invariant"); |
|
418 |
} |
|
419 |
||
58863 | 420 |
void JfrRecorderService::prepare_for_vm_error_rotation() { |
421 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
422 |
if (!_chunkwriter.is_valid()) { |
|
423 |
open_new_chunk(true); |
|
424 |
} |
|
425 |
_checkpoint_manager.register_service_thread(Thread::current()); |
|
426 |
} |
|
427 |
||
428 |
void JfrRecorderService::vm_error_rotation() { |
|
429 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
430 |
if (_chunkwriter.is_valid()) { |
|
431 |
Thread* const t = Thread::current(); |
|
432 |
_storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t); |
|
59226 | 433 |
_chunkwriter.mark_chunk_final(); |
58863 | 434 |
invoke_flush(); |
435 |
_chunkwriter.set_time_stamp(); |
|
436 |
_repository.close_chunk(); |
|
437 |
assert(!_chunkwriter.is_valid(), "invariant"); |
|
438 |
_repository.on_vm_error(); |
|
439 |
} |
|
440 |
} |
|
441 |
||
50113 | 442 |
void JfrRecorderService::rotate(int msgs) { |
58863 | 443 |
assert(!JfrStream_lock->owned_by_self(), "invariant"); |
444 |
MutexLocker lock(JfrStream_lock); |
|
50113 | 445 |
static bool vm_error = false; |
446 |
if (msgs & MSGBIT(MSG_VM_ERROR)) { |
|
447 |
vm_error = true; |
|
448 |
prepare_for_vm_error_rotation(); |
|
449 |
} |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
450 |
if (!_storage.control().to_disk()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
451 |
in_memory_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
452 |
} else if (vm_error) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
453 |
vm_error_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
454 |
} else { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
455 |
chunk_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
456 |
} |
50113 | 457 |
if (msgs & (MSGBIT(MSG_STOP))) { |
458 |
stop(); |
|
459 |
} |
|
460 |
} |
|
461 |
||
462 |
void JfrRecorderService::in_memory_rotation() { |
|
58863 | 463 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
50113 | 464 |
// currently running an in-memory recording |
58863 | 465 |
assert(!_storage.control().to_disk(), "invariant"); |
50113 | 466 |
open_new_chunk(); |
467 |
if (_chunkwriter.is_valid()) { |
|
468 |
// dump all in-memory buffer data to the newly created chunk |
|
58863 | 469 |
write_storage(_storage, _chunkwriter); |
50113 | 470 |
} |
471 |
} |
|
472 |
||
473 |
void JfrRecorderService::chunk_rotation() { |
|
58863 | 474 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
50113 | 475 |
finalize_current_chunk(); |
476 |
open_new_chunk(); |
|
477 |
} |
|
478 |
||
479 |
void JfrRecorderService::finalize_current_chunk() { |
|
480 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
481 |
write(); |
|
482 |
} |
|
483 |
||
484 |
void JfrRecorderService::write() { |
|
485 |
ResourceMark rm; |
|
486 |
HandleMark hm; |
|
487 |
pre_safepoint_write(); |
|
488 |
invoke_safepoint_write(); |
|
489 |
post_safepoint_write(); |
|
490 |
} |
|
491 |
||
492 |
void JfrRecorderService::pre_safepoint_write() { |
|
493 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
494 |
if (LeakProfiler::is_running()) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
495 |
// Exclusive access to the object sampler instance. |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
496 |
// The sampler is released (unlocked) later in post_safepoint_write. |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
497 |
ObjectSampleCheckpoint::on_rotation(ObjectSampler::acquire(), _stack_trace_repository); |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
498 |
} |
58863 | 499 |
if (_string_pool.is_modified()) { |
500 |
write_stringpool(_string_pool, _chunkwriter); |
|
501 |
} |
|
502 |
write_storage(_storage, _chunkwriter); |
|
503 |
if (_stack_trace_repository.is_modified()) { |
|
504 |
write_stacktrace(_stack_trace_repository, _chunkwriter, false); |
|
505 |
} |
|
50113 | 506 |
} |
507 |
||
508 |
void JfrRecorderService::invoke_safepoint_write() { |
|
509 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_write> safepoint_task(*this); |
|
510 |
VMThread::execute(&safepoint_task); |
|
511 |
} |
|
512 |
||
513 |
void JfrRecorderService::safepoint_write() { |
|
514 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
58863 | 515 |
if (_string_pool.is_modified()) { |
516 |
write_stringpool_safepoint(_string_pool, _chunkwriter); |
|
517 |
} |
|
518 |
_checkpoint_manager.on_rotation(); |
|
50113 | 519 |
_storage.write_at_safepoint(); |
520 |
_checkpoint_manager.shift_epoch(); |
|
58863 | 521 |
_chunkwriter.set_time_stamp(); |
522 |
write_stacktrace(_stack_trace_repository, _chunkwriter, true); |
|
50113 | 523 |
} |
524 |
||
525 |
void JfrRecorderService::post_safepoint_write() { |
|
526 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
527 |
// During the safepoint tasks just completed, the system transitioned to a new epoch. |
|
528 |
// Type tagging is epoch relative which entails we are able to write out the |
|
529 |
// already tagged artifacts for the previous epoch. We can accomplish this concurrently |
|
530 |
// with threads now tagging artifacts in relation to the new, now updated, epoch and remain outside of a safepoint. |
|
531 |
_checkpoint_manager.write_type_set(); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
532 |
if (LeakProfiler::is_running()) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
533 |
// The object sampler instance was exclusively acquired and locked in pre_safepoint_write. |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
534 |
// Note: There is a dependency on write_type_set() above, ensure the release is subsequent. |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
535 |
ObjectSampler::release(); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
536 |
} |
50113 | 537 |
// serialize the metadata descriptor event and close out the chunk |
58863 | 538 |
write_metadata(_chunkwriter); |
539 |
_repository.close_chunk(); |
|
540 |
} |
|
541 |
||
542 |
static JfrBuffer* thread_local_buffer(Thread* t) { |
|
543 |
assert(t != NULL, "invariant"); |
|
544 |
return t->jfr_thread_local()->native_buffer(); |
|
50113 | 545 |
} |
546 |
||
58863 | 547 |
static void reset_buffer(JfrBuffer* buffer, Thread* t) { |
548 |
assert(buffer != NULL, "invariant"); |
|
549 |
assert(t != NULL, "invariant"); |
|
550 |
assert(buffer == thread_local_buffer(t), "invariant"); |
|
551 |
buffer->set_pos(const_cast<u1*>(buffer->top())); |
|
552 |
} |
|
553 |
||
554 |
static void reset_thread_local_buffer(Thread* t) { |
|
555 |
reset_buffer(thread_local_buffer(t), t); |
|
556 |
} |
|
557 |
||
558 |
static void write_thread_local_buffer(JfrChunkWriter& chunkwriter, Thread* t) { |
|
559 |
JfrBuffer * const buffer = thread_local_buffer(t); |
|
560 |
assert(buffer != NULL, "invariant"); |
|
561 |
if (!buffer->empty()) { |
|
562 |
chunkwriter.write_unbuffered(buffer->top(), buffer->pos() - buffer->top()); |
|
563 |
reset_buffer(buffer, t); |
|
50113 | 564 |
} |
565 |
} |
|
566 |
||
58863 | 567 |
size_t JfrRecorderService::flush() { |
568 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
569 |
size_t total_elements = flush_metadata(_chunkwriter); |
|
570 |
const size_t storage_elements = flush_storage(_storage, _chunkwriter); |
|
571 |
if (0 == storage_elements) { |
|
572 |
return total_elements; |
|
573 |
} |
|
574 |
total_elements += storage_elements; |
|
575 |
if (_string_pool.is_modified()) { |
|
576 |
total_elements += flush_stringpool(_string_pool, _chunkwriter); |
|
577 |
} |
|
578 |
if (_stack_trace_repository.is_modified()) { |
|
579 |
total_elements += flush_stacktrace(_stack_trace_repository, _chunkwriter); |
|
580 |
} |
|
581 |
if (_checkpoint_manager.is_type_set_required()) { |
|
582 |
total_elements += flush_typeset(_checkpoint_manager, _chunkwriter); |
|
583 |
} else if (_checkpoint_manager.is_static_type_set_required()) { |
|
584 |
// don't tally this, it is only in order to flush the waiting constants |
|
585 |
_checkpoint_manager.flush_static_type_set(); |
|
586 |
} |
|
587 |
return total_elements; |
|
588 |
} |
|
589 |
||
590 |
typedef Content<EventFlush, JfrRecorderService, &JfrRecorderService::flush> FlushFunctor; |
|
591 |
typedef WriteContent<FlushFunctor> Flush; |
|
592 |
||
593 |
void JfrRecorderService::invoke_flush() { |
|
594 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
50113 | 595 |
assert(_chunkwriter.is_valid(), "invariant"); |
58863 | 596 |
Thread* const t = Thread::current(); |
597 |
ResourceMark rm(t); |
|
598 |
HandleMark hm(t); |
|
599 |
++flushpoint_id; |
|
600 |
reset_thread_local_buffer(t); |
|
601 |
FlushFunctor flushpoint(*this); |
|
602 |
Flush fl(_chunkwriter, flushpoint); |
|
603 |
invoke_with_flush_event(fl); |
|
604 |
write_thread_local_buffer(_chunkwriter, t); |
|
605 |
_repository.flush_chunk(); |
|
606 |
} |
|
607 |
||
608 |
void JfrRecorderService::flushpoint() { |
|
609 |
MutexLocker lock(JfrStream_lock); |
|
610 |
invoke_flush(); |
|
50113 | 611 |
} |
612 |
||
613 |
void JfrRecorderService::process_full_buffers() { |
|
614 |
if (_chunkwriter.is_valid()) { |
|
615 |
_storage.write_full(); |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
void JfrRecorderService::scavenge() { |
|
620 |
_storage.scavenge(); |
|
621 |
} |
|
622 |
||
623 |
void JfrRecorderService::evaluate_chunk_size_for_rotation() { |
|
53014
339d2fbe8675
8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
52877
diff
changeset
|
624 |
JfrChunkRotation::evaluate(_chunkwriter); |
50113 | 625 |
} |