Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/writers/jfrStreamWriterHost.inline.hpp
38920 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP25#define SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP2627#include "jfr/writers/jfrStreamWriterHost.hpp"28#include "runtime/os.hpp"2930template <typename Adapter, typename AP>31StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, Thread* thread) :32MemoryWriterHost<Adapter, AP>(storage, thread), _stream_pos(0), _fd(invalid_fd) {33}3435template <typename Adapter, typename AP>36StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, size_t size) :37MemoryWriterHost<Adapter, AP>(storage, size), _stream_pos(0), _fd(invalid_fd) {38}3940template <typename Adapter, typename AP>41StreamWriterHost<Adapter, AP>::StreamWriterHost(Thread* thread) :42MemoryWriterHost<Adapter, AP>(thread), _stream_pos(0), _fd(invalid_fd) {43}4445template <typename Adapter, typename AP>46inline int64_t StreamWriterHost<Adapter, AP>::current_stream_position() const {47return this->used_offset() + _stream_pos;48}4950template <typename Adapter, typename AP>51inline bool StreamWriterHost<Adapter, AP>::accommodate(size_t used, size_t requested) {52if (used > 0) {53this->flush(used);54}55assert(this->used_size() == 0, "invariant");56if (this->available_size() >= requested) {57return true;58}59return StorageHost<Adapter, AP>::accommodate(0, requested);60}6162template <typename Adapter, typename AP>63inline void StreamWriterHost<Adapter, AP>::bytes(void* dest, const void* buf, size_t len) {64if (len > this->available_size()) {65this->write_unbuffered(buf, len);66return;67}68MemoryWriterHost<Adapter, AP>::bytes(dest, buf, len);69}7071template <typename Adapter, typename AP>72inline void StreamWriterHost<Adapter, AP>::flush(size_t size) {73assert(size > 0, "invariant");74assert(this->is_valid(), "invariant");75_stream_pos += os::write(_fd, this->start_pos(), (unsigned int)size);76StorageHost<Adapter, AP>::reset();77assert(0 == this->used_offset(), "invariant");78}7980template <typename Adapter, typename AP>81inline bool StreamWriterHost<Adapter, AP>::has_valid_fd() const {82return invalid_fd != _fd;83}8485template <typename Adapter, typename AP>86inline int64_t StreamWriterHost<Adapter, AP>::current_offset() const {87return current_stream_position();88}8990template <typename Adapter, typename AP>91void StreamWriterHost<Adapter, AP>::seek(int64_t offset) {92this->flush();93assert(0 == this->used_offset(), "can only seek from beginning");94_stream_pos = os::seek_to_file_offset(_fd, offset);95}9697template <typename Adapter, typename AP>98void StreamWriterHost<Adapter, AP>::flush() {99if (this->is_valid()) {100const size_t used = this->used_size();101if (used > 0) {102this->flush(used);103}104}105}106107template <typename Adapter, typename AP>108void StreamWriterHost<Adapter, AP>::write_unbuffered(const void* buf, size_t len) {109this->flush();110assert(0 == this->used_offset(), "can only seek from beginning");111while (len > 0) {112const unsigned int n = MIN2((unsigned int)len, (unsigned int)INT_MAX);113_stream_pos += os::write(_fd, buf, n);114len -= n;115}116}117118template <typename Adapter, typename AP>119inline bool StreamWriterHost<Adapter, AP>::is_valid() const {120return has_valid_fd();121}122123template <typename Adapter, typename AP>124inline void StreamWriterHost<Adapter, AP>::close_fd() {125assert(this->has_valid_fd(), "closing invalid fd!");126os::close(_fd);127_fd = invalid_fd;128}129130template <typename Adapter, typename AP>131inline void StreamWriterHost<Adapter, AP>::reset(fio_fd fd) {132assert(!this->has_valid_fd(), "invariant");133_fd = fd;134_stream_pos = 0;135this->hard_reset();136}137138#endif // SHARE_VM_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP139140141