author | mgronlun |
Sat, 24 Aug 2019 14:30:27 +0200 | |
branch | JEP-349-branch |
changeset 57870 | 00860d9caf4d |
parent 57360 | 5d043a159d5c |
child 57872 | 7aa1b3d6ff8f |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
57360 | 2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/javaClasses.inline.hpp" |
|
27 |
#include "jfr/recorder/jfrRecorder.hpp" |
|
28 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
|
29 |
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
|
30 |
#include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
|
31 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp" |
|
32 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
33 |
#include "jfr/recorder/storage/jfrMemorySpace.inline.hpp" |
|
34 |
#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp" |
|
35 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
36 |
#include "jfr/utilities/jfrBigEndian.hpp" |
|
57360 | 37 |
#include "jfr/utilities/jfrIterator.hpp" |
38 |
#include "jfr/utilities/jfrThreadIterator.hpp" |
|
50113 | 39 |
#include "jfr/utilities/jfrTypes.hpp" |
57360 | 40 |
#include "jfr/writers/jfrJavaEventWriter.hpp" |
50113 | 41 |
#include "logging/log.hpp" |
42 |
#include "memory/resourceArea.hpp" |
|
57360 | 43 |
#include "runtime/handles.inline.hpp" |
50113 | 44 |
#include "runtime/mutexLocker.hpp" |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50117
diff
changeset
|
45 |
#include "runtime/orderAccess.hpp" |
50117
fb66b2959eaf
8203251: Non-PCH build failed after JDK-8199712 (Flight Recorder)
shade
parents:
50113
diff
changeset
|
46 |
#include "runtime/os.inline.hpp" |
50113 | 47 |
#include "runtime/safepoint.hpp" |
48 |
||
49 |
typedef JfrCheckpointManager::Buffer* BufferPtr; |
|
50 |
||
51 |
static JfrCheckpointManager* _instance = NULL; |
|
52 |
||
53 |
JfrCheckpointManager& JfrCheckpointManager::instance() { |
|
54 |
return *_instance; |
|
55 |
} |
|
56 |
||
57 |
JfrCheckpointManager* JfrCheckpointManager::create(JfrChunkWriter& cw) { |
|
58 |
assert(_instance == NULL, "invariant"); |
|
59 |
_instance = new JfrCheckpointManager(cw); |
|
60 |
return _instance; |
|
61 |
} |
|
62 |
||
63 |
void JfrCheckpointManager::destroy() { |
|
64 |
assert(_instance != NULL, "invariant"); |
|
65 |
delete _instance; |
|
66 |
_instance = NULL; |
|
67 |
} |
|
68 |
||
69 |
JfrCheckpointManager::JfrCheckpointManager(JfrChunkWriter& cw) : |
|
70 |
_free_list_mspace(NULL), |
|
71 |
_epoch_transition_mspace(NULL), |
|
72 |
_lock(NULL), |
|
73 |
_service_thread(NULL), |
|
74 |
_chunkwriter(cw), |
|
75 |
_checkpoint_epoch_state(JfrTraceIdEpoch::epoch()) {} |
|
76 |
||
77 |
JfrCheckpointManager::~JfrCheckpointManager() { |
|
78 |
if (_free_list_mspace != NULL) { |
|
79 |
delete _free_list_mspace; |
|
80 |
} |
|
81 |
if (_epoch_transition_mspace != NULL) { |
|
82 |
delete _epoch_transition_mspace; |
|
83 |
} |
|
84 |
if (_lock != NULL) { |
|
85 |
delete _lock; |
|
86 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
87 |
JfrTypeManager::clear(); |
50113 | 88 |
} |
89 |
||
90 |
static const size_t unlimited_mspace_size = 0; |
|
91 |
static const size_t checkpoint_buffer_cache_count = 2; |
|
92 |
static const size_t checkpoint_buffer_size = 512 * K; |
|
93 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
94 |
static JfrCheckpointMspace* allocate_mspace(size_t size, size_t limit, size_t cache_count, JfrCheckpointManager* mgr) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
95 |
return create_mspace<JfrCheckpointMspace, JfrCheckpointManager>(size, limit, cache_count, mgr); |
50113 | 96 |
} |
97 |
||
98 |
bool JfrCheckpointManager::initialize() { |
|
99 |
assert(_free_list_mspace == NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
100 |
_free_list_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this); |
50113 | 101 |
if (_free_list_mspace == NULL) { |
102 |
return false; |
|
103 |
} |
|
104 |
assert(_epoch_transition_mspace == NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
105 |
_epoch_transition_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this); |
50113 | 106 |
if (_epoch_transition_mspace == NULL) { |
107 |
return false; |
|
108 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
109 |
assert(_lock == NULL, "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
110 |
_lock = new Mutex(Monitor::leaf - 1, "Checkpoint mutex", Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
111 |
if (_lock == NULL) { |
50113 | 112 |
return false; |
113 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
114 |
return JfrTypeManager::initialize(); |
50113 | 115 |
} |
116 |
||
117 |
void JfrCheckpointManager::register_service_thread(const Thread* thread) { |
|
118 |
_service_thread = thread; |
|
119 |
} |
|
120 |
||
121 |
void JfrCheckpointManager::register_full(BufferPtr t, Thread* thread) { |
|
122 |
// nothing here at the moment |
|
57360 | 123 |
assert(t != NULL, "invariant"); |
124 |
assert(t->acquired_by(thread), "invariant"); |
|
50113 | 125 |
assert(t->retired(), "invariant"); |
126 |
} |
|
127 |
||
128 |
void JfrCheckpointManager::lock() { |
|
129 |
assert(!_lock->owned_by_self(), "invariant"); |
|
130 |
_lock->lock_without_safepoint_check(); |
|
131 |
} |
|
132 |
||
133 |
void JfrCheckpointManager::unlock() { |
|
134 |
_lock->unlock(); |
|
135 |
} |
|
136 |
||
137 |
#ifdef ASSERT |
|
138 |
bool JfrCheckpointManager::is_locked() const { |
|
139 |
return _lock->owned_by_self(); |
|
140 |
} |
|
141 |
||
142 |
static void assert_free_lease(const BufferPtr buffer) { |
|
143 |
assert(buffer != NULL, "invariant"); |
|
144 |
assert(buffer->acquired_by_self(), "invariant"); |
|
145 |
assert(buffer->lease(), "invariant"); |
|
146 |
} |
|
147 |
||
148 |
static void assert_release(const BufferPtr buffer) { |
|
149 |
assert(buffer != NULL, "invariant"); |
|
150 |
assert(buffer->lease(), "invariant"); |
|
151 |
assert(buffer->acquired_by_self(), "invariant"); |
|
152 |
} |
|
153 |
#endif // ASSERT |
|
154 |
||
155 |
static BufferPtr lease_free(size_t size, JfrCheckpointMspace* mspace, size_t retry_count, Thread* thread) { |
|
156 |
static const size_t max_elem_size = mspace->min_elem_size(); // min is max |
|
157 |
BufferPtr buffer; |
|
158 |
if (size <= max_elem_size) { |
|
159 |
BufferPtr buffer = mspace_get_free_lease_with_retry(size, mspace, retry_count, thread); |
|
160 |
if (buffer != NULL) { |
|
161 |
DEBUG_ONLY(assert_free_lease(buffer);) |
|
162 |
return buffer; |
|
163 |
} |
|
164 |
} |
|
165 |
buffer = mspace_allocate_transient_lease_to_free(size, mspace, thread); |
|
166 |
DEBUG_ONLY(assert_free_lease(buffer);) |
|
167 |
return buffer; |
|
168 |
} |
|
169 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
170 |
bool JfrCheckpointManager::use_epoch_transition_mspace(const Thread* thread) const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
171 |
return _service_thread != thread && OrderAccess::load_acquire(&_checkpoint_epoch_state) != JfrTraceIdEpoch::epoch(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
172 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
173 |
|
50113 | 174 |
static const size_t lease_retry = 10; |
175 |
||
176 |
BufferPtr JfrCheckpointManager::lease_buffer(Thread* thread, size_t size /* 0 */) { |
|
177 |
JfrCheckpointManager& manager = instance(); |
|
178 |
if (manager.use_epoch_transition_mspace(thread)) { |
|
179 |
return lease_free(size, manager._epoch_transition_mspace, lease_retry, thread); |
|
180 |
} |
|
181 |
return lease_free(size, manager._free_list_mspace, lease_retry, thread); |
|
182 |
} |
|
183 |
||
184 |
/* |
|
185 |
* If the buffer was a "lease" from the free list, release back. |
|
186 |
* |
|
187 |
* The buffer is effectively invalidated for the thread post-return, |
|
188 |
* and the caller should take means to ensure that it is not referenced. |
|
189 |
*/ |
|
190 |
static void release(BufferPtr const buffer, Thread* thread) { |
|
191 |
DEBUG_ONLY(assert_release(buffer);) |
|
192 |
buffer->clear_lease(); |
|
193 |
buffer->release(); |
|
194 |
} |
|
195 |
||
196 |
BufferPtr JfrCheckpointManager::flush(BufferPtr old, size_t used, size_t requested, Thread* thread) { |
|
197 |
assert(old != NULL, "invariant"); |
|
198 |
assert(old->lease(), "invariant"); |
|
199 |
if (0 == requested) { |
|
200 |
// indicates a lease is being returned |
|
201 |
release(old, thread); |
|
202 |
return NULL; |
|
203 |
} |
|
204 |
// migration of in-flight information |
|
205 |
BufferPtr const new_buffer = lease_buffer(thread, used + requested); |
|
206 |
if (new_buffer != NULL) { |
|
207 |
migrate_outstanding_writes(old, new_buffer, used, requested); |
|
208 |
} |
|
209 |
release(old, thread); |
|
210 |
return new_buffer; // might be NULL |
|
211 |
} |
|
212 |
||
213 |
// offsets into the JfrCheckpointEntry |
|
214 |
static const juint starttime_offset = sizeof(jlong); |
|
215 |
static const juint duration_offset = starttime_offset + sizeof(jlong); |
|
216 |
static const juint flushpoint_offset = duration_offset + sizeof(jlong); |
|
217 |
static const juint types_offset = flushpoint_offset + sizeof(juint); |
|
218 |
static const juint payload_offset = types_offset + sizeof(juint); |
|
219 |
||
220 |
template <typename Return> |
|
221 |
static Return read_data(const u1* data) { |
|
222 |
return JfrBigEndian::read<Return>(data); |
|
223 |
} |
|
224 |
||
225 |
static jlong total_size(const u1* data) { |
|
226 |
return read_data<jlong>(data); |
|
227 |
} |
|
228 |
||
229 |
static jlong starttime(const u1* data) { |
|
230 |
return read_data<jlong>(data + starttime_offset); |
|
231 |
} |
|
232 |
||
233 |
static jlong duration(const u1* data) { |
|
234 |
return read_data<jlong>(data + duration_offset); |
|
235 |
} |
|
236 |
||
237 |
static juint number_of_types(const u1* data) { |
|
238 |
return read_data<juint>(data + types_offset); |
|
239 |
} |
|
240 |
||
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
|
241 |
static void write_checkpoint_header(JfrChunkWriter& cw, int64_t offset_prev_cp_event, const u1* data) { |
50113 | 242 |
cw.reserve(sizeof(u4)); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
243 |
cw.write<u8>(EVENT_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
|
244 |
cw.write<u8>(starttime(data)); |
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
|
245 |
cw.write<u8>(duration(data)); |
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
|
246 |
cw.write<u8>(offset_prev_cp_event); |
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
|
247 |
cw.write<bool>(false); // not a flushpoint |
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
|
248 |
cw.write<juint>(number_of_types(data)); |
50113 | 249 |
} |
250 |
||
251 |
static void write_checkpoint_content(JfrChunkWriter& cw, const u1* data, size_t size) { |
|
252 |
assert(data != NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
253 |
cw.write_unbuffered(data + payload_offset, size - sizeof(JfrCheckpointEntry)); |
50113 | 254 |
} |
255 |
||
256 |
static size_t write_checkpoint_event(JfrChunkWriter& cw, const u1* data) { |
|
257 |
assert(data != NULL, "invariant"); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
258 |
const int64_t event_begin = cw.current_offset(); |
57360 | 259 |
const int64_t last_checkpoint_event = cw.last_checkpoint_offset(); |
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
|
260 |
const int64_t delta = last_checkpoint_event == 0 ? 0 : last_checkpoint_event - event_begin; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
261 |
const int64_t checkpoint_size = total_size(data); |
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
|
262 |
write_checkpoint_header(cw, delta, data); |
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
|
263 |
write_checkpoint_content(cw, data, checkpoint_size); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
264 |
const int64_t event_size = cw.current_offset() - event_begin; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
265 |
cw.write_padded_at_offset<u4>(event_size, event_begin); |
57360 | 266 |
cw.set_last_checkpoint_offset(event_begin); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
267 |
return (size_t)checkpoint_size; |
50113 | 268 |
} |
269 |
||
270 |
static size_t write_checkpoints(JfrChunkWriter& cw, const u1* data, size_t size) { |
|
271 |
assert(cw.is_valid(), "invariant"); |
|
272 |
assert(data != NULL, "invariant"); |
|
273 |
assert(size > 0, "invariant"); |
|
274 |
const u1* const limit = data + size; |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
275 |
const u1* next = data; |
50113 | 276 |
size_t processed = 0; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
277 |
while (next < limit) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
278 |
const size_t checkpoint_size = write_checkpoint_event(cw, next); |
50113 | 279 |
processed += checkpoint_size; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
280 |
next += checkpoint_size; |
50113 | 281 |
} |
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
|
282 |
assert(next == limit, "invariant"); |
50113 | 283 |
return processed; |
284 |
} |
|
285 |
||
286 |
template <typename T> |
|
287 |
class CheckpointWriteOp { |
|
288 |
private: |
|
289 |
JfrChunkWriter& _writer; |
|
290 |
size_t _processed; |
|
291 |
public: |
|
292 |
typedef T Type; |
|
293 |
CheckpointWriteOp(JfrChunkWriter& writer) : _writer(writer), _processed(0) {} |
|
294 |
bool write(Type* t, const u1* data, size_t size) { |
|
295 |
_processed += write_checkpoints(_writer, data, size); |
|
296 |
return true; |
|
297 |
} |
|
298 |
size_t processed() const { return _processed; } |
|
299 |
}; |
|
300 |
||
301 |
typedef CheckpointWriteOp<JfrCheckpointMspace::Type> WriteOperation; |
|
302 |
typedef ReleaseOp<JfrCheckpointMspace> CheckpointReleaseOperation; |
|
303 |
||
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
|
304 |
template <template <typename> class WriterHost, template <typename, typename> class CompositeOperation> |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
305 |
static size_t write_mspace(JfrCheckpointMspace* mspace, JfrChunkWriter& chunkwriter) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
306 |
assert(mspace != NULL, "invariant"); |
50113 | 307 |
WriteOperation wo(chunkwriter); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
308 |
WriterHost<WriteOperation> wh(wo); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
309 |
CheckpointReleaseOperation cro(mspace, Thread::current(), false); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
310 |
CompositeOperation<WriterHost<WriteOperation>, CheckpointReleaseOperation> co(&wh, &cro); |
50113 | 311 |
assert(mspace->is_full_empty(), "invariant"); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
312 |
process_free_list(co, mspace); |
50113 | 313 |
return wo.processed(); |
314 |
} |
|
315 |
||
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
|
316 |
void JfrCheckpointManager::synchronize_epoch() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
317 |
assert(_checkpoint_epoch_state != JfrTraceIdEpoch::epoch(), "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
318 |
OrderAccess::storestore(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
319 |
_checkpoint_epoch_state = JfrTraceIdEpoch::epoch(); |
57360 | 320 |
} |
321 |
||
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
|
322 |
void JfrCheckpointManager::shift_epoch() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
323 |
debug_only(const u1 current_epoch = JfrTraceIdEpoch::current();) |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
324 |
JfrTraceIdEpoch::shift_epoch(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
325 |
assert(current_epoch != JfrTraceIdEpoch::current(), "invariant"); |
50113 | 326 |
} |
327 |
||
328 |
typedef DiscardOp<DefaultDiscarder<JfrBuffer> > DiscardOperation; |
|
329 |
size_t JfrCheckpointManager::clear() { |
|
330 |
DiscardOperation discarder(mutexed); // mutexed discard mode |
|
331 |
process_free_list(discarder, _free_list_mspace); |
|
332 |
process_free_list(discarder, _epoch_transition_mspace); |
|
333 |
synchronize_epoch(); |
|
57360 | 334 |
return discarder.elements(); |
50113 | 335 |
} |
336 |
||
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
|
337 |
size_t JfrCheckpointManager::write() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
338 |
const size_t processed = write_mspace<MutexedWriteOp, CompositeOperation>(_free_list_mspace, _chunkwriter); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
339 |
synchronize_epoch(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
340 |
return processed; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
341 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
342 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
343 |
typedef MutexedWriteOp<WriteOperation> FlushOperation; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
344 |
|
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
|
345 |
size_t JfrCheckpointManager::flush() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
346 |
WriteOperation wo(_chunkwriter); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
347 |
FlushOperation fo(wo); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
348 |
assert(_free_list_mspace->is_full_empty(), "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
349 |
process_free_list(fo, _free_list_mspace); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
350 |
return wo.processed(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
351 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
352 |
|
50113 | 353 |
size_t JfrCheckpointManager::write_types() { |
57360 | 354 |
ResourceMark rm; |
355 |
HandleMark hm; |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
356 |
Thread* const t = Thread::current(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
357 |
// Optimization here is to write the types directly into the epoch transition mspace |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
358 |
// because the caller will immediately serialize and reset this mspace. |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
359 |
JfrBuffer* const buffer = _epoch_transition_mspace->free_tail(); |
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
|
360 |
assert(buffer != NULL, "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
361 |
buffer->acquire(t); |
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
|
362 |
buffer->set_lease(); |
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
|
363 |
DEBUG_ONLY(assert_free_lease(buffer);) |
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
|
364 |
JfrCheckpointWriter writer(t, buffer); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
365 |
JfrTypeManager::write_types(writer); |
50113 | 366 |
return writer.used_size(); |
367 |
} |
|
368 |
||
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
|
369 |
size_t JfrCheckpointManager::write_epoch_transition_mspace() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
370 |
return write_mspace<ExclusiveOp, CompositeOperation>(_epoch_transition_mspace, _chunkwriter); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
371 |
} |
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
|
372 |
|
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
|
373 |
size_t JfrCheckpointManager::write_constants() { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
374 |
write_types(); |
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
|
375 |
return write_epoch_transition_mspace(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57360
diff
changeset
|
376 |
} |
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
|
377 |
|
57360 | 378 |
class JfrNotifyClosure : public ThreadClosure { |
379 |
public: |
|
380 |
void do_thread(Thread* t) { |
|
381 |
assert(t != NULL, "invariant"); |
|
382 |
assert(t->is_Java_thread(), "invariant"); |
|
383 |
assert_locked_or_safepoint(Threads_lock); |
|
384 |
JfrJavaEventWriter::notify((JavaThread*)t); |
|
385 |
} |
|
386 |
}; |
|
387 |
||
388 |
void JfrCheckpointManager::notify_threads() { |
|
389 |
assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
390 |
JfrNotifyClosure tc; |
|
391 |
JfrJavaThreadIterator iter; |
|
392 |
while (iter.has_next()) { |
|
393 |
tc.do_thread(iter.next()); |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
void JfrCheckpointManager::notify_types_on_rotation() { |
|
398 |
JfrTypeManager::notify_types_on_rotation(); |
|
50113 | 399 |
} |
400 |
||
401 |
void JfrCheckpointManager::write_type_set() { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
402 |
JfrTypeManager::write_type_set(); |
50113 | 403 |
} |
404 |
||
405 |
void JfrCheckpointManager::write_type_set_for_unloaded_classes() { |
|
52212
e6973df15152
8212663: Remove conservative at_safepoint assert when JFR writes type sets during class unloading
eosterlund
parents:
50703
diff
changeset
|
406 |
assert_locked_or_safepoint(ClassLoaderDataGraph_lock); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50429
diff
changeset
|
407 |
JfrTypeManager::write_type_set_for_unloaded_classes(); |
50113 | 408 |
} |
409 |
||
57360 | 410 |
size_t JfrCheckpointManager::flush_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
|
411 |
return JfrTypeManager::flush_type_set(); |
50113 | 412 |
} |
413 |
||
57360 | 414 |
void JfrCheckpointManager::create_thread_checkpoint(Thread* t) { |
415 |
JfrTypeManager::create_thread_checkpoint(t); |
|
50113 | 416 |
} |
57360 | 417 |
|
418 |
void JfrCheckpointManager::write_thread_checkpoint(Thread* t) { |
|
419 |
JfrTypeManager::write_thread_checkpoint(t); |
|
420 |
} |