35 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
35 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
36 #include "jfr/recorder/service/jfrOptionSet.hpp" |
36 #include "jfr/recorder/service/jfrOptionSet.hpp" |
37 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" |
37 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" |
38 #include "jfr/utilities/jfrHashtable.hpp" |
38 #include "jfr/utilities/jfrHashtable.hpp" |
39 #include "jfr/utilities/jfrTypes.hpp" |
39 #include "jfr/utilities/jfrTypes.hpp" |
|
40 #include "runtime/mutexLocker.hpp" |
40 #include "runtime/safepoint.hpp" |
41 #include "runtime/safepoint.hpp" |
41 #include "runtime/thread.hpp" |
42 #include "runtime/thread.hpp" |
42 #include "utilities/growableArray.hpp" |
43 #include "utilities/growableArray.hpp" |
43 |
44 |
44 static bool predicate(GrowableArray<traceid>* set, traceid id) { |
45 static bool predicate(GrowableArray<traceid>* set, traceid id) { |
269 sample->set_stacktrace(blob); |
270 sample->set_stacktrace(blob); |
270 return; |
271 return; |
271 } |
272 } |
272 const JfrStackTrace* const stack_trace = resolve(sample); |
273 const JfrStackTrace* const stack_trace = resolve(sample); |
273 DEBUG_ONLY(validate_stack_trace(sample, stack_trace)); |
274 DEBUG_ONLY(validate_stack_trace(sample, stack_trace)); |
274 JfrCheckpointWriter writer(false, true, Thread::current()); |
275 JfrCheckpointWriter writer; |
275 writer.write_type(TYPE_STACKTRACE); |
276 writer.write_type(TYPE_STACKTRACE); |
276 writer.write_count(1); |
277 writer.write_count(1); |
277 ObjectSampleCheckpoint::write_stacktrace(stack_trace, writer); |
278 ObjectSampleCheckpoint::write_stacktrace(stack_trace, writer); |
278 blob = writer.move(); |
279 blob = writer.move(); |
279 _cache.put(sample, blob); |
280 _cache.put(sample, blob); |
289 } |
290 } |
290 } |
291 } |
291 |
292 |
292 // caller needs ResourceMark |
293 // caller needs ResourceMark |
293 void ObjectSampleCheckpoint::on_rotation(const ObjectSampler* sampler, JfrStackTraceRepository& stack_trace_repo) { |
294 void ObjectSampleCheckpoint::on_rotation(const ObjectSampler* sampler, JfrStackTraceRepository& stack_trace_repo) { |
|
295 assert(JfrStream_lock->owned_by_self(), "invariant"); |
294 assert(sampler != NULL, "invariant"); |
296 assert(sampler != NULL, "invariant"); |
295 assert(LeakProfiler::is_running(), "invariant"); |
297 assert(LeakProfiler::is_running(), "invariant"); |
296 install_stack_traces(sampler, stack_trace_repo); |
298 install_stack_traces(sampler, stack_trace_repo); |
297 } |
299 } |
298 |
300 |
386 }; |
388 }; |
387 |
389 |
388 static void write_sample_blobs(const ObjectSampler* sampler, bool emit_all, Thread* thread) { |
390 static void write_sample_blobs(const ObjectSampler* sampler, bool emit_all, Thread* thread) { |
389 // sample set is predicated on time of last sweep |
391 // sample set is predicated on time of last sweep |
390 const jlong last_sweep = emit_all ? max_jlong : sampler->last_sweep().value(); |
392 const jlong last_sweep = emit_all ? max_jlong : sampler->last_sweep().value(); |
391 JfrCheckpointWriter writer(false, false, thread); |
393 JfrCheckpointWriter writer(thread, false); |
392 BlobWriter cbw(sampler, writer, last_sweep); |
394 BlobWriter cbw(sampler, writer, last_sweep); |
393 iterate_samples(cbw, true); |
395 iterate_samples(cbw, true); |
394 // reset blob write states |
396 // reset blob write states |
395 cbw.set_reset(); |
397 cbw.set_reset(); |
396 iterate_samples(cbw, true); |
398 iterate_samples(cbw, true); |
397 } |
399 } |
398 |
400 |
399 void ObjectSampleCheckpoint::write(const ObjectSampler* sampler, EdgeStore* edge_store, bool emit_all, Thread* thread) { |
401 void ObjectSampleCheckpoint::write(const ObjectSampler* sampler, EdgeStore* edge_store, bool emit_all, Thread* thread) { |
|
402 assert_locked_or_safepoint(JfrStream_lock); |
400 assert(sampler != NULL, "invariant"); |
403 assert(sampler != NULL, "invariant"); |
401 assert(edge_store != NULL, "invariant"); |
404 assert(edge_store != NULL, "invariant"); |
402 assert(thread != NULL, "invariant"); |
405 assert(thread != NULL, "invariant"); |
403 write_sample_blobs(sampler, emit_all, thread); |
406 write_sample_blobs(sampler, emit_all, thread); |
404 // write reference chains |
407 // write reference chains |
405 if (!edge_store->is_empty()) { |
408 if (!edge_store->is_empty()) { |
406 JfrCheckpointWriter writer(false, true, thread); |
409 JfrCheckpointWriter writer(thread); |
407 ObjectSampleWriter osw(writer, edge_store); |
410 ObjectSampleWriter osw(writer, edge_store); |
408 edge_store->iterate(osw); |
411 edge_store->iterate(osw); |
409 } |
412 } |
410 } |
413 } |
411 |
414 |