--- /dev/null 2019-01-28 17:48:27.000000000 +0800 +++ new/src/share/vm/jfr/writers/jfrEventWriterHost.inline.hpp 2019-01-28 17:48:27.000000000 +0800 @@ -0,0 +1,97 @@ +/* + * 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_JFREVENTWRITERHOST_INLINE_HPP +#define SHARE_VM_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP + +#include "jfr/writers/jfrEventWriterHost.hpp" + +template +template +inline EventWriterHost:: +EventWriterHost(StorageType* storage, Thread* thread) : WriterHost(storage, thread) {} + +template +inline EventWriterHost::EventWriterHost(Thread* thread) : WriterHost(thread) { +} + +template +inline void EventWriterHost::begin_write() { + assert(this->is_valid(), "invariant"); + assert(!this->is_acquired(), "calling begin with writer already in acquired state!"); + this->acquire(); + assert(this->used_offset() == 0, "invariant"); + assert(this->is_acquired(), "invariant"); +} + +template +inline intptr_t EventWriterHost::end_write(void) { + assert(this->is_acquired(), + "state corruption, calling end with writer with non-acquired state!"); + return this->is_valid() ? this->used_offset() : 0; +} + +template +inline void EventWriterHost::begin_event_write() { + assert(this->is_valid(), "invariant"); + assert(!this->is_acquired(), "calling begin with writer already in acquired state!"); + this->begin_write(); + this->reserve(sizeof(u4)); // reserve the event size slot +} + +template +inline intptr_t EventWriterHost::end_event_write() { + assert(this->is_acquired(), "invariant"); + if (!this->is_valid()) { + this->release(); + return 0; + } + const u4 written = (u4)end_write(); + if (written > sizeof(u4)) { // larger than header reserve + this->write_padded_at_offset(written, 0); + this->commit(); + } + this->release(); + assert(!this->is_acquired(), "invariant"); + return written; +} + +template +template +inline StackEventWriterHost:: +StackEventWriterHost(StorageType* storage, Thread* thread) : EventWriterHost(storage, thread) { + this->begin_event_write(); +} + +template +inline StackEventWriterHost::StackEventWriterHost(Thread* thread) : EventWriterHost(thread) { + this->begin_event_write(); +} + +template +inline StackEventWriterHost::~StackEventWriterHost() { + this->end_event_write(); +} + +#endif // SHARE_VM_JFR_WRITERS_JFREVENTWRITERHOST_INLINE_HPP