21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "jfr/jfr.hpp" |
|
27 #include "jfr/leakprofiler/leakProfiler.hpp" |
|
28 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
|
29 #include "jfr/metadata/jfrSerializer.hpp" |
26 #include "jfr/metadata/jfrSerializer.hpp" |
30 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
31 #include "jfr/recorder/checkpoint/types/jfrType.hpp" |
28 #include "jfr/recorder/checkpoint/types/jfrType.hpp" |
32 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
29 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
|
30 #include "jfr/recorder/jfrRecorder.hpp" |
33 #include "jfr/utilities/jfrDoublyLinkedList.hpp" |
31 #include "jfr/utilities/jfrDoublyLinkedList.hpp" |
34 #include "jfr/utilities/jfrIterator.hpp" |
32 #include "jfr/utilities/jfrIterator.hpp" |
35 #include "memory/resourceArea.hpp" |
33 #include "memory/resourceArea.hpp" |
36 #include "runtime/handles.inline.hpp" |
34 #include "runtime/handles.inline.hpp" |
|
35 #include "runtime/safepoint.hpp" |
|
36 #include "runtime/semaphore.hpp" |
37 #include "runtime/thread.inline.hpp" |
37 #include "runtime/thread.inline.hpp" |
38 #include "utilities/exceptions.hpp" |
38 #include "utilities/exceptions.hpp" |
39 #include "runtime/semaphore.hpp" |
|
40 |
39 |
41 class JfrSerializerRegistration : public JfrCHeapObj { |
40 class JfrSerializerRegistration : public JfrCHeapObj { |
42 private: |
41 private: |
43 JfrSerializerRegistration* _next; |
42 JfrSerializerRegistration* _next; |
44 JfrSerializerRegistration* _prev; |
43 JfrSerializerRegistration* _prev; |
140 JfrCheckpointWriter writer(t, true, THREADS); |
139 JfrCheckpointWriter writer(t, true, THREADS); |
141 writer.write_type(TYPE_THREAD); |
140 writer.write_type(TYPE_THREAD); |
142 type_thread.serialize(writer); |
141 type_thread.serialize(writer); |
143 } |
142 } |
144 |
143 |
145 size_t JfrTypeManager::flush_type_set() { |
|
146 JfrCheckpointWriter writer; |
|
147 FlushTypeSet flush; |
|
148 flush.serialize(writer); |
|
149 return flush.elements(); |
|
150 } |
|
151 |
|
152 void JfrTypeManager::write_type_set() { |
|
153 if (!LeakProfiler::is_running()) { |
|
154 JfrCheckpointWriter writer; |
|
155 TypeSet set; |
|
156 set.serialize(writer); |
|
157 return; |
|
158 } |
|
159 JfrCheckpointWriter leakp_writer; |
|
160 JfrCheckpointWriter writer; |
|
161 TypeSet set(&leakp_writer); |
|
162 set.serialize(writer); |
|
163 ObjectSampleCheckpoint::on_type_set(leakp_writer); |
|
164 } |
|
165 |
|
166 void JfrTypeManager::write_type_set_for_unloaded_classes() { |
|
167 JfrCheckpointWriter writer; |
|
168 const JfrCheckpointContext ctx = writer.context(); |
|
169 ClassUnloadTypeSet class_unload_set; |
|
170 class_unload_set.serialize(writer); |
|
171 if (LeakProfiler::is_running()) { |
|
172 ObjectSampleCheckpoint::on_type_set_unload(writer); |
|
173 } |
|
174 if (!Jfr::is_recording()) { |
|
175 // discard anything written |
|
176 writer.set_context(ctx); |
|
177 } |
|
178 } |
|
179 |
|
180 class SerializerRegistrationGuard : public StackObj { |
144 class SerializerRegistrationGuard : public StackObj { |
181 private: |
145 private: |
182 static Semaphore _mutex_semaphore; |
146 static Semaphore _mutex_semaphore; |
183 public: |
147 public: |
184 SerializerRegistrationGuard() { |
148 SerializerRegistrationGuard() { |
204 assert(registration != NULL, "invariant"); |
168 assert(registration != NULL, "invariant"); |
205 delete registration; |
169 delete registration; |
206 } |
170 } |
207 } |
171 } |
208 |
172 |
209 void JfrTypeManager::clear() { |
|
210 TypeSet type_set; |
|
211 type_set.clear(); |
|
212 } |
|
213 |
|
214 void JfrTypeManager::on_rotation() { |
173 void JfrTypeManager::on_rotation() { |
215 const Iterator iter(types); |
174 const Iterator iter(types); |
216 while (iter.has_next()) { |
175 while (iter.has_next()) { |
217 iter.next()->on_rotation(); |
176 iter.next()->on_rotation(); |
218 } |
177 } |
236 delete serializer; |
195 delete serializer; |
237 return false; |
196 return false; |
238 } |
197 } |
239 assert(!types.in_list(registration), "invariant"); |
198 assert(!types.in_list(registration), "invariant"); |
240 DEBUG_ONLY(assert_not_registered_twice(id, types);) |
199 DEBUG_ONLY(assert_not_registered_twice(id, types);) |
241 if (Jfr::is_recording()) { |
200 if (JfrRecorder::is_recording()) { |
242 JfrCheckpointWriter writer(STATICS); |
201 JfrCheckpointWriter writer(STATICS); |
243 registration->invoke(writer); |
202 registration->invoke(writer); |
244 new_registration = true; |
203 new_registration = true; |
245 } |
204 } |
246 types.prepend(registration); |
205 types.prepend(registration); |