author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58786 | 7909763ad193 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52212
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" |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
26 |
#include "jfr/metadata/jfrSerializer.hpp" |
50113 | 27 |
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
28 |
#include "jfr/recorder/checkpoint/types/jfrType.hpp" |
|
29 |
#include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
|
58863 | 30 |
#include "jfr/recorder/jfrRecorder.hpp" |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
31 |
#include "jfr/utilities/jfrDoublyLinkedList.hpp" |
50113 | 32 |
#include "jfr/utilities/jfrIterator.hpp" |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
33 |
#include "memory/resourceArea.hpp" |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
34 |
#include "runtime/handles.inline.hpp" |
50113 | 35 |
#include "runtime/safepoint.hpp" |
58786
7909763ad193
8231081: TestMetadataRetention fails due to missing symbol id
mgronlun
parents:
58132
diff
changeset
|
36 |
#include "runtime/semaphore.hpp" |
50113 | 37 |
#include "runtime/thread.inline.hpp" |
38 |
#include "utilities/exceptions.hpp" |
|
39 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
40 |
class JfrSerializerRegistration : public JfrCHeapObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
41 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
42 |
JfrSerializerRegistration* _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
43 |
JfrSerializerRegistration* _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
44 |
JfrSerializer* _serializer; |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
58003
diff
changeset
|
45 |
mutable JfrBlobHandle _cache; |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
46 |
JfrTypeId _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
47 |
bool _permit_cache; |
50113 | 48 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
49 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
50 |
JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) : |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
51 |
_next(NULL), _prev(NULL), _serializer(serializer), _cache(), _id(id), _permit_cache(permit_cache) {} |
50113 | 52 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
53 |
~JfrSerializerRegistration() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
54 |
delete _serializer; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
55 |
} |
50113 | 56 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
57 |
JfrSerializerRegistration* next() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
58 |
return _next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
59 |
} |
50113 | 60 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
61 |
void set_next(JfrSerializerRegistration* next) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
62 |
_next = next; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
63 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
64 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
65 |
JfrSerializerRegistration* prev() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
66 |
return _prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
67 |
} |
50113 | 68 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
69 |
void set_prev(JfrSerializerRegistration* prev) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
70 |
_prev = prev; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
71 |
} |
50113 | 72 |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
73 |
JfrTypeId id() const { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
74 |
return _id; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
75 |
} |
50113 | 76 |
|
58863 | 77 |
void on_rotation() const { |
78 |
_serializer->on_rotation(); |
|
79 |
} |
|
80 |
||
81 |
void invoke(JfrCheckpointWriter& writer) const { |
|
82 |
if (_cache.valid()) { |
|
83 |
writer.increment(); |
|
84 |
_cache->write(writer); |
|
85 |
return; |
|
86 |
} |
|
87 |
const JfrCheckpointContext ctx = writer.context(); |
|
88 |
// serialize the type id before invoking callback |
|
89 |
writer.write_type(_id); |
|
90 |
const intptr_t start = writer.current_offset(); |
|
91 |
// invoke the serializer routine |
|
92 |
_serializer->serialize(writer); |
|
93 |
if (start == writer.current_offset()) { |
|
94 |
// the serializer implementation did nothing, rewind to restore |
|
95 |
writer.set_context(ctx); |
|
96 |
return; |
|
97 |
} |
|
98 |
if (_permit_cache) { |
|
99 |
_cache = writer.copy(&ctx); |
|
100 |
} |
|
101 |
} |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
102 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
103 |
|
58863 | 104 |
static void serialize_threads(JfrCheckpointWriter& writer) { |
105 |
JfrThreadConstantSet thread_set; |
|
106 |
writer.write_type(TYPE_THREAD); |
|
107 |
thread_set.serialize(writer); |
|
108 |
} |
|
109 |
||
110 |
static void serialize_thread_groups(JfrCheckpointWriter& writer) { |
|
111 |
JfrThreadGroupConstant thread_group_set; |
|
112 |
writer.write_type(TYPE_THREADGROUP); |
|
113 |
thread_group_set.serialize(writer); |
|
114 |
} |
|
115 |
||
116 |
void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) { |
|
117 |
serialize_threads(writer); |
|
118 |
serialize_thread_groups(writer); |
|
119 |
} |
|
120 |
||
121 |
void JfrTypeManager::create_thread_blob(Thread* t) { |
|
122 |
assert(t != NULL, "invariant"); |
|
123 |
ResourceMark rm(t); |
|
124 |
HandleMark hm(t); |
|
125 |
JfrThreadConstant type_thread(t); |
|
126 |
JfrCheckpointWriter writer(t, true, THREADS); |
|
127 |
writer.write_type(TYPE_THREAD); |
|
128 |
type_thread.serialize(writer); |
|
129 |
// create and install a checkpoint blob |
|
130 |
t->jfr_thread_local()->set_thread_blob(writer.move()); |
|
131 |
assert(t->jfr_thread_local()->has_thread_blob(), "invariant"); |
|
132 |
} |
|
133 |
||
134 |
void JfrTypeManager::write_thread_checkpoint(Thread* t) { |
|
135 |
assert(t != NULL, "invariant"); |
|
136 |
ResourceMark rm(t); |
|
137 |
HandleMark hm(t); |
|
138 |
JfrThreadConstant type_thread(t); |
|
139 |
JfrCheckpointWriter writer(t, true, THREADS); |
|
140 |
writer.write_type(TYPE_THREAD); |
|
141 |
type_thread.serialize(writer); |
|
50113 | 142 |
} |
143 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
144 |
class SerializerRegistrationGuard : public StackObj { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
145 |
private: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
146 |
static Semaphore _mutex_semaphore; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
147 |
public: |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
148 |
SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
149 |
_mutex_semaphore.wait(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
150 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
151 |
~SerializerRegistrationGuard() { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
152 |
_mutex_semaphore.signal(); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
153 |
} |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
154 |
}; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
155 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
156 |
Semaphore SerializerRegistrationGuard::_mutex_semaphore(1); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
157 |
|
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
158 |
typedef JfrDoublyLinkedList<JfrSerializerRegistration> List; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
159 |
typedef StopOnNullIterator<const List> Iterator; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
160 |
static List types; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
161 |
|
58786
7909763ad193
8231081: TestMetadataRetention fails due to missing symbol id
mgronlun
parents:
58132
diff
changeset
|
162 |
void JfrTypeManager::destroy() { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
163 |
SerializerRegistrationGuard guard; |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
164 |
Iterator iter(types); |
50113 | 165 |
JfrSerializerRegistration* registration; |
166 |
while (iter.has_next()) { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
167 |
registration = types.remove(iter.next()); |
50113 | 168 |
assert(registration != NULL, "invariant"); |
169 |
delete registration; |
|
170 |
} |
|
171 |
} |
|
172 |
||
58863 | 173 |
void JfrTypeManager::on_rotation() { |
174 |
const Iterator iter(types); |
|
50113 | 175 |
while (iter.has_next()) { |
58863 | 176 |
iter.next()->on_rotation(); |
50113 | 177 |
} |
178 |
} |
|
179 |
||
180 |
#ifdef ASSERT |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
181 |
static void assert_not_registered_twice(JfrTypeId id, List& list) { |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
182 |
const Iterator iter(list); |
50113 | 183 |
while (iter.has_next()) { |
184 |
assert(iter.next()->id() != id, "invariant"); |
|
185 |
} |
|
186 |
} |
|
187 |
#endif |
|
188 |
||
58863 | 189 |
static bool new_registration = false; |
190 |
||
191 |
static bool register_static_type(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
192 |
assert(serializer != NULL, "invariant"); |
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
193 |
JfrSerializerRegistration* const registration = new JfrSerializerRegistration(id, permit_cache, serializer); |
50113 | 194 |
if (registration == NULL) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
195 |
delete serializer; |
50113 | 196 |
return false; |
197 |
} |
|
58863 | 198 |
assert(!types.in_list(registration), "invariant"); |
199 |
DEBUG_ONLY(assert_not_registered_twice(id, types);) |
|
200 |
if (JfrRecorder::is_recording()) { |
|
201 |
JfrCheckpointWriter writer(STATICS); |
|
202 |
registration->invoke(writer); |
|
203 |
new_registration = true; |
|
50113 | 204 |
} |
58863 | 205 |
types.prepend(registration); |
50113 | 206 |
return true; |
207 |
} |
|
208 |
||
209 |
bool JfrTypeManager::initialize() { |
|
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
210 |
SerializerRegistrationGuard guard; |
58863 | 211 |
register_static_type(TYPE_FLAGVALUEORIGIN, true, new FlagValueOriginConstant()); |
212 |
register_static_type(TYPE_INFLATECAUSE, true, new MonitorInflateCauseConstant()); |
|
213 |
register_static_type(TYPE_GCCAUSE, true, new GCCauseConstant()); |
|
214 |
register_static_type(TYPE_GCNAME, true, new GCNameConstant()); |
|
215 |
register_static_type(TYPE_GCWHEN, true, new GCWhenConstant()); |
|
216 |
register_static_type(TYPE_GCTHRESHOLDUPDATER, true, new GCThresholdUpdaterConstant()); |
|
217 |
register_static_type(TYPE_METADATATYPE, true, new MetadataTypeConstant()); |
|
218 |
register_static_type(TYPE_METASPACEOBJECTTYPE, true, new MetaspaceObjectTypeConstant()); |
|
219 |
register_static_type(TYPE_REFERENCETYPE, true, new ReferenceTypeConstant()); |
|
220 |
register_static_type(TYPE_NARROWOOPMODE, true, new NarrowOopModeConstant()); |
|
221 |
register_static_type(TYPE_COMPILERPHASETYPE, true, new CompilerPhaseTypeConstant()); |
|
222 |
register_static_type(TYPE_CODEBLOBTYPE, true, new CodeBlobTypeConstant()); |
|
223 |
register_static_type(TYPE_VMOPERATIONTYPE, true, new VMOperationTypeConstant()); |
|
224 |
register_static_type(TYPE_THREADSTATE, true, new ThreadStateConstant()); |
|
50113 | 225 |
return true; |
226 |
} |
|
227 |
||
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
228 |
// implementation for the static registration function exposed in the JfrSerializer api |
58863 | 229 |
bool JfrSerializer::register_serializer(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) { |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
230 |
SerializerRegistrationGuard guard; |
58863 | 231 |
return register_static_type(id, permit_cache, serializer); |
50703
0486d7749b8d
8205053: Decouple type registration from framework lifecycle
egahlin
parents:
50525
diff
changeset
|
232 |
} |
58863 | 233 |
|
234 |
bool JfrTypeManager::has_new_static_type() { |
|
235 |
if (new_registration) { |
|
236 |
SerializerRegistrationGuard guard; |
|
237 |
new_registration = false; |
|
238 |
return true; |
|
239 |
} |
|
240 |
return false; |
|
241 |
} |
|
242 |
||
243 |
void JfrTypeManager::write_static_types(JfrCheckpointWriter& writer) { |
|
244 |
SerializerRegistrationGuard guard; |
|
245 |
const Iterator iter(types); |
|
246 |
while (iter.has_next()) { |
|
247 |
iter.next()->invoke(writer); |
|
248 |
} |
|
249 |
new_registration = false; |
|
250 |
} |