--- /dev/null 2019-01-28 17:48:37.000000000 +0800 +++ new/src/share/vm/jfr/writers/jfrStorageHost.inline.hpp 2019-01-28 17:48:37.000000000 +0800 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP +#define SHARE_VM_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP + +#include "jfr/writers/jfrStorageHost.hpp" + +template +inline void StorageHost::bind() { + if (is_backed()) { + this->hard_reset(); + assert(is_valid(), "invariant"); + return; + } + this->set_start_pos(NULL); + this->set_current_pos((const u1*)NULL); + this->set_end_pos(NULL); +} + +template +inline void StorageHost::soft_reset() { + this->set_start_pos(this->current_pos()); +} + +template +inline void StorageHost::hard_reset() { + this->set_start_pos(_adapter.pos()); + this->set_current_pos(_adapter.pos()); + this->set_end_pos(_adapter.end()); +} + +template +inline void StorageHost::cancel() { + this->set_end_pos(NULL); +} + +template +inline bool StorageHost::is_backed() { + return _adapter.storage() != NULL; +} + +template +inline bool StorageHost::accommodate(size_t used, size_t requested) { + if (!_adapter.flush(used, requested)) { + this->cancel(); + return false; + } + assert(is_backed(), "invariant"); + this->hard_reset(); + this->set_current_pos(used); + return true; +} + +template +inline void StorageHost::commit() { + if (this->is_valid()) { + assert(_adapter.pos() == this->start_pos(), "invariant"); + assert(_adapter.end() == this->end_pos(), "invariant"); + u1* new_position = this->current_pos(); + _adapter.commit(new_position); + this->set_start_pos(new_position); + } +} + +template +inline void StorageHost::release() { + _adapter.release(); +} + +template +inline StorageHost::StorageHost(typename Adapter::StorageType* storage, Thread* thread) : Position(), _adapter(storage, thread) { + bind(); +} + +template +inline StorageHost::StorageHost(typename Adapter::StorageType* storage, size_t size) : Position(), _adapter(storage, size) { + bind(); +} + +template +inline StorageHost::StorageHost(Thread* thread) : Position(), _adapter(thread) { + bind(); +} + +template +inline bool StorageHost::is_valid() const { + return this->end_pos() != NULL; +} + +template +inline typename Adapter::StorageType* StorageHost::storage() { + return _adapter.storage(); +} + +template +inline void StorageHost::set_storage(typename Adapter::StorageType* storage) { + _adapter.set_storage(storage); + bind(); +} + +template +inline void StorageHost::flush() { + this->accommodate(this->is_valid() ? this->used_size() : 0, 0); +} + +template +inline void StorageHost::seek(intptr_t offset) { + if (this->is_valid()) { + assert(offset >= 0, "negative offsets not supported"); + assert(this->start_pos() + offset <= this->end_pos(), "invariant"); + assert(this->start_pos() + offset >= this->start_pos(), "invariant"); + this->set_current_pos(this->start_pos() + offset); + } +} + +#endif // SHARE_VM_JFR_WRITERS_JFRSTORAGEHOST_INLINE_HPP