src/hotspot/share/jfr/recorder/repository/jfrRepository.cpp
changeset 53897 0abec72a3ac2
parent 53762 65deccd64f3a
child 54263 3cabb47758c9
equal deleted inserted replaced
53896:b47fd614c75e 53897:0abec72a3ac2
   145   // "YYYY-MM-DDTHH:MM:SS"
   145   // "YYYY-MM-DDTHH:MM:SS"
   146   buffer[iso8601_len] = '\0';
   146   buffer[iso8601_len] = '\0';
   147   iso8601_to_date_time(buffer);
   147   iso8601_to_date_time(buffer);
   148 }
   148 }
   149 
   149 
   150 static jlong file_size(fio_fd fd) {
   150 static int64_t file_size(fio_fd fd) {
   151   assert(fd != invalid_fd, "invariant");
   151   assert(fd != invalid_fd, "invariant");
   152   const jlong current_offset = os::current_file_offset(fd);
   152   const int64_t current_offset = os::current_file_offset(fd);
   153   const jlong size = os::lseek(fd, 0, SEEK_END);
   153   const int64_t size = os::lseek(fd, 0, SEEK_END);
   154   os::seek_to_file_offset(fd, current_offset);
   154   os::seek_to_file_offset(fd, current_offset);
   155   return size;
   155   return size;
   156 }
   156 }
   157 
   157 
   158 class RepositoryIterator : public StackObj {
   158 class RepositoryIterator : public StackObj {
   216   }
   216   }
   217   const fio_fd entry_fd = open_existing(fully_qualified_path_entry);
   217   const fio_fd entry_fd = open_existing(fully_qualified_path_entry);
   218   if (invalid_fd == entry_fd) {
   218   if (invalid_fd == entry_fd) {
   219     return NULL;
   219     return NULL;
   220   }
   220   }
   221   const jlong entry_size = file_size(entry_fd);
   221   const int64_t entry_size = file_size(entry_fd);
   222   os::close(entry_fd);
   222   os::close(entry_fd);
   223   if (0 == entry_size) {
   223   if (0 == entry_size) {
   224     return NULL;
   224     return NULL;
   225   }
   225   }
   226   return entry_name;
   226   return entry_name;
   258   while (has_next()) {
   258   while (has_next()) {
   259     log_error(jfr, system)( "%s", next());
   259     log_error(jfr, system)( "%s", next());
   260   }
   260   }
   261 }
   261 }
   262 #endif
   262 #endif
       
   263 
   263 bool RepositoryIterator::has_next() const {
   264 bool RepositoryIterator::has_next() const {
   264   return (_files != NULL && _iterator < _files->length());
   265   return (_files != NULL && _iterator < _files->length());
   265 }
   266 }
   266 
   267 
   267 const char* const RepositoryIterator::next() const {
   268 const char* const RepositoryIterator::next() const {
   273   const size_t size_of_file_copy_block = 1 * M; // 1 mb
   274   const size_t size_of_file_copy_block = 1 * M; // 1 mb
   274   jbyte* const file_copy_block = NEW_RESOURCE_ARRAY_RETURN_NULL(jbyte, size_of_file_copy_block);
   275   jbyte* const file_copy_block = NEW_RESOURCE_ARRAY_RETURN_NULL(jbyte, size_of_file_copy_block);
   275   if (file_copy_block == NULL) {
   276   if (file_copy_block == NULL) {
   276     return;
   277     return;
   277   }
   278   }
   278  jlong bytes_written_total = 0;
   279  int64_t bytes_written_total = 0;
   279   while (iterator.has_next()) {
   280   while (iterator.has_next()) {
   280     fio_fd current_fd = invalid_fd;
   281     fio_fd current_fd = invalid_fd;
   281     const char* const fqn = iterator.next();
   282     const char* const fqn = iterator.next();
   282     if (fqn != NULL) {
   283     if (fqn != NULL) {
   283       current_fd = open_existing(fqn);
   284       current_fd = open_existing(fqn);
   284       if (current_fd != invalid_fd) {
   285       if (current_fd != invalid_fd) {
   285         const jlong current_filesize = file_size(current_fd);
   286         const int64_t current_filesize = file_size(current_fd);
   286         assert(current_filesize > 0, "invariant");
   287         assert(current_filesize > 0, "invariant");
   287         jlong bytes_read = 0;
   288         int64_t bytes_read = 0;
   288         jlong bytes_written = 0;
   289         int64_t bytes_written = 0;
   289         while (bytes_read < current_filesize) {
   290         while (bytes_read < current_filesize) {
   290           bytes_read += (jlong)os::read_at(current_fd, file_copy_block, size_of_file_copy_block, bytes_read);
   291           const ssize_t read_result = os::read_at(current_fd, file_copy_block, size_of_file_copy_block, bytes_read);
   291           assert(bytes_read - bytes_written <= (jlong)size_of_file_copy_block, "invariant");
   292           if (-1 == read_result) {
   292           bytes_written += (jlong)os::write(emergency_fd, file_copy_block, bytes_read - bytes_written);
   293             log_info(jfr) ( // For user, should not be "jfr, system"
       
   294               "Unable to recover JFR data");
       
   295             break;
       
   296           }
       
   297           bytes_read += (int64_t)read_result;
       
   298           assert(bytes_read - bytes_written <= (int64_t)size_of_file_copy_block, "invariant");
       
   299           bytes_written += (int64_t)os::write(emergency_fd, file_copy_block, bytes_read - bytes_written);
   293           assert(bytes_read == bytes_written, "invariant");
   300           assert(bytes_read == bytes_written, "invariant");
   294         }
   301         }
   295         os::close(current_fd);
   302         os::close(current_fd);
   296         bytes_written_total += bytes_written;
   303         bytes_written_total += bytes_written;
   297       }
   304       }
   466     _chunkwriter->set_chunk_path(path);
   473     _chunkwriter->set_chunk_path(path);
   467   }
   474   }
   468   return _chunkwriter->open();
   475   return _chunkwriter->open();
   469 }
   476 }
   470 
   477 
   471 size_t JfrRepository::close_chunk(jlong metadata_offset) {
   478 size_t JfrRepository::close_chunk(int64_t metadata_offset) {
   472   return _chunkwriter->close(metadata_offset);
   479   return _chunkwriter->close(metadata_offset);
   473 }
   480 }