Path: blob/master/src/hotspot/share/jfr/writers/jfrEventWriterHost.inline.hpp
41149 views
/*1* Copyright (c) 2016, 2020, 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_JFREVENTWRITERHOST_INLINE_HPP25#define SHARE_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP2627#include "jfr/writers/jfrEventWriterHost.hpp"2829template <typename BE, typename IE, typename WriterPolicyImpl>30template <typename StorageType>31inline EventWriterHost<BE, IE, WriterPolicyImpl>::32EventWriterHost(StorageType* storage, Thread* thread) : WriterHost<BE, IE, WriterPolicyImpl>(storage, thread) {}3334template <typename BE, typename IE, typename WriterPolicyImpl>35inline EventWriterHost<BE, IE, WriterPolicyImpl>::EventWriterHost(Thread* thread) : WriterHost<BE, IE, WriterPolicyImpl>(thread) {36}3738template <typename BE, typename IE, typename WriterPolicyImpl>39inline void EventWriterHost<BE, IE, WriterPolicyImpl>::begin_write() {40assert(this->is_valid(), "invariant");41assert(!this->is_acquired(), "calling begin with writer already in acquired state!");42this->acquire();43assert(this->used_offset() == 0, "invariant");44assert(this->is_acquired(), "invariant");45}4647template <typename BE, typename IE, typename WriterPolicyImpl>48inline intptr_t EventWriterHost<BE, IE, WriterPolicyImpl>::end_write(void) {49assert(this->is_acquired(),50"state corruption, calling end with writer with non-acquired state!");51return this->is_valid() ? (intptr_t)this->used_offset() : 0;52}5354template <typename BE, typename IE, typename WriterPolicyImpl>55inline void EventWriterHost<BE, IE, WriterPolicyImpl>::begin_event_write(bool large) {56assert(this->is_valid(), "invariant");57assert(!this->is_acquired(), "calling begin with writer already in acquired state!");58this->begin_write();59// reserve the event size slot60if (large) {61this->reserve(sizeof(u4));62} else {63this->reserve(sizeof(u1));64}65}6667template <typename BE, typename IE, typename WriterPolicyImpl>68inline intptr_t EventWriterHost<BE, IE, WriterPolicyImpl>::end_event_write(bool large) {69assert(this->is_acquired(), "invariant");70if (!this->is_valid()) {71this->release();72return 0;73}74u4 written = (u4)end_write();75if (large) {76// size written is larger than header reserve, so commit77if (written > sizeof(u4)) {78this->write_padded_at_offset(written, 0);79this->commit();80}81} else {82// abort if event size will not fit in one byte (compressed)83if (written > 127) {84this->reset();85written = 0;86} else {87// size written is larger than header reserve, so commit88if (written > sizeof(u1)) {89this->write_at_offset(written, 0);90this->commit();91}92}93}94this->release();95assert(!this->is_acquired(), "invariant");96return written;97}98#endif // SHARE_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP99100101