src/share/vm/jfr/recorder/repository/jfrRepository.cpp

changeset 9947
db357034b763
parent 9880
3549c2f110d2
equal deleted inserted replaced
9946:103d1261f1f4 9947:db357034b763
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 if (true) tty->print_cr( "%s", next()); 259 if (true) tty->print_cr( "%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 if (LogJFR) tty->print_cr("Unable to recover JFR data");
294 break;
295 }
296 bytes_read += (int64_t)read_result;
297 assert(bytes_read - bytes_written <= (int64_t)size_of_file_copy_block, "invariant");
298 bytes_written += (int64_t)os::write(emergency_fd, file_copy_block, bytes_read - bytes_written);
293 assert(bytes_read == bytes_written, "invariant"); 299 assert(bytes_read == bytes_written, "invariant");
294 } 300 }
295 os::close(current_fd); 301 os::close(current_fd);
296 bytes_written_total += bytes_written; 302 bytes_written_total += bytes_written;
297 } 303 }
466 _chunkwriter->set_chunk_path(path); 472 _chunkwriter->set_chunk_path(path);
467 } 473 }
468 return _chunkwriter->open(); 474 return _chunkwriter->open();
469 } 475 }
470 476
471 size_t JfrRepository::close_chunk(jlong metadata_offset) { 477 size_t JfrRepository::close_chunk(int64_t metadata_offset) {
472 return _chunkwriter->close(metadata_offset); 478 return _chunkwriter->close(metadata_offset);
473 } 479 }

mercurial