Path: blob/master/src/hotspot/share/jfr/writers/jfrStorageHost.inline.hpp
41149 views
/*1* Copyright (c) 2016, 2019, 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_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP25#define SHARE_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP2627#include "jfr/writers/jfrStorageHost.hpp"2829template <typename Adapter, typename AP>30inline void StorageHost<Adapter, AP>::bind() {31if (is_backed()) {32this->hard_reset();33assert(is_valid(), "invariant");34return;35}36this->set_start_pos(NULL);37this->set_current_pos((const u1*)NULL);38this->set_end_pos(NULL);39}4041template <typename Adapter, typename AP>42inline void StorageHost<Adapter, AP>::soft_reset() {43this->set_start_pos(this->current_pos());44}4546template <typename Adapter, typename AP>47inline void StorageHost<Adapter, AP>::hard_reset() {48this->set_start_pos(_adapter.pos());49this->set_current_pos(_adapter.pos());50this->set_end_pos(_adapter.end());51}5253template <typename Adapter, typename AP>54inline void StorageHost<Adapter, AP>::cancel() {55this->set_end_pos(NULL);56}5758template <typename Adapter, typename AP>59inline bool StorageHost<Adapter, AP>::is_backed() {60return _adapter.storage() != NULL;61}6263template <typename Adapter, typename AP>64inline bool StorageHost<Adapter, AP>::accommodate(size_t used, size_t requested) {65if (!_adapter.flush(used, requested)) {66this->cancel();67return false;68}69assert(is_backed(), "invariant");70this->hard_reset();71this->set_current_pos(used);72return true;73}7475template <typename Adapter, typename AP>76inline void StorageHost<Adapter, AP>::commit() {77if (this->is_valid()) {78assert(_adapter.pos() == this->start_pos(), "invariant");79assert(_adapter.end() == this->end_pos(), "invariant");80u1* new_position = this->current_pos();81_adapter.commit(new_position);82this->set_start_pos(new_position);83}84}8586template <typename Adapter, typename AP>87inline void StorageHost<Adapter, AP>::release() {88_adapter.release();89}9091template <typename Adapter, typename AP>92inline StorageHost<Adapter, AP>::StorageHost(typename Adapter::StorageType* storage, Thread* thread) : Position<AP>(), _adapter(storage, thread) {93bind();94}9596template <typename Adapter, typename AP>97inline StorageHost<Adapter, AP>::StorageHost(typename Adapter::StorageType* storage, size_t size) : Position<AP>(), _adapter(storage, size) {98bind();99}100101template <typename Adapter, typename AP>102inline StorageHost<Adapter, AP>::StorageHost(Thread* thread) : Position<AP>(), _adapter(thread) {103bind();104}105106template <typename Adapter, typename AP>107inline bool StorageHost<Adapter, AP>::is_valid() const {108return this->end_pos() != NULL;109}110111template <typename Adapter, typename AP>112inline typename Adapter::StorageType* StorageHost<Adapter, AP>::storage() {113return _adapter.storage();114}115116template <typename Adapter, typename AP>117inline void StorageHost<Adapter, AP>::set_storage(typename Adapter::StorageType* storage) {118_adapter.set_storage(storage);119bind();120}121122template <typename Adapter, typename AP>123inline void StorageHost<Adapter, AP>::flush() {124this->accommodate(this->is_valid() ? this->used_size() : 0, 0);125}126127template <typename Adapter, typename AP>128inline void StorageHost<Adapter, AP>::seek(intptr_t offset) {129if (this->is_valid()) {130assert(offset >= 0, "negative offsets not supported");131assert(this->start_pos() + offset <= this->end_pos(), "invariant");132assert(this->start_pos() + offset >= this->start_pos(), "invariant");133this->set_current_pos(this->start_pos() + offset);134}135}136137#endif // SHARE_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP138139140