apetushkov@9858: /* mikael@9880: * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #include "precompiled.hpp" apetushkov@9858: #include "jfr/jfr.hpp" apetushkov@9858: #include "jfr/jni/jfrJavaSupport.hpp" apetushkov@9858: #include "jfr/recorder/jfrRecorder.hpp" apetushkov@9858: #include "jfr/recorder/repository/jfrChunkState.hpp" apetushkov@9858: #include "jfr/recorder/repository/jfrChunkWriter.hpp" apetushkov@9858: #include "jfr/recorder/repository/jfrRepository.hpp" apetushkov@9858: #include "jfr/recorder/service/jfrPostBox.hpp" apetushkov@9858: #include "memory/resourceArea.hpp" apetushkov@9858: #include "runtime/mutex.hpp" apetushkov@9858: #include "runtime/arguments.hpp" apetushkov@9858: #include "runtime/os.hpp" apetushkov@9858: #include "runtime/thread.inline.hpp" apetushkov@9858: apetushkov@9858: static JfrRepository* _instance = NULL; apetushkov@9858: apetushkov@9858: JfrRepository& JfrRepository::instance() { apetushkov@9858: return *_instance; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static JfrChunkWriter* _chunkwriter = NULL; apetushkov@9858: apetushkov@9858: static bool initialize_chunkwriter() { apetushkov@9858: assert(_chunkwriter == NULL, "invariant"); apetushkov@9858: _chunkwriter = new JfrChunkWriter(); apetushkov@9858: return _chunkwriter != NULL && _chunkwriter->initialize(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrChunkWriter& JfrRepository::chunkwriter() { apetushkov@9858: return *_chunkwriter; apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrRepository::JfrRepository(JfrPostBox& post_box) : _path(NULL), _post_box(post_box) {} apetushkov@9858: apetushkov@9858: bool JfrRepository::initialize() { apetushkov@9858: return initialize_chunkwriter(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrRepository::~JfrRepository() { apetushkov@9858: if (_path != NULL) { apetushkov@9858: JfrCHeapObj::free(_path, strlen(_path) + 1); apetushkov@9858: _path = NULL; apetushkov@9858: } apetushkov@9858: apetushkov@9858: if (_chunkwriter != NULL) { apetushkov@9858: delete _chunkwriter; apetushkov@9858: _chunkwriter = NULL; apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrRepository* JfrRepository::create(JfrPostBox& post_box) { apetushkov@9858: assert(_instance == NULL, "invariant"); apetushkov@9858: _instance = new JfrRepository(post_box); apetushkov@9858: return _instance; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrRepository::destroy() { apetushkov@9858: assert(_instance != NULL, "invariant"); apetushkov@9858: delete _instance; apetushkov@9858: _instance = NULL; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char vm_error_filename_fmt[] = "hs_err_pid%p.jfr"; apetushkov@9858: static const char vm_oom_filename_fmt[] = "hs_oom_pid%p.jfr"; apetushkov@9858: static const char vm_soe_filename_fmt[] = "hs_soe_pid%p.jfr"; apetushkov@9858: static const char chunk_file_jfr_ext[] = ".jfr"; apetushkov@9858: static const size_t iso8601_len = 19; // "YYYY-MM-DDTHH:MM:SS" apetushkov@9858: apetushkov@9858: static fio_fd open_exclusivly(const char* path) { apetushkov@9858: return os::open(path, O_CREAT | O_WRONLY, S_IREAD | S_IWRITE); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static fio_fd open_existing(const char* path) { apetushkov@9858: return os::open(path, O_RDWR, S_IREAD | S_IWRITE); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static int file_sort(const char** const file1, const char** file2) { apetushkov@9858: assert(NULL != *file1 && NULL != *file2, "invariant"); apetushkov@9858: int cmp = strncmp(*file1, *file2, iso8601_len); apetushkov@9858: if (0 == cmp) { apetushkov@9858: const char* const dot1 = strchr(*file1, '.'); apetushkov@9858: assert(NULL != dot1, "invariant"); apetushkov@9858: const char* const dot2 = strchr(*file2, '.'); apetushkov@9858: assert(NULL != dot2, "invariant"); apetushkov@9858: ptrdiff_t file1_len = dot1 - *file1; apetushkov@9858: ptrdiff_t file2_len = dot2 - *file2; apetushkov@9858: if (file1_len < file2_len) { apetushkov@9858: return -1; apetushkov@9858: } apetushkov@9858: if (file1_len > file2_len) { apetushkov@9858: return 1; apetushkov@9858: } apetushkov@9858: assert(file1_len == file2_len, "invariant"); apetushkov@9858: cmp = strncmp(*file1, *file2, file1_len); apetushkov@9858: } apetushkov@9858: assert(cmp != 0, "invariant"); apetushkov@9858: return cmp; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void iso8601_to_date_time(char* iso8601_str) { apetushkov@9858: assert(iso8601_str != NULL, "invariant"); apetushkov@9858: assert(strlen(iso8601_str) == iso8601_len, "invariant"); apetushkov@9858: // "YYYY-MM-DDTHH:MM:SS" apetushkov@9858: for (size_t i = 0; i < iso8601_len; ++i) { apetushkov@9858: switch(iso8601_str[i]) { apetushkov@9858: case 'T' : apetushkov@9858: case '-' : apetushkov@9858: case ':' : apetushkov@9858: iso8601_str[i] = '_'; apetushkov@9858: break; apetushkov@9858: } apetushkov@9858: } apetushkov@9858: // "YYYY_MM_DD_HH_MM_SS" apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void date_time(char* buffer, size_t buffer_len) { apetushkov@9858: assert(buffer != NULL, "invariant"); apetushkov@9858: assert(buffer_len >= iso8601_len, "buffer too small"); apetushkov@9858: os::iso8601_time(buffer, buffer_len); apetushkov@9858: assert(strlen(buffer) >= iso8601_len + 1, "invariant"); apetushkov@9858: // "YYYY-MM-DDTHH:MM:SS" apetushkov@9858: buffer[iso8601_len] = '\0'; apetushkov@9858: iso8601_to_date_time(buffer); apetushkov@9858: } apetushkov@9858: bulasevich@9947: static int64_t file_size(fio_fd fd) { apetushkov@9858: assert(fd != invalid_fd, "invariant"); bulasevich@9947: const int64_t current_offset = os::current_file_offset(fd); bulasevich@9947: const int64_t size = os::lseek(fd, 0, SEEK_END); apetushkov@9858: os::seek_to_file_offset(fd, current_offset); apetushkov@9858: return size; apetushkov@9858: } apetushkov@9858: apetushkov@9858: class RepositoryIterator : public StackObj { apetushkov@9858: private: apetushkov@9858: const char* const _repo; apetushkov@9858: const size_t _repository_len; apetushkov@9858: GrowableArray* _files; apetushkov@9858: const char* const fully_qualified(const char* entry) const; apetushkov@9858: mutable int _iterator; apetushkov@9858: apetushkov@9858: public: apetushkov@9858: RepositoryIterator(const char* repository, size_t repository_len); apetushkov@9858: ~RepositoryIterator() {} apetushkov@9858: debug_only(void print_repository_files() const;) apetushkov@9858: const char* const filter(const char* entry) const; apetushkov@9858: bool has_next() const; apetushkov@9858: const char* const next() const; apetushkov@9858: }; apetushkov@9858: apetushkov@9858: const char* const RepositoryIterator::fully_qualified(const char* entry) const { apetushkov@9858: assert(NULL != entry, "invariant"); apetushkov@9858: char* file_path_entry = NULL; apetushkov@9858: // only use files that have content, not placeholders apetushkov@9858: const char* const file_separator = os::file_separator(); apetushkov@9858: if (NULL != file_separator) { apetushkov@9858: const size_t entry_len = strlen(entry); apetushkov@9858: const size_t file_separator_length = strlen(file_separator); apetushkov@9858: const size_t file_path_entry_length = _repository_len + file_separator_length + entry_len; apetushkov@9858: file_path_entry = NEW_RESOURCE_ARRAY_RETURN_NULL(char, file_path_entry_length + 1); apetushkov@9858: if (NULL == file_path_entry) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: int position = 0; apetushkov@9858: position += jio_snprintf(&file_path_entry[position], _repository_len + 1, "%s", _repo); apetushkov@9858: position += jio_snprintf(&file_path_entry[position], file_separator_length + 1, "%s", os::file_separator()); apetushkov@9858: position += jio_snprintf(&file_path_entry[position], entry_len + 1, "%s", entry); apetushkov@9858: file_path_entry[position] = '\0'; apetushkov@9858: assert((size_t)position == file_path_entry_length, "invariant"); apetushkov@9858: assert(strlen(file_path_entry) == (size_t)position, "invariant"); apetushkov@9858: } apetushkov@9858: return file_path_entry; apetushkov@9858: } apetushkov@9858: apetushkov@9858: const char* const RepositoryIterator::filter(const char* entry) const { apetushkov@9858: if (entry == NULL) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: const size_t entry_len = strlen(entry); apetushkov@9858: if (entry_len <= 2) { apetushkov@9858: // for "." and ".." apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: char* entry_name = NEW_RESOURCE_ARRAY_RETURN_NULL(char, entry_len + 1); apetushkov@9858: if (entry_name == NULL) { apetushkov@9858: return NULL; apetushkov@9858: } mikael@9880: strncpy(entry_name, entry, entry_len + 1); apetushkov@9858: const char* const fully_qualified_path_entry = fully_qualified(entry_name); apetushkov@9858: if (NULL == fully_qualified_path_entry) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: const fio_fd entry_fd = open_existing(fully_qualified_path_entry); apetushkov@9858: if (invalid_fd == entry_fd) { apetushkov@9858: return NULL; apetushkov@9858: } bulasevich@9947: const int64_t entry_size = file_size(entry_fd); apetushkov@9858: os::close(entry_fd); apetushkov@9858: if (0 == entry_size) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: return entry_name; apetushkov@9858: } apetushkov@9858: apetushkov@9858: RepositoryIterator::RepositoryIterator(const char* repository, size_t repository_len) : apetushkov@9858: _repo(repository), apetushkov@9858: _repository_len(repository_len), apetushkov@9858: _files(NULL), apetushkov@9858: _iterator(0) { apetushkov@9858: if (NULL != _repo) { apetushkov@9858: assert(strlen(_repo) == _repository_len, "invariant"); apetushkov@9858: _files = new GrowableArray(10); apetushkov@9858: DIR* dirp = os::opendir(_repo); apetushkov@9858: if (dirp == NULL) { apetushkov@9858: if (true) tty->print_cr("Unable to open repository %s", _repo); apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: struct dirent* dentry; apetushkov@9858: while ((dentry = os::readdir(dirp)) != NULL) { apetushkov@9858: const char* const entry_path = filter(dentry->d_name); apetushkov@9858: if (NULL != entry_path) { apetushkov@9858: _files->append(entry_path); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: os::closedir(dirp); apetushkov@9858: if (_files->length() > 1) { apetushkov@9858: _files->sort(file_sort); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: #ifdef ASSERT apetushkov@9858: void RepositoryIterator::print_repository_files() const { apetushkov@9858: while (has_next()) { apetushkov@9858: if (true) tty->print_cr( "%s", next()); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: #endif bulasevich@9947: apetushkov@9858: bool RepositoryIterator::has_next() const { apetushkov@9858: return (_files != NULL && _iterator < _files->length()); apetushkov@9858: } apetushkov@9858: apetushkov@9858: const char* const RepositoryIterator::next() const { apetushkov@9858: return _iterator >= _files->length() ? NULL : fully_qualified(_files->at(_iterator++)); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void write_emergency_file(fio_fd emergency_fd, const RepositoryIterator& iterator) { apetushkov@9858: assert(emergency_fd != invalid_fd, "invariant"); apetushkov@9858: const size_t size_of_file_copy_block = 1 * M; // 1 mb apetushkov@9858: jbyte* const file_copy_block = NEW_RESOURCE_ARRAY_RETURN_NULL(jbyte, size_of_file_copy_block); apetushkov@9858: if (file_copy_block == NULL) { apetushkov@9858: return; apetushkov@9858: } bulasevich@9947: int64_t bytes_written_total = 0; apetushkov@9858: while (iterator.has_next()) { apetushkov@9858: fio_fd current_fd = invalid_fd; apetushkov@9858: const char* const fqn = iterator.next(); apetushkov@9858: if (fqn != NULL) { apetushkov@9858: current_fd = open_existing(fqn); apetushkov@9858: if (current_fd != invalid_fd) { bulasevich@9947: const int64_t current_filesize = file_size(current_fd); apetushkov@9858: assert(current_filesize > 0, "invariant"); bulasevich@9947: int64_t bytes_read = 0; bulasevich@9947: int64_t bytes_written = 0; apetushkov@9858: while (bytes_read < current_filesize) { bulasevich@9947: const ssize_t read_result = os::read_at(current_fd, file_copy_block, size_of_file_copy_block, bytes_read); bulasevich@9947: if (-1 == read_result) { bulasevich@9947: if (LogJFR) tty->print_cr("Unable to recover JFR data"); bulasevich@9947: break; bulasevich@9947: } bulasevich@9947: bytes_read += (int64_t)read_result; bulasevich@9947: assert(bytes_read - bytes_written <= (int64_t)size_of_file_copy_block, "invariant"); bulasevich@9947: bytes_written += (int64_t)os::write(emergency_fd, file_copy_block, bytes_read - bytes_written); apetushkov@9858: assert(bytes_read == bytes_written, "invariant"); apetushkov@9858: } apetushkov@9858: os::close(current_fd); apetushkov@9858: bytes_written_total += bytes_written; apetushkov@9858: } apetushkov@9858: } apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char* create_emergency_dump_path() { apetushkov@9858: assert(JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: char* buffer = NEW_RESOURCE_ARRAY_RETURN_NULL(char, O_BUFLEN); apetushkov@9858: if (NULL == buffer) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: const char* const cwd = os::get_current_directory(buffer, O_BUFLEN); apetushkov@9858: if (NULL == cwd) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: size_t pos = strlen(cwd); apetushkov@9858: const int fsep_len = jio_snprintf(&buffer[pos], O_BUFLEN - pos, "%s", os::file_separator()); apetushkov@9858: const char* filename_fmt = NULL; apetushkov@9858: // fetch specific error cause apetushkov@9858: switch (JfrJavaSupport::cause()) { apetushkov@9858: case JfrJavaSupport::OUT_OF_MEMORY: apetushkov@9858: filename_fmt = vm_oom_filename_fmt; apetushkov@9858: break; apetushkov@9858: case JfrJavaSupport::STACK_OVERFLOW: apetushkov@9858: filename_fmt = vm_soe_filename_fmt; apetushkov@9858: break; apetushkov@9858: default: apetushkov@9858: filename_fmt = vm_error_filename_fmt; apetushkov@9858: } apetushkov@9858: char* emergency_dump_path = NULL; apetushkov@9858: pos += fsep_len; apetushkov@9858: if (Arguments::copy_expand_pid(filename_fmt, strlen(filename_fmt), &buffer[pos], O_BUFLEN - pos)) { apetushkov@9858: const size_t emergency_filename_length = strlen(buffer); apetushkov@9858: emergency_dump_path = NEW_RESOURCE_ARRAY_RETURN_NULL(char, emergency_filename_length + 1); apetushkov@9858: if (NULL == emergency_dump_path) { apetushkov@9858: return NULL; apetushkov@9858: } mikael@9880: strncpy(emergency_dump_path, buffer, emergency_filename_length + 1); apetushkov@9858: } apetushkov@9858: return emergency_dump_path; apetushkov@9858: } apetushkov@9858: apetushkov@9858: // Caller needs ResourceMark apetushkov@9858: static const char* create_emergency_chunk_path(const char* repository_base, size_t repository_len) { apetushkov@9858: assert(repository_base != NULL, "invariant"); apetushkov@9858: assert(JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: // date time apetushkov@9858: char date_time_buffer[32] = {0}; apetushkov@9858: date_time(date_time_buffer, sizeof(date_time_buffer)); apetushkov@9858: size_t date_time_len = strlen(date_time_buffer); apetushkov@9858: size_t chunkname_max_len = repository_len // repository_base apetushkov@9858: + 1 // "/" apetushkov@9858: + date_time_len // date_time apetushkov@9858: + strlen(chunk_file_jfr_ext) // .jfr apetushkov@9858: + 1; apetushkov@9858: char* chunk_path = NEW_RESOURCE_ARRAY_RETURN_NULL(char, chunkname_max_len); apetushkov@9858: if (chunk_path == NULL) { apetushkov@9858: return NULL; apetushkov@9858: } apetushkov@9858: // append the individual substrings apetushkov@9858: jio_snprintf(chunk_path, chunkname_max_len, "%s%s%s%s", repository_base, os::file_separator(), date_time_buffer, chunk_file_jfr_ext); apetushkov@9858: return chunk_path; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static fio_fd emergency_dump_file() { apetushkov@9858: assert(JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: ResourceMark rm; apetushkov@9858: const char* const emergency_dump_path = create_emergency_dump_path(); apetushkov@9858: if (emergency_dump_path == NULL) { apetushkov@9858: return invalid_fd; apetushkov@9858: } apetushkov@9858: const fio_fd fd = open_exclusivly(emergency_dump_path); apetushkov@9858: if (fd != invalid_fd) { apetushkov@9858: if (LogJFR) tty->print_cr( // For user, should not be "jfr, system" apetushkov@9858: "Attempting to recover JFR data, emergency jfr file: %s", emergency_dump_path); apetushkov@9858: } apetushkov@9858: return fd; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char* emergency_path(const char* repository, size_t repository_len) { apetushkov@9858: return repository == NULL ? create_emergency_dump_path() : create_emergency_chunk_path(repository, repository_len); apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrRepository::on_vm_error() { apetushkov@9858: assert(!JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: const char* path = _path; apetushkov@9858: if (path == NULL) { apetushkov@9858: // completed already apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: ResourceMark rm; apetushkov@9858: MutexLockerEx stream_lock(JfrStream_lock, Mutex::_no_safepoint_check_flag); apetushkov@9858: const fio_fd emergency_fd = emergency_dump_file(); apetushkov@9858: if (emergency_fd != invalid_fd) { apetushkov@9858: RepositoryIterator iterator(path, strlen(path)); apetushkov@9858: write_emergency_file(emergency_fd, iterator); apetushkov@9858: os::close(emergency_fd); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool JfrRepository::set_path(const char* path) { apetushkov@9858: assert(path != NULL, "trying to set the repository path with a NULL string!"); apetushkov@9858: if (_path != NULL) { apetushkov@9858: // delete existing apetushkov@9858: JfrCHeapObj::free(_path, strlen(_path) + 1); apetushkov@9858: } apetushkov@9858: const size_t path_len = strlen(path); apetushkov@9858: _path = JfrCHeapObj::new_array(path_len + 1); apetushkov@9858: if (_path == NULL) { apetushkov@9858: return false; apetushkov@9858: } mikael@9880: strncpy(_path, path, path_len + 1); apetushkov@9858: return true; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrRepository::set_chunk_path(const char* path) { apetushkov@9858: assert(JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: chunkwriter().set_chunk_path(path); apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrRepository::notify_on_new_chunk_path() { apetushkov@9858: if (Jfr::is_recording()) { apetushkov@9858: instance()._post_box.post(MSG_ROTATE); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: /** apetushkov@9858: * Sets the file where data should be written. apetushkov@9858: * apetushkov@9858: * Recording Previous Current Action apetushkov@9858: * ============================================== apetushkov@9858: * true null null Ignore, keep recording in-memory apetushkov@9858: * true null file1 Start disk recording apetushkov@9858: * true file null Copy out metadata to disk and continue in-memory recording apetushkov@9858: * true file1 file2 Copy out metadata and start with new File (file2) apetushkov@9858: * false * null Ignore, but start recording to memory apetushkov@9858: * false * file Ignore, but start recording to disk apetushkov@9858: */ apetushkov@9858: void JfrRepository::set_chunk_path(jstring path, JavaThread* jt) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt)); apetushkov@9858: ResourceMark rm(jt); apetushkov@9858: const char* const canonical_chunk_path = JfrJavaSupport::c_str(path, jt); apetushkov@9858: { apetushkov@9858: MutexLockerEx stream_lock(JfrStream_lock, Mutex::_no_safepoint_check_flag); apetushkov@9858: if (NULL == canonical_chunk_path && !_chunkwriter->is_valid()) { apetushkov@9858: // new output is NULL and current output is NULL apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: instance().set_chunk_path(canonical_chunk_path); apetushkov@9858: } apetushkov@9858: notify_on_new_chunk_path(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrRepository::set_path(jstring location, JavaThread* jt) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt)); apetushkov@9858: ResourceMark rm(jt); apetushkov@9858: const char* const path = JfrJavaSupport::c_str(location, jt); apetushkov@9858: if (path != NULL) { apetushkov@9858: instance().set_path(path); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool JfrRepository::open_chunk(bool vm_error /* false */) { apetushkov@9858: assert(JfrStream_lock->owned_by_self(), "invariant"); apetushkov@9858: if (vm_error) { apetushkov@9858: ResourceMark rm; apetushkov@9858: const char* repository_path = _path; apetushkov@9858: const size_t repository_path_len = repository_path != NULL ? strlen(repository_path) : 0; apetushkov@9858: const char* const path = emergency_path(repository_path, repository_path_len); apetushkov@9858: _chunkwriter->set_chunk_path(path); apetushkov@9858: } apetushkov@9858: return _chunkwriter->open(); apetushkov@9858: } apetushkov@9858: bulasevich@9947: size_t JfrRepository::close_chunk(int64_t metadata_offset) { apetushkov@9858: return _chunkwriter->close(metadata_offset); apetushkov@9858: }