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 { |
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 } |