author | mgronlun |
Sun, 13 Oct 2019 16:46:15 +0200 | |
branch | JEP-349-branch |
changeset 58578 | 7b89c53db169 |
parent 58567 | e77a97d0edbb |
child 58823 | 6a21dba79b81 |
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" |
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/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"); |
|
58164 | 62 |
const void* const current = *dest; |
50113 | 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)()> |
58068 | 140 |
class Content { |
57360 | 141 |
private: |
142 |
Instance& _instance; |
|
143 |
u4 _elements; |
|
144 |
public: |
|
145 |
typedef E EventType; |
|
58068 | 146 |
Content(Instance& instance) : _instance(instance), _elements(0) {} |
57360 | 147 |
bool process() { |
148 |
_elements = (u4)(_instance.*func)(); |
|
149 |
return true; |
|
150 |
} |
|
151 |
u4 elements() const { return _elements; } |
|
152 |
}; |
|
153 |
||
58068 | 154 |
template <typename Content> |
155 |
class WriteContent : public StackObj { |
|
57360 | 156 |
protected: |
157 |
const JfrTicks _start_time; |
|
158 |
JfrTicks _end_time; |
|
159 |
JfrChunkWriter& _cw; |
|
58068 | 160 |
Content& _content; |
57360 | 161 |
const int64_t _start_offset; |
162 |
public: |
|
58068 | 163 |
typedef typename Content::EventType EventType; |
57360 | 164 |
|
58068 | 165 |
WriteContent(JfrChunkWriter& cw, Content& content) : |
57360 | 166 |
_start_time(JfrTicks::now()), |
167 |
_end_time(), |
|
168 |
_cw(cw), |
|
58068 | 169 |
_content(content), |
57360 | 170 |
_start_offset(_cw.current_offset()) { |
171 |
assert(_cw.is_valid(), "invariant"); |
|
172 |
} |
|
173 |
||
174 |
bool process() { |
|
175 |
// invocation |
|
58068 | 176 |
_content.process(); |
57360 | 177 |
_end_time = JfrTicks::now(); |
58068 | 178 |
return 0 != _content.elements(); |
57360 | 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 { |
|
58068 | 202 |
return (u4) _content.elements(); |
57360 | 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 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
const int64_t delta_to_last_checkpoint = 0 == last_cp_offset ? 0 : last_cp_offset - cw.current_offset(); |
50113 | 237 |
cw.reserve(sizeof(u4)); |
238 |
cw.write<u8>(EVENT_CHECKPOINT); |
|
239 |
cw.write(JfrTicks::now()); |
|
58167 | 240 |
cw.write<u8>(0); // duration |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
241 |
cw.write(delta_to_last_checkpoint); |
58167 | 242 |
cw.write<u4>(GENERIC); // checkpoint type |
243 |
cw.write<u4>(1); // nof types in this checkpoint |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53014
diff
changeset
|
244 |
cw.write(type_id); |
58167 | 245 |
return cw.reserve(sizeof(u4)); |
50113 | 246 |
} |
247 |
||
58068 | 248 |
template <typename Content> |
249 |
class WriteCheckpointEvent : public WriteContent<Content> { |
|
50113 | 250 |
private: |
57360 | 251 |
const u8 _type_id; |
50113 | 252 |
public: |
58068 | 253 |
WriteCheckpointEvent(JfrChunkWriter& cw, Content& content, u8 type_id) : |
254 |
WriteContent<Content>(cw, content), _type_id(type_id) {} |
|
57360 | 255 |
|
50113 | 256 |
bool process() { |
57360 | 257 |
const int64_t num_elements_offset = write_checkpoint_event_prologue(this->_cw, _type_id); |
58068 | 258 |
if (!WriteContent<Content>::process()) { |
50113 | 259 |
// nothing to do, rewind writer to start |
57360 | 260 |
this->rewind(); |
261 |
assert(this->current_offset() == this->start_offset(), "invariant"); |
|
262 |
return false; |
|
50113 | 263 |
} |
57360 | 264 |
assert(this->elements() > 0, "invariant"); |
265 |
assert(this->current_offset() > num_elements_offset, "invariant"); |
|
266 |
this->write_elements(num_elements_offset); |
|
267 |
this->write_size(); |
|
268 |
this->set_last_checkpoint(); |
|
50113 | 269 |
return true; |
270 |
} |
|
271 |
}; |
|
272 |
||
57360 | 273 |
template <typename Functor> |
58068 | 274 |
static u4 invoke(Functor& f) { |
275 |
f.process(); |
|
276 |
return f.elements(); |
|
277 |
} |
|
278 |
||
279 |
template <typename Functor> |
|
57360 | 280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
e.commit(); |
50113 | 289 |
} |
57360 | 290 |
} |
291 |
||
292 |
template <typename Functor> |
|
293 |
static u4 invoke_with_flush_event(Functor& f) { |
|
294 |
const u4 elements = invoke(f); |
|
57872 | 295 |
write_flush_event(f); |
57360 | 296 |
return elements; |
297 |
} |
|
50113 | 298 |
|
58068 | 299 |
class StackTraceRepository : public StackObj { |
50113 | 300 |
private: |
58068 | 301 |
JfrStackTraceRepository& _repo; |
302 |
JfrChunkWriter& _cw; |
|
303 |
size_t _elements; |
|
304 |
bool _clear; |
|
305 |
||
50113 | 306 |
public: |
58068 | 307 |
typedef EventFlushStacktrace EventType; |
308 |
StackTraceRepository(JfrStackTraceRepository& repo, JfrChunkWriter& cw, bool clear) : |
|
309 |
_repo(repo), _cw(cw), _elements(0), _clear(clear) {} |
|
50113 | 310 |
bool process() { |
58068 | 311 |
_elements = _repo.write(_cw, _clear); |
50113 | 312 |
return true; |
313 |
} |
|
58068 | 314 |
size_t elements() const { return _elements; } |
315 |
void reset() { _elements = 0; } |
|
50113 | 316 |
}; |
317 |
||
58068 | 318 |
typedef WriteCheckpointEvent<StackTraceRepository> WriteStackTrace; |
319 |
||
320 |
static u4 flush_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter) { |
|
321 |
StackTraceRepository str(stack_trace_repo, chunkwriter, false); |
|
322 |
WriteStackTrace wst(chunkwriter, str, TYPE_STACKTRACE); |
|
323 |
return invoke_with_flush_event(wst); |
|
324 |
} |
|
325 |
||
326 |
static u4 write_stacktrace(JfrStackTraceRepository& stack_trace_repo, JfrChunkWriter& chunkwriter, bool clear) { |
|
327 |
StackTraceRepository str(stack_trace_repo, chunkwriter, clear); |
|
328 |
WriteStackTrace wst(chunkwriter, str, TYPE_STACKTRACE); |
|
329 |
return invoke(wst); |
|
330 |
} |
|
331 |
||
332 |
typedef Content<EventFlushStorage, JfrStorage, &JfrStorage::write> Storage; |
|
333 |
typedef WriteContent<Storage> WriteStorage; |
|
334 |
||
335 |
static size_t flush_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) { |
|
336 |
assert(chunkwriter.is_valid(), "invariant"); |
|
337 |
Storage fsf(storage); |
|
338 |
WriteStorage fs(chunkwriter, fsf); |
|
339 |
return invoke_with_flush_event(fs); |
|
340 |
} |
|
341 |
||
342 |
static size_t write_storage(JfrStorage& storage, JfrChunkWriter& chunkwriter) { |
|
343 |
assert(chunkwriter.is_valid(), "invariant"); |
|
344 |
Storage fsf(storage); |
|
345 |
WriteStorage fs(chunkwriter, fsf); |
|
346 |
return invoke(fs); |
|
347 |
} |
|
348 |
||
349 |
typedef Content<EventFlushStringPool, JfrStringPool, &JfrStringPool::write> StringPool; |
|
350 |
typedef Content<EventFlushStringPool, JfrStringPool, &JfrStringPool::write_at_safepoint> StringPoolSafepoint; |
|
351 |
typedef WriteCheckpointEvent<StringPool> WriteStringPool; |
|
352 |
typedef WriteCheckpointEvent<StringPoolSafepoint> WriteStringPoolSafepoint; |
|
353 |
||
354 |
static u4 flush_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
355 |
StringPool sp(string_pool); |
|
356 |
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING); |
|
357 |
return invoke_with_flush_event(wsp); |
|
358 |
} |
|
359 |
||
360 |
static u4 write_stringpool(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
361 |
StringPool sp(string_pool); |
|
362 |
WriteStringPool wsp(chunkwriter, sp, TYPE_STRING); |
|
363 |
return invoke(wsp); |
|
364 |
} |
|
365 |
||
366 |
static u4 write_stringpool_safepoint(JfrStringPool& string_pool, JfrChunkWriter& chunkwriter) { |
|
367 |
StringPoolSafepoint sps(string_pool); |
|
368 |
WriteStringPoolSafepoint wsps(chunkwriter, sps, TYPE_STRING); |
|
369 |
return invoke(wsps); |
|
370 |
} |
|
371 |
||
372 |
typedef Content<EventFlushTypeSet, JfrCheckpointManager, &JfrCheckpointManager::flush_type_set> FlushTypeSetFunctor; |
|
373 |
typedef WriteContent<FlushTypeSetFunctor> FlushTypeSet; |
|
374 |
||
375 |
static u4 flush_typeset(JfrCheckpointManager& checkpoint_manager, JfrChunkWriter& chunkwriter) { |
|
376 |
FlushTypeSetFunctor flush_type_set(checkpoint_manager); |
|
377 |
FlushTypeSet fts(chunkwriter, flush_type_set); |
|
378 |
return invoke_with_flush_event(fts); |
|
379 |
} |
|
380 |
||
381 |
class MetadataEvent : public StackObj { |
|
382 |
private: |
|
383 |
JfrChunkWriter& _cw; |
|
384 |
public: |
|
385 |
typedef EventFlushMetadata EventType; |
|
386 |
MetadataEvent(JfrChunkWriter& cw) : _cw(cw) {} |
|
387 |
bool process() { |
|
388 |
JfrMetadataEvent::write(_cw); |
|
389 |
return true; |
|
390 |
} |
|
391 |
size_t elements() const { return 1; } |
|
392 |
}; |
|
393 |
||
394 |
typedef WriteContent<MetadataEvent> WriteMetadata; |
|
395 |
||
396 |
static u4 flush_metadata(JfrChunkWriter& chunkwriter) { |
|
397 |
assert(chunkwriter.is_valid(), "invariant"); |
|
398 |
MetadataEvent me(chunkwriter); |
|
399 |
WriteMetadata wm(chunkwriter, me); |
|
400 |
return invoke_with_flush_event(wm); |
|
401 |
} |
|
402 |
||
403 |
static u4 write_metadata(JfrChunkWriter& chunkwriter) { |
|
404 |
assert(chunkwriter.is_valid(), "invariant"); |
|
405 |
MetadataEvent me(chunkwriter); |
|
406 |
WriteMetadata wm(chunkwriter, me); |
|
407 |
return invoke(wm); |
|
408 |
} |
|
409 |
||
50113 | 410 |
template <typename Instance, void(Instance::*func)()> |
411 |
class JfrVMOperation : public VM_Operation { |
|
412 |
private: |
|
413 |
Instance& _instance; |
|
414 |
public: |
|
415 |
JfrVMOperation(Instance& instance) : _instance(instance) {} |
|
416 |
void doit() { (_instance.*func)(); } |
|
417 |
VMOp_Type type() const { return VMOp_JFRCheckpoint; } |
|
418 |
Mode evaluation_mode() const { return _safepoint; } // default |
|
419 |
}; |
|
420 |
||
58068 | 421 |
JfrRecorderService::JfrRecorderService() : |
422 |
_checkpoint_manager(JfrCheckpointManager::instance()), |
|
423 |
_chunkwriter(JfrRepository::chunkwriter()), |
|
424 |
_repository(JfrRepository::instance()), |
|
425 |
_stack_trace_repository(JfrStackTraceRepository::instance()), |
|
426 |
_storage(JfrStorage::instance()), |
|
427 |
_string_pool(JfrStringPool::instance()) {} |
|
50113 | 428 |
|
429 |
static bool recording = false; |
|
430 |
||
431 |
static void set_recording_state(bool is_recording) { |
|
432 |
OrderAccess::storestore(); |
|
433 |
recording = is_recording; |
|
434 |
} |
|
435 |
||
436 |
bool JfrRecorderService::is_recording() { |
|
437 |
return recording; |
|
438 |
} |
|
439 |
||
440 |
void JfrRecorderService::start() { |
|
441 |
RotationLock rl(Thread::current()); |
|
442 |
if (rl.not_acquired()) { |
|
443 |
return; |
|
444 |
} |
|
445 |
log_debug(jfr, system)("Request to START recording"); |
|
446 |
assert(!is_recording(), "invariant"); |
|
447 |
clear(); |
|
448 |
set_recording_state(true); |
|
449 |
assert(is_recording(), "invariant"); |
|
450 |
open_new_chunk(); |
|
451 |
log_debug(jfr, system)("Recording STARTED"); |
|
452 |
} |
|
453 |
||
454 |
void JfrRecorderService::clear() { |
|
455 |
ResourceMark rm; |
|
456 |
HandleMark hm; |
|
457 |
pre_safepoint_clear(); |
|
458 |
invoke_safepoint_clear(); |
|
459 |
post_safepoint_clear(); |
|
460 |
} |
|
461 |
||
462 |
void JfrRecorderService::pre_safepoint_clear() { |
|
463 |
_stack_trace_repository.clear(); |
|
464 |
_string_pool.clear(); |
|
465 |
_storage.clear(); |
|
466 |
} |
|
467 |
||
468 |
void JfrRecorderService::invoke_safepoint_clear() { |
|
469 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_clear> safepoint_task(*this); |
|
470 |
VMThread::execute(&safepoint_task); |
|
471 |
} |
|
472 |
||
473 |
void JfrRecorderService::safepoint_clear() { |
|
474 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
475 |
_stack_trace_repository.clear(); |
|
476 |
_string_pool.clear(); |
|
477 |
_storage.clear(); |
|
478 |
_checkpoint_manager.shift_epoch(); |
|
57887 | 479 |
_chunkwriter.set_time_stamp(); |
50113 | 480 |
} |
481 |
||
482 |
void JfrRecorderService::post_safepoint_clear() { |
|
483 |
_checkpoint_manager.clear(); |
|
484 |
} |
|
485 |
||
58068 | 486 |
void JfrRecorderService::open_new_chunk(bool vm_error) { |
487 |
JfrChunkRotation::on_rotation(); |
|
488 |
const bool valid_chunk = _repository.open_chunk(vm_error); |
|
489 |
_storage.control().set_to_disk(valid_chunk); |
|
490 |
if (valid_chunk) { |
|
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
491 |
_checkpoint_manager.write_static_type_set_and_threads(); |
58068 | 492 |
} |
493 |
} |
|
494 |
||
50113 | 495 |
static void stop() { |
496 |
assert(JfrRecorderService::is_recording(), "invariant"); |
|
497 |
log_debug(jfr, system)("Recording STOPPED"); |
|
498 |
set_recording_state(false); |
|
499 |
assert(!JfrRecorderService::is_recording(), "invariant"); |
|
500 |
} |
|
501 |
||
58068 | 502 |
void JfrRecorderService::prepare_for_vm_error_rotation() { |
503 |
if (!_chunkwriter.is_valid()) { |
|
504 |
open_new_chunk(true); |
|
505 |
} |
|
506 |
_checkpoint_manager.register_service_thread(Thread::current()); |
|
507 |
} |
|
508 |
||
509 |
void JfrRecorderService::vm_error_rotation() { |
|
510 |
if (_chunkwriter.is_valid()) { |
|
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
511 |
Thread* const t = Thread::current(); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
512 |
_storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
513 |
invoke_flush(t); |
58068 | 514 |
_chunkwriter.set_time_stamp(); |
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
515 |
_repository.close_chunk(); |
58068 | 516 |
assert(!_chunkwriter.is_valid(), "invariant"); |
517 |
_repository.on_vm_error(); |
|
518 |
} |
|
519 |
} |
|
520 |
||
50113 | 521 |
void JfrRecorderService::rotate(int msgs) { |
522 |
RotationLock rl(Thread::current()); |
|
523 |
if (rl.not_acquired()) { |
|
524 |
return; |
|
525 |
} |
|
526 |
static bool vm_error = false; |
|
527 |
if (msgs & MSGBIT(MSG_VM_ERROR)) { |
|
528 |
vm_error = true; |
|
529 |
prepare_for_vm_error_rotation(); |
|
530 |
} |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
531 |
if (!_storage.control().to_disk()) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
532 |
in_memory_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
533 |
} else if (vm_error) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
534 |
vm_error_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
535 |
} else { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
536 |
chunk_rotation(); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
55571
diff
changeset
|
537 |
} |
50113 | 538 |
if (msgs & (MSGBIT(MSG_STOP))) { |
539 |
stop(); |
|
540 |
} |
|
541 |
} |
|
542 |
||
543 |
void JfrRecorderService::in_memory_rotation() { |
|
544 |
// currently running an in-memory recording |
|
57360 | 545 |
assert(!_storage.control().to_disk(), "invariant"); |
50113 | 546 |
open_new_chunk(); |
547 |
if (_chunkwriter.is_valid()) { |
|
548 |
// dump all in-memory buffer data to the newly created chunk |
|
58068 | 549 |
write_storage(_storage, _chunkwriter); |
50113 | 550 |
} |
551 |
} |
|
552 |
||
553 |
void JfrRecorderService::chunk_rotation() { |
|
554 |
finalize_current_chunk(); |
|
555 |
open_new_chunk(); |
|
556 |
} |
|
557 |
||
558 |
void JfrRecorderService::finalize_current_chunk() { |
|
559 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
560 |
write(); |
|
561 |
} |
|
562 |
||
563 |
void JfrRecorderService::write() { |
|
564 |
ResourceMark rm; |
|
565 |
HandleMark hm; |
|
566 |
pre_safepoint_write(); |
|
567 |
invoke_safepoint_write(); |
|
568 |
post_safepoint_write(); |
|
569 |
} |
|
570 |
||
571 |
void JfrRecorderService::pre_safepoint_write() { |
|
572 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
58068 | 573 |
if (_stack_trace_repository.is_modified()) { |
574 |
write_stacktrace(_stack_trace_repository, _chunkwriter, false); |
|
575 |
} |
|
576 |
if (_string_pool.is_modified()) { |
|
577 |
write_stringpool(_string_pool, _chunkwriter); |
|
578 |
} |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
579 |
if (LeakProfiler::is_running()) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
580 |
// 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
|
581 |
// 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
|
582 |
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
|
583 |
} |
58068 | 584 |
write_storage(_storage, _chunkwriter); |
50113 | 585 |
} |
586 |
||
587 |
void JfrRecorderService::invoke_safepoint_write() { |
|
588 |
JfrVMOperation<JfrRecorderService, &JfrRecorderService::safepoint_write> safepoint_task(*this); |
|
589 |
VMThread::execute(&safepoint_task); |
|
590 |
} |
|
591 |
||
592 |
void JfrRecorderService::safepoint_write() { |
|
593 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
58068 | 594 |
write_stacktrace(_stack_trace_repository, _chunkwriter, true); |
595 |
if (_string_pool.is_modified()) { |
|
596 |
write_stringpool_safepoint(_string_pool, _chunkwriter); |
|
597 |
} |
|
50113 | 598 |
_storage.write_at_safepoint(); |
58184 | 599 |
_checkpoint_manager.on_rotation(); |
58068 | 600 |
_chunkwriter.set_time_stamp(); |
50113 | 601 |
} |
602 |
||
603 |
void JfrRecorderService::post_safepoint_write() { |
|
604 |
assert(_chunkwriter.is_valid(), "invariant"); |
|
605 |
// During the safepoint tasks just completed, the system transitioned to a new epoch. |
|
606 |
// Type tagging is epoch relative which entails we are able to write out the |
|
607 |
// already tagged artifacts for the previous epoch. We can accomplish this concurrently |
|
608 |
// with threads now tagging artifacts in relation to the new, now updated, epoch and remain outside of a safepoint. |
|
609 |
_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
|
610 |
if (LeakProfiler::is_running()) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
611 |
// 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
|
612 |
// 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
|
613 |
ObjectSampler::release(); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
54623
diff
changeset
|
614 |
} |
50113 | 615 |
// serialize the metadata descriptor event and close out the chunk |
58068 | 616 |
write_metadata(_chunkwriter); |
617 |
_repository.close_chunk(); |
|
50113 | 618 |
} |
619 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
620 |
static JfrBuffer* thread_local_buffer(Thread* t) { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
621 |
assert(t != NULL, "invariant"); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
622 |
return t->jfr_thread_local()->native_buffer(); |
57360 | 623 |
} |
624 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
625 |
static void reset_buffer(JfrBuffer* buffer, Thread* t) { |
57360 | 626 |
assert(buffer != NULL, "invariant"); |
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
627 |
assert(t != NULL, "invariant"); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
628 |
assert(buffer == thread_local_buffer(t), "invariant"); |
57360 | 629 |
buffer->set_pos(const_cast<u1*>(buffer->top())); |
630 |
} |
|
631 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
632 |
static void reset_thread_local_buffer(Thread* t) { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
633 |
reset_buffer(thread_local_buffer(t), t); |
57360 | 634 |
} |
635 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
636 |
static void write_thread_local_buffer(JfrChunkWriter& chunkwriter, Thread* t) { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
637 |
JfrBuffer * const buffer = thread_local_buffer(t); |
57360 | 638 |
assert(buffer != NULL, "invariant"); |
639 |
if (!buffer->empty()) { |
|
640 |
chunkwriter.write_unbuffered(buffer->top(), buffer->pos() - buffer->top()); |
|
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
641 |
reset_buffer(buffer, t); |
57360 | 642 |
} |
50113 | 643 |
} |
644 |
||
57360 | 645 |
size_t JfrRecorderService::flush() { |
58567
e77a97d0edbb
Metadata races (TestStart) and thread exclusion inclusion (TestRecursive)
mgronlun
parents:
58187
diff
changeset
|
646 |
size_t total_elements = flush_metadata(_chunkwriter); |
57360 | 647 |
const size_t storage_elements = flush_storage(_storage, _chunkwriter); |
648 |
if (0 == storage_elements) { |
|
649 |
return total_elements; |
|
50113 | 650 |
} |
57360 | 651 |
total_elements += storage_elements; |
57872 | 652 |
if (_stack_trace_repository.is_modified()) { |
653 |
total_elements += flush_stacktrace(_stack_trace_repository, _chunkwriter); |
|
654 |
} |
|
655 |
if (_string_pool.is_modified()) { |
|
57360 | 656 |
total_elements += flush_stringpool(_string_pool, _chunkwriter); |
657 |
} |
|
57934 | 658 |
if (_checkpoint_manager.is_type_set_required()) { |
57873 | 659 |
total_elements += flush_typeset(_checkpoint_manager, _chunkwriter); |
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
660 |
} else if (_checkpoint_manager.is_static_type_set_required()) { |
57934 | 661 |
// don't tally this, it is only in order to flush the waiting constants |
58187
8994744e221c
renames and restructuring of JfrCheckpointManager
mgronlun
parents:
58184
diff
changeset
|
662 |
_checkpoint_manager.flush_static_type_set(); |
57873 | 663 |
} |
57360 | 664 |
return total_elements; |
50113 | 665 |
} |
666 |
||
58068 | 667 |
typedef Content<EventFlush, JfrRecorderService, &JfrRecorderService::flush> FlushFunctor; |
668 |
typedef WriteContent<FlushFunctor> Flush; |
|
669 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
670 |
void JfrRecorderService::invoke_flush(Thread* t) { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
671 |
assert(t != NULL, "invariant"); |
50113 | 672 |
assert(_chunkwriter.is_valid(), "invariant"); |
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
673 |
ResourceMark rm(t); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
674 |
HandleMark hm(t); |
57360 | 675 |
++flushpoint_id; |
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
676 |
reset_thread_local_buffer(t); |
57360 | 677 |
FlushFunctor flushpoint(*this); |
678 |
Flush fl(_chunkwriter, flushpoint); |
|
679 |
invoke_with_flush_event(fl); |
|
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
680 |
write_thread_local_buffer(_chunkwriter, t); |
57360 | 681 |
_repository.flush_chunk(); |
50113 | 682 |
} |
683 |
||
58578
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
684 |
void JfrRecorderService::flushpoint() { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
685 |
Thread* const t = Thread::current(); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
686 |
RotationLock rl(t); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
687 |
if (rl.not_acquired() || !_chunkwriter.is_valid()) { |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
688 |
return; |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
689 |
} |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
690 |
invoke_flush(t); |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
691 |
} |
7b89c53db169
Mutual exclusions on emergency dump in relation to flush()
mgronlun
parents:
58567
diff
changeset
|
692 |
|
50113 | 693 |
void JfrRecorderService::process_full_buffers() { |
694 |
if (_chunkwriter.is_valid()) { |
|
695 |
_storage.write_full(); |
|
696 |
} |
|
697 |
} |
|
698 |
||
699 |
void JfrRecorderService::scavenge() { |
|
700 |
_storage.scavenge(); |
|
701 |
} |
|
702 |
||
703 |
void JfrRecorderService::evaluate_chunk_size_for_rotation() { |
|
53014
339d2fbe8675
8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
52877
diff
changeset
|
704 |
JfrChunkRotation::evaluate(_chunkwriter); |
50113 | 705 |
} |