Tue, 16 Jun 2020 11:03:04 +0800
8217647: JFR: recordings on 32-bit systems unreadable
Reviewed-by: egahlin
Contributed-by: boris.ulasevich@bell-sw.com, markus.gronlund@oracle.com
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #ifndef SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP |
apetushkov@9858 | 26 | #define SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP |
apetushkov@9858 | 27 | |
apetushkov@9858 | 28 | #include "jfr/writers/jfrStreamWriterHost.hpp" |
apetushkov@9858 | 29 | #include "runtime/os.hpp" |
apetushkov@9858 | 30 | |
apetushkov@9858 | 31 | template <typename Adapter, typename AP> |
apetushkov@9858 | 32 | StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, Thread* thread) : |
apetushkov@9858 | 33 | MemoryWriterHost<Adapter, AP>(storage, thread), _stream_pos(0), _fd(invalid_fd) { |
apetushkov@9858 | 34 | } |
apetushkov@9858 | 35 | |
apetushkov@9858 | 36 | template <typename Adapter, typename AP> |
apetushkov@9858 | 37 | StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, size_t size) : |
apetushkov@9858 | 38 | MemoryWriterHost<Adapter, AP>(storage, size), _stream_pos(0), _fd(invalid_fd) { |
apetushkov@9858 | 39 | } |
apetushkov@9858 | 40 | |
apetushkov@9858 | 41 | template <typename Adapter, typename AP> |
apetushkov@9858 | 42 | StreamWriterHost<Adapter, AP>::StreamWriterHost(Thread* thread) : |
apetushkov@9858 | 43 | MemoryWriterHost<Adapter, AP>(thread), _stream_pos(0), _fd(invalid_fd) { |
apetushkov@9858 | 44 | } |
apetushkov@9858 | 45 | |
apetushkov@9858 | 46 | template <typename Adapter, typename AP> |
bulasevich@9947 | 47 | inline int64_t StreamWriterHost<Adapter, AP>::current_stream_position() const { |
apetushkov@9858 | 48 | return this->used_offset() + _stream_pos; |
apetushkov@9858 | 49 | } |
apetushkov@9858 | 50 | |
apetushkov@9858 | 51 | template <typename Adapter, typename AP> |
apetushkov@9858 | 52 | inline bool StreamWriterHost<Adapter, AP>::accommodate(size_t used, size_t requested) { |
apetushkov@9858 | 53 | if (used > 0) { |
apetushkov@9858 | 54 | this->flush(used); |
apetushkov@9858 | 55 | } |
apetushkov@9858 | 56 | assert(this->used_size() == 0, "invariant"); |
apetushkov@9858 | 57 | if (this->available_size() >= requested) { |
apetushkov@9858 | 58 | return true; |
apetushkov@9858 | 59 | } |
apetushkov@9858 | 60 | return StorageHost<Adapter, AP>::accommodate(0, requested); |
apetushkov@9858 | 61 | } |
apetushkov@9858 | 62 | |
apetushkov@9858 | 63 | template <typename Adapter, typename AP> |
apetushkov@9858 | 64 | inline void StreamWriterHost<Adapter, AP>::bytes(void* dest, const void* buf, size_t len) { |
apetushkov@9858 | 65 | if (len > this->available_size()) { |
apetushkov@9858 | 66 | this->write_unbuffered(buf, len); |
apetushkov@9858 | 67 | return; |
apetushkov@9858 | 68 | } |
apetushkov@9858 | 69 | MemoryWriterHost<Adapter, AP>::bytes(dest, buf, len); |
apetushkov@9858 | 70 | } |
apetushkov@9858 | 71 | |
apetushkov@9858 | 72 | template <typename Adapter, typename AP> |
apetushkov@9858 | 73 | inline void StreamWriterHost<Adapter, AP>::flush(size_t size) { |
apetushkov@9858 | 74 | assert(size > 0, "invariant"); |
apetushkov@9858 | 75 | assert(this->is_valid(), "invariant"); |
bulasevich@9947 | 76 | _stream_pos += os::write(_fd, this->start_pos(), (unsigned int)size); |
apetushkov@9858 | 77 | StorageHost<Adapter, AP>::reset(); |
apetushkov@9858 | 78 | assert(0 == this->used_offset(), "invariant"); |
apetushkov@9858 | 79 | } |
apetushkov@9858 | 80 | |
apetushkov@9858 | 81 | template <typename Adapter, typename AP> |
apetushkov@9858 | 82 | inline bool StreamWriterHost<Adapter, AP>::has_valid_fd() const { |
apetushkov@9858 | 83 | return invalid_fd != _fd; |
apetushkov@9858 | 84 | } |
apetushkov@9858 | 85 | |
apetushkov@9858 | 86 | template <typename Adapter, typename AP> |
bulasevich@9947 | 87 | inline int64_t StreamWriterHost<Adapter, AP>::current_offset() const { |
apetushkov@9858 | 88 | return current_stream_position(); |
apetushkov@9858 | 89 | } |
apetushkov@9858 | 90 | |
apetushkov@9858 | 91 | template <typename Adapter, typename AP> |
bulasevich@9947 | 92 | void StreamWriterHost<Adapter, AP>::seek(int64_t offset) { |
apetushkov@9858 | 93 | this->flush(); |
apetushkov@9858 | 94 | assert(0 == this->used_offset(), "can only seek from beginning"); |
apetushkov@9858 | 95 | _stream_pos = os::seek_to_file_offset(_fd, offset); |
apetushkov@9858 | 96 | } |
apetushkov@9858 | 97 | |
apetushkov@9858 | 98 | template <typename Adapter, typename AP> |
apetushkov@9858 | 99 | void StreamWriterHost<Adapter, AP>::flush() { |
apetushkov@9858 | 100 | if (this->is_valid()) { |
apetushkov@9858 | 101 | const size_t used = this->used_size(); |
apetushkov@9858 | 102 | if (used > 0) { |
apetushkov@9858 | 103 | this->flush(used); |
apetushkov@9858 | 104 | } |
apetushkov@9858 | 105 | } |
apetushkov@9858 | 106 | } |
apetushkov@9858 | 107 | |
apetushkov@9858 | 108 | template <typename Adapter, typename AP> |
apetushkov@9858 | 109 | void StreamWriterHost<Adapter, AP>::write_unbuffered(const void* buf, size_t len) { |
apetushkov@9858 | 110 | this->flush(); |
apetushkov@9858 | 111 | assert(0 == this->used_offset(), "can only seek from beginning"); |
apetushkov@9858 | 112 | while (len > 0) { |
bulasevich@9947 | 113 | const unsigned int n = MIN2((unsigned int)len, (unsigned int)INT_MAX); |
apetushkov@9858 | 114 | _stream_pos += os::write(_fd, buf, n); |
apetushkov@9858 | 115 | len -= n; |
apetushkov@9858 | 116 | } |
apetushkov@9858 | 117 | } |
apetushkov@9858 | 118 | |
apetushkov@9858 | 119 | template <typename Adapter, typename AP> |
apetushkov@9858 | 120 | inline bool StreamWriterHost<Adapter, AP>::is_valid() const { |
apetushkov@9858 | 121 | return has_valid_fd(); |
apetushkov@9858 | 122 | } |
apetushkov@9858 | 123 | |
apetushkov@9858 | 124 | template <typename Adapter, typename AP> |
apetushkov@9858 | 125 | inline void StreamWriterHost<Adapter, AP>::close_fd() { |
apetushkov@9858 | 126 | assert(this->has_valid_fd(), "closing invalid fd!"); |
apetushkov@9858 | 127 | os::close(_fd); |
apetushkov@9858 | 128 | _fd = invalid_fd; |
apetushkov@9858 | 129 | } |
apetushkov@9858 | 130 | |
apetushkov@9858 | 131 | template <typename Adapter, typename AP> |
apetushkov@9858 | 132 | inline void StreamWriterHost<Adapter, AP>::reset(fio_fd fd) { |
apetushkov@9858 | 133 | assert(!this->has_valid_fd(), "invariant"); |
apetushkov@9858 | 134 | _fd = fd; |
apetushkov@9858 | 135 | _stream_pos = 0; |
apetushkov@9858 | 136 | this->hard_reset(); |
apetushkov@9858 | 137 | } |
apetushkov@9858 | 138 | |
apetushkov@9858 | 139 | #endif // SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP |