src/hotspot/share/jfr/recorder/repository/jfrChunkWriter.cpp
changeset 59226 a0f39cc47387
parent 58863 c16ac7a2eba4
equal deleted inserted replaced
59225:80e1201f6c9a 59226:a0f39cc47387
    39 static const int64_t START_NANOS_OFFSET = METADATA_OFFSET + SLOT_SIZE;
    39 static const int64_t START_NANOS_OFFSET = METADATA_OFFSET + SLOT_SIZE;
    40 static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE;
    40 static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE;
    41 static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE;
    41 static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE;
    42 static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE;
    42 static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE;
    43 static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE;
    43 static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE;
    44 static const int64_t CAPABILITY_OFFSET = GENERATION_OFFSET + 2;
    44 static const int64_t FLAG_OFFSET = GENERATION_OFFSET + 2;
    45 static const int64_t HEADER_SIZE = CAPABILITY_OFFSET + 2;
    45 static const int64_t HEADER_SIZE = FLAG_OFFSET + 2;
    46 
    46 
    47 static fio_fd open_chunk(const char* path) {
    47 static fio_fd open_chunk(const char* path) {
    48   return path != NULL ? os::open(path, O_CREAT | O_RDWR, S_IREAD | S_IWRITE) : invalid_fd;
    48   return path != NULL ? os::open(path, O_CREAT | O_RDWR, S_IREAD | S_IWRITE) : invalid_fd;
    49 }
    49 }
    50 
    50 
   115   void write_guard_flush() {
   115   void write_guard_flush() {
   116     write_guard();
   116     write_guard();
   117     _writer->flush();
   117     _writer->flush();
   118   }
   118   }
   119 
   119 
   120   void write_capabilities() {
   120   void write_flags() {
   121     _writer->be_write(_chunk->capabilities());
   121     _writer->be_write(_chunk->flags());
   122   }
   122   }
   123 
   123 
   124   void write_size_to_generation(int64_t size, bool finalize) {
   124   void write_size_to_generation(int64_t size, bool finalize) {
   125     write_size(size);
   125     write_size(size);
   126     write_checkpoint();
   126     write_checkpoint();
   133   void flush(int64_t size, bool finalize) {
   133   void flush(int64_t size, bool finalize) {
   134     assert(_writer->is_valid(), "invariant");
   134     assert(_writer->is_valid(), "invariant");
   135     assert(_chunk != NULL, "invariant");
   135     assert(_chunk != NULL, "invariant");
   136     DEBUG_ONLY(assert_writer_position(_writer, SIZE_OFFSET);)
   136     DEBUG_ONLY(assert_writer_position(_writer, SIZE_OFFSET);)
   137     write_size_to_generation(size, finalize);
   137     write_size_to_generation(size, finalize);
   138     // no need to write capabilities
   138     write_flags();
   139     _writer->seek(size); // implicit flush
   139     _writer->seek(size); // implicit flush
   140   }
   140   }
   141 
   141 
   142   void initialize() {
   142   void initialize() {
   143     assert(_writer->is_valid(), "invariant");
   143     assert(_writer->is_valid(), "invariant");
   144     assert(_chunk != NULL, "invariant");
   144     assert(_chunk != NULL, "invariant");
   145     DEBUG_ONLY(assert_writer_position(_writer, 0);)
   145     DEBUG_ONLY(assert_writer_position(_writer, 0);)
   146     write_magic();
   146     write_magic();
   147     write_version();
   147     write_version();
   148     write_size_to_generation(HEADER_SIZE, false);
   148     write_size_to_generation(HEADER_SIZE, false);
   149     write_capabilities();
   149     write_flags();
   150     DEBUG_ONLY(assert_writer_position(_writer, HEADER_SIZE);)
   150     DEBUG_ONLY(assert_writer_position(_writer, HEADER_SIZE);)
   151     _writer->flush();
   151     _writer->flush();
   152   }
   152   }
   153 
   153 
   154   JfrChunkHeadWriter(JfrChunkWriter* writer, int64_t offset, bool guard = true) : _writer(writer), _chunk(writer->_chunk) {
   154   JfrChunkHeadWriter(JfrChunkWriter* writer, int64_t offset, bool guard = true) : _writer(writer), _chunk(writer->_chunk) {
   199   be_write(event_size_offset); // last checkpoint offset will be this checkpoint
   199   be_write(event_size_offset); // last checkpoint offset will be this checkpoint
   200   head.write_metadata();
   200   head.write_metadata();
   201   head.write_time(false);
   201   head.write_time(false);
   202   head.write_cpu_frequency();
   202   head.write_cpu_frequency();
   203   head.write_next_generation();
   203   head.write_next_generation();
   204   head.write_capabilities();
   204   head.write_flags();
   205   assert(current_offset() - header_content_pos == HEADER_SIZE, "invariant");
   205   assert(current_offset() - header_content_pos == HEADER_SIZE, "invariant");
   206   const u4 checkpoint_size = current_offset() - event_size_offset;
   206   const u4 checkpoint_size = current_offset() - event_size_offset;
   207   write_padded_at_offset<u4>(checkpoint_size, event_size_offset);
   207   write_padded_at_offset<u4>(checkpoint_size, event_size_offset);
   208   set_last_checkpoint_offset(event_size_offset);
   208   set_last_checkpoint_offset(event_size_offset);
   209   const size_t sz_written = size_written();
   209   const size_t sz_written = size_written();
   210   write_be_at_offset(sz_written, chunk_size_offset);
   210   write_be_at_offset(sz_written, chunk_size_offset);
   211   return sz_written;
   211   return sz_written;
   212 }
   212 }
   213 
   213 
       
   214 void JfrChunkWriter::mark_chunk_final() {
       
   215   assert(_chunk != NULL, "invariant");
       
   216   _chunk->mark_final();
       
   217 }
       
   218 
   214 int64_t JfrChunkWriter::flush_chunk(bool flushpoint) {
   219 int64_t JfrChunkWriter::flush_chunk(bool flushpoint) {
   215   assert(_chunk != NULL, "invariant");
   220   assert(_chunk != NULL, "invariant");
   216   const int64_t sz_written = write_chunk_header_checkpoint(flushpoint);
   221   const int64_t sz_written = write_chunk_header_checkpoint(flushpoint);
   217   assert(size_written() == sz_written, "invariant");
   222   assert(size_written() == sz_written, "invariant");
   218   JfrChunkHeadWriter head(this, SIZE_OFFSET);
   223   JfrChunkHeadWriter head(this, SIZE_OFFSET);