< prev index next >

src/hotspot/share/jfr/leakprofiler/checkpoint/eventEmitter.cpp

Print this page

 27 #include "jfr/jfrEvents.hpp"
 28 #include "jfr/leakprofiler/chains/edgeStore.hpp"
 29 #include "jfr/leakprofiler/chains/pathToGcRootsOperation.hpp"
 30 #include "jfr/leakprofiler/checkpoint/eventEmitter.hpp"
 31 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
 32 #include "jfr/leakprofiler/sampling/objectSample.hpp"
 33 #include "jfr/leakprofiler/sampling/objectSampler.hpp"
 34 #include "jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp"
 35 #include "logging/log.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "oops/markWord.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "runtime/mutexLocker.hpp"
 40 #include "runtime/thread.inline.hpp"
 41 #include "runtime/vmThread.hpp"
 42 
 43 EventEmitter::EventEmitter(const JfrTicks& start_time, const JfrTicks& end_time) :
 44   _start_time(start_time),
 45   _end_time(end_time),
 46   _thread(Thread::current()),
 47   _jfr_thread_local(_thread->jfr_thread_local()),
 48   _thread_id(_thread->jfr_thread_local()->thread_id()) {}
 49 
 50 EventEmitter::~EventEmitter() {
 51   // restore / reset thread local stack trace and thread id
 52   _jfr_thread_local->set_thread_id(_thread_id);
 53   _jfr_thread_local->clear_cached_stack_trace();

 54 }
 55 
 56 void EventEmitter::emit(ObjectSampler* sampler, int64_t cutoff_ticks, bool emit_all, bool skip_bfs) {
 57   assert(sampler != NULL, "invariant");
 58   ResourceMark rm;
 59   EdgeStore edge_store;
 60   if (cutoff_ticks <= 0) {
 61     // no reference chains
 62     JfrTicks time_stamp = JfrTicks::now();
 63     EventEmitter emitter(time_stamp, time_stamp);
 64     emitter.write_events(sampler, &edge_store, emit_all);
 65     return;
 66   }
 67   // events emitted with reference chains require a safepoint operation
 68   PathToGcRootsOperation op(sampler, &edge_store, cutoff_ticks, emit_all, skip_bfs);
 69   VMThread::execute(&op);
 70 }
 71 
 72 size_t EventEmitter::write_events(ObjectSampler* object_sampler, EdgeStore* edge_store, bool emit_all) {
 73   assert(_thread == Thread::current(), "invariant");

158 
159   EventOldObjectSample e(UNTIMED);
160   e.set_starttime(_start_time);
161   e.set_endtime(_end_time);
162   e.set_allocationTime(sample->allocation_time());
163   e.set_objectSize(sample->allocated());
164   e.set_objectAge(object_age);
165   e.set_lastKnownHeapUsage(sample->heap_used_at_last_gc());
166   e.set_object(object_id);
167   e.set_arrayElements(array_size(edge->pointee()));
168   e.set_root(gc_root_id);
169 
170   // Temporarily assigning both the stack trace id and thread id
171   // onto the thread local data structure of the emitter thread (for the duration
172   // of the commit() call). This trick provides a means to override
173   // the event generation mechanism by injecting externally provided id's.
174   // At this particular location, it allows us to emit an old object event
175   // supplying information from where the actual sampling occurred.
176   _jfr_thread_local->set_cached_stack_trace_id(sample->stack_trace_id());
177   assert(sample->has_thread(), "invariant");
178   _jfr_thread_local->set_thread_id(sample->thread_id());
179   e.commit();
180 }

 27 #include "jfr/jfrEvents.hpp"
 28 #include "jfr/leakprofiler/chains/edgeStore.hpp"
 29 #include "jfr/leakprofiler/chains/pathToGcRootsOperation.hpp"
 30 #include "jfr/leakprofiler/checkpoint/eventEmitter.hpp"
 31 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp"
 32 #include "jfr/leakprofiler/sampling/objectSample.hpp"
 33 #include "jfr/leakprofiler/sampling/objectSampler.hpp"
 34 #include "jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp"
 35 #include "logging/log.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "oops/markWord.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "runtime/mutexLocker.hpp"
 40 #include "runtime/thread.inline.hpp"
 41 #include "runtime/vmThread.hpp"
 42 
 43 EventEmitter::EventEmitter(const JfrTicks& start_time, const JfrTicks& end_time) :
 44   _start_time(start_time),
 45   _end_time(end_time),
 46   _thread(Thread::current()),
 47   _jfr_thread_local(_thread->jfr_thread_local()) {}

 48 
 49 EventEmitter::~EventEmitter() {
 50   // restore / reset thread local stack trace and thread id

 51   _jfr_thread_local->clear_cached_stack_trace();
 52   JfrThreadLocal::stop_impersonating(_thread);
 53 }
 54 
 55 void EventEmitter::emit(ObjectSampler* sampler, int64_t cutoff_ticks, bool emit_all, bool skip_bfs) {
 56   assert(sampler != NULL, "invariant");
 57   ResourceMark rm;
 58   EdgeStore edge_store;
 59   if (cutoff_ticks <= 0) {
 60     // no reference chains
 61     JfrTicks time_stamp = JfrTicks::now();
 62     EventEmitter emitter(time_stamp, time_stamp);
 63     emitter.write_events(sampler, &edge_store, emit_all);
 64     return;
 65   }
 66   // events emitted with reference chains require a safepoint operation
 67   PathToGcRootsOperation op(sampler, &edge_store, cutoff_ticks, emit_all, skip_bfs);
 68   VMThread::execute(&op);
 69 }
 70 
 71 size_t EventEmitter::write_events(ObjectSampler* object_sampler, EdgeStore* edge_store, bool emit_all) {
 72   assert(_thread == Thread::current(), "invariant");

157 
158   EventOldObjectSample e(UNTIMED);
159   e.set_starttime(_start_time);
160   e.set_endtime(_end_time);
161   e.set_allocationTime(sample->allocation_time());
162   e.set_objectSize(sample->allocated());
163   e.set_objectAge(object_age);
164   e.set_lastKnownHeapUsage(sample->heap_used_at_last_gc());
165   e.set_object(object_id);
166   e.set_arrayElements(array_size(edge->pointee()));
167   e.set_root(gc_root_id);
168 
169   // Temporarily assigning both the stack trace id and thread id
170   // onto the thread local data structure of the emitter thread (for the duration
171   // of the commit() call). This trick provides a means to override
172   // the event generation mechanism by injecting externally provided id's.
173   // At this particular location, it allows us to emit an old object event
174   // supplying information from where the actual sampling occurred.
175   _jfr_thread_local->set_cached_stack_trace_id(sample->stack_trace_id());
176   assert(sample->has_thread(), "invariant");
177   JfrThreadLocal::impersonate(_thread, sample->thread_id());
178   e.commit();
179 }
< prev index next >