22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "jfr/jfr.hpp" |
26 #include "jfr/jfr.hpp" |
|
27 #include "jfr/leakprofiler/leakProfiler.hpp" |
|
28 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
27 #include "jfr/metadata/jfrSerializer.hpp" |
29 #include "jfr/metadata/jfrSerializer.hpp" |
28 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
30 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
29 #include "jfr/recorder/checkpoint/types/jfrType.hpp" |
31 #include "jfr/recorder/checkpoint/types/jfrType.hpp" |
30 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
32 #include "jfr/recorder/checkpoint/types/jfrTypeManager.hpp" |
31 #include "jfr/utilities/jfrDoublyLinkedList.hpp" |
33 #include "jfr/utilities/jfrDoublyLinkedList.hpp" |
40 class JfrSerializerRegistration : public JfrCHeapObj { |
42 class JfrSerializerRegistration : public JfrCHeapObj { |
41 private: |
43 private: |
42 JfrSerializerRegistration* _next; |
44 JfrSerializerRegistration* _next; |
43 JfrSerializerRegistration* _prev; |
45 JfrSerializerRegistration* _prev; |
44 JfrSerializer* _serializer; |
46 JfrSerializer* _serializer; |
45 mutable JfrCheckpointBlobHandle _cache; |
47 mutable JfrBlobHandle _cache; |
46 JfrTypeId _id; |
48 JfrTypeId _id; |
47 bool _permit_cache; |
49 bool _permit_cache; |
48 |
50 |
49 public: |
51 public: |
50 JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) : |
52 JfrSerializerRegistration(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) : |
169 } |
171 } |
170 } |
172 } |
171 |
173 |
172 void JfrTypeManager::write_type_set() { |
174 void JfrTypeManager::write_type_set() { |
173 assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); |
175 assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); |
|
176 if (!LeakProfiler::is_running()) { |
|
177 JfrCheckpointWriter writer; |
|
178 TypeSet set; |
|
179 set.serialize(writer); |
|
180 return; |
|
181 } |
|
182 JfrCheckpointWriter leakp_writer; |
174 JfrCheckpointWriter writer; |
183 JfrCheckpointWriter writer; |
175 TypeSet set; |
184 TypeSet set(&leakp_writer); |
176 set.serialize(writer); |
185 set.serialize(writer); |
|
186 ObjectSampleCheckpoint::on_type_set(leakp_writer); |
177 } |
187 } |
178 |
188 |
179 void JfrTypeManager::write_type_set_for_unloaded_classes() { |
189 void JfrTypeManager::write_type_set_for_unloaded_classes() { |
180 assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
190 assert(SafepointSynchronize::is_at_safepoint(), "invariant"); |
181 JfrCheckpointWriter writer; |
191 JfrCheckpointWriter writer; |
182 const JfrCheckpointContext ctx = writer.context(); |
192 const JfrCheckpointContext ctx = writer.context(); |
183 ClassUnloadTypeSet class_unload_set; |
193 ClassUnloadTypeSet class_unload_set; |
184 class_unload_set.serialize(writer); |
194 class_unload_set.serialize(writer); |
|
195 if (LeakProfiler::is_running()) { |
|
196 ObjectSampleCheckpoint::on_type_set_unload(writer); |
|
197 } |
185 if (!Jfr::is_recording()) { |
198 if (!Jfr::is_recording()) { |
186 // discard anything written |
199 // discard anything written |
187 writer.set_context(ctx); |
200 writer.set_context(ctx); |
188 } |
201 } |
189 } |
202 } |
194 FlushTypeSet flush; |
207 FlushTypeSet flush; |
195 flush.serialize(writer); |
208 flush.serialize(writer); |
196 return flush.elements(); |
209 return flush.elements(); |
197 } |
210 } |
198 |
211 |
199 void JfrTypeManager::create_thread_checkpoint(Thread* t) { |
212 void JfrTypeManager::create_thread_blob(Thread* t) { |
200 assert(t != NULL, "invariant"); |
213 assert(t != NULL, "invariant"); |
201 ResourceMark rm(t); |
214 ResourceMark rm(t); |
202 HandleMark hm(t); |
215 HandleMark hm(t); |
203 JfrThreadConstant type_thread(t); |
216 JfrThreadConstant type_thread(t); |
204 JfrCheckpointWriter writer(t, true, THREADS); |
217 JfrCheckpointWriter writer(t, true, THREADS); |
205 writer.write_type(TYPE_THREAD); |
218 writer.write_type(TYPE_THREAD); |
206 type_thread.serialize(writer); |
219 type_thread.serialize(writer); |
207 // create and install a checkpoint blob |
220 // create and install a checkpoint blob |
208 t->jfr_thread_local()->set_thread_checkpoint(writer.move()); |
221 t->jfr_thread_local()->set_thread_blob(writer.move()); |
209 assert(t->jfr_thread_local()->has_thread_checkpoint(), "invariant"); |
222 assert(t->jfr_thread_local()->has_thread_blob(), "invariant"); |
210 } |
223 } |
211 |
224 |
212 void JfrTypeManager::write_thread_checkpoint(Thread* t) { |
225 void JfrTypeManager::write_thread_checkpoint(Thread* t) { |
213 assert(t != NULL, "invariant"); |
226 assert(t != NULL, "invariant"); |
214 ResourceMark rm(t); |
227 ResourceMark rm(t); |