| 1 | /* |
| 2 | * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP |
| 26 | #define SHARE_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP |
| 27 | |
| 28 | #include "jfr/writers/jfrEventWriterHost.hpp" |
| 29 | |
| 30 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 31 | template <typename StorageType> |
| 32 | inline EventWriterHost<BE, IE, WriterPolicyImpl>:: |
| 33 | EventWriterHost(StorageType* storage, Thread* thread) : WriterHost<BE, IE, WriterPolicyImpl>(storage, thread) {} |
| 34 | |
| 35 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 36 | inline EventWriterHost<BE, IE, WriterPolicyImpl>::EventWriterHost(Thread* thread) : WriterHost<BE, IE, WriterPolicyImpl>(thread) { |
| 37 | } |
| 38 | |
| 39 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 40 | inline void EventWriterHost<BE, IE, WriterPolicyImpl>::begin_write() { |
| 41 | assert(this->is_valid(), "invariant" ); |
| 42 | assert(!this->is_acquired(), "calling begin with writer already in acquired state!" ); |
| 43 | this->acquire(); |
| 44 | assert(this->used_offset() == 0, "invariant" ); |
| 45 | assert(this->is_acquired(), "invariant" ); |
| 46 | } |
| 47 | |
| 48 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 49 | inline intptr_t EventWriterHost<BE, IE, WriterPolicyImpl>::end_write(void) { |
| 50 | assert(this->is_acquired(), |
| 51 | "state corruption, calling end with writer with non-acquired state!" ); |
| 52 | return this->is_valid() ? (intptr_t)this->used_offset() : 0; |
| 53 | } |
| 54 | |
| 55 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 56 | inline void EventWriterHost<BE, IE, WriterPolicyImpl>::begin_event_write() { |
| 57 | assert(this->is_valid(), "invariant" ); |
| 58 | assert(!this->is_acquired(), "calling begin with writer already in acquired state!" ); |
| 59 | this->begin_write(); |
| 60 | this->reserve(sizeof(u4)); // reserve the event size slot |
| 61 | } |
| 62 | |
| 63 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 64 | inline intptr_t EventWriterHost<BE, IE, WriterPolicyImpl>::end_event_write() { |
| 65 | assert(this->is_acquired(), "invariant" ); |
| 66 | if (!this->is_valid()) { |
| 67 | this->release(); |
| 68 | return 0; |
| 69 | } |
| 70 | const u4 written = (u4)end_write(); |
| 71 | if (written > sizeof(u4)) { // larger than header reserve |
| 72 | this->write_padded_at_offset(written, 0); |
| 73 | this->commit(); |
| 74 | } |
| 75 | this->release(); |
| 76 | assert(!this->is_acquired(), "invariant" ); |
| 77 | return written; |
| 78 | } |
| 79 | |
| 80 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 81 | template <typename StorageType> |
| 82 | inline StackEventWriterHost<BE, IE, WriterPolicyImpl>:: |
| 83 | StackEventWriterHost(StorageType* storage, Thread* thread) : EventWriterHost<BE, IE, WriterPolicyImpl>(storage, thread) { |
| 84 | this->begin_event_write(); |
| 85 | } |
| 86 | |
| 87 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 88 | inline StackEventWriterHost<BE, IE, WriterPolicyImpl>::StackEventWriterHost(Thread* thread) : EventWriterHost<BE, IE, WriterPolicyImpl>(thread) { |
| 89 | this->begin_event_write(); |
| 90 | } |
| 91 | |
| 92 | template <typename BE, typename IE, typename WriterPolicyImpl> |
| 93 | inline StackEventWriterHost<BE, IE, WriterPolicyImpl>::~StackEventWriterHost() { |
| 94 | this->end_event_write(); |
| 95 | } |
| 96 | |
| 97 | #endif // SHARE_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP |
| 98 | |