src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp
branchJEP-349-branch
changeset 57872 7aa1b3d6ff8f
parent 57870 00860d9caf4d
child 57873 68134337dbf8
equal deleted inserted replaced
57871:7d2478b04e95 57872:7aa1b3d6ff8f
   293 }
   293 }
   294 
   294 
   295 template <typename Functor>
   295 template <typename Functor>
   296 static u4 invoke_with_flush_event(Functor& f) {
   296 static u4 invoke_with_flush_event(Functor& f) {
   297   const u4 elements = invoke(f);
   297   const u4 elements = invoke(f);
   298   if (elements != 0) {
   298   write_flush_event(f);
   299     write_flush_event(f);
       
   300   }
       
   301   return elements;
   299   return elements;
   302 }
   300 }
   303 
   301 
   304 template <typename Instance, void(Instance::*func)()>
   302 template <typename Instance, void(Instance::*func)()>
   305 class JfrVMOperation : public VM_Operation {
   303 class JfrVMOperation : public VM_Operation {
   608   const size_t storage_elements = flush_storage(_storage, _chunkwriter);
   606   const size_t storage_elements = flush_storage(_storage, _chunkwriter);
   609   if (0 == storage_elements) {
   607   if (0 == storage_elements) {
   610     return total_elements;
   608     return total_elements;
   611   }
   609   }
   612   total_elements += storage_elements;
   610   total_elements += storage_elements;
   613   total_elements += flush_stacktrace(_stack_trace_repository, _chunkwriter);
   611   if (_stack_trace_repository.is_modified()) {
   614   if (_string_pool.modified()) {
   612     total_elements += flush_stacktrace(_stack_trace_repository, _chunkwriter);
       
   613   }
       
   614   if (_string_pool.is_modified()) {
   615     total_elements += flush_stringpool(_string_pool, _chunkwriter);
   615     total_elements += flush_stringpool(_string_pool, _chunkwriter);
   616   }
   616   }
   617   total_elements += flush_typeset(_checkpoint_manager, _chunkwriter);
   617   total_elements += flush_typeset(_checkpoint_manager, _chunkwriter);
   618   return total_elements;
   618   return total_elements;
   619 }
   619 }
   620 
   620 
   621 void JfrRecorderService::flush(int msgs) {
   621 void JfrRecorderService::flush(int msgs) {
   622   assert(_chunkwriter.is_valid(), "invariant");
   622   assert(_chunkwriter.is_valid(), "invariant");
   623   ResourceMark rm;
   623   ResourceMark rm;
   624   HandleMark hm;
   624   HandleMark hm;
       
   625   write_metadata_in_flushpoint = (msgs & MSGBIT(MSG_FLUSHPOINT_METADATA));
       
   626   ++flushpoint_id;
   625   reset_thread_local_buffer();
   627   reset_thread_local_buffer();
   626   ++flushpoint_id;
       
   627   write_metadata_in_flushpoint = (msgs & MSGBIT(MSG_FLUSHPOINT_METADATA));
       
   628   FlushFunctor flushpoint(*this);
   628   FlushFunctor flushpoint(*this);
   629   Flush fl(_chunkwriter, flushpoint);
   629   Flush fl(_chunkwriter, flushpoint);
   630   invoke_with_flush_event(fl);
   630   invoke_with_flush_event(fl);
   631   write_thread_local_buffer(_chunkwriter);
   631   write_thread_local_buffer(_chunkwriter);
   632   _checkpoint_manager.flush();
       
   633   _repository.flush_chunk();
   632   _repository.flush_chunk();
   634 }
   633 }
   635 
   634 
   636 //
   635 //
   637 // pre-safepoint write sequence
   636 // pre-safepoint write sequence
   641 //      notify about pending rotation ->
   640 //      notify about pending rotation ->
   642 //        write storage
   641 //        write storage
   643 //
   642 //
   644 void JfrRecorderService::pre_safepoint_write() {
   643 void JfrRecorderService::pre_safepoint_write() {
   645   assert(_chunkwriter.is_valid(), "invariant");
   644   assert(_chunkwriter.is_valid(), "invariant");
   646   flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, false);
   645   if (_stack_trace_repository.is_modified()) {
   647   if (_string_pool.modified()) {
   646     flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, false);
       
   647   }
       
   648   if (_string_pool.is_modified()) {
   648     flush_stringpool_checkpoint(_string_pool, _chunkwriter);
   649     flush_stringpool_checkpoint(_string_pool, _chunkwriter);
   649   }
   650   }
   650   if (LeakProfiler::is_running()) {
   651   if (LeakProfiler::is_running()) {
   651     // Exclusive access to the object sampler instance.
   652     // Exclusive access to the object sampler instance.
   652     // The sampler is released (unlocked) later in post_safepoint_write.
   653     // The sampler is released (unlocked) later in post_safepoint_write.
   672 //           shift_epoch ->
   673 //           shift_epoch ->
   673 //             update time
   674 //             update time
   674 //
   675 //
   675 void JfrRecorderService::safepoint_write() {
   676 void JfrRecorderService::safepoint_write() {
   676   assert(SafepointSynchronize::is_at_safepoint(), "invariant");
   677   assert(SafepointSynchronize::is_at_safepoint(), "invariant");
   677 
       
   678   flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, true);
   678   flush_stacktrace_checkpoint(_stack_trace_repository, _chunkwriter, true);
   679   if (_string_pool.modified()) {
   679   if (_string_pool.is_modified()) {
   680     flush_stringpool_checkpoint_safepoint(_string_pool, _chunkwriter);
   680     flush_stringpool_checkpoint_safepoint(_string_pool, _chunkwriter);
   681   }
   681   }
   682   if (LeakProfiler::is_running()) {
   682   if (LeakProfiler::is_running()) {
   683     ObjectSampleCheckpoint::resolve_sampled_objects();
   683     ObjectSampleCheckpoint::resolve_sampled_objects();
   684   }
   684   }