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_VM_JFR_WRITERS_JFRMEMORYWRITERHOST_INLINE_HPP
  26 #define SHARE_VM_JFR_WRITERS_JFRMEMORYWRITERHOST_INLINE_HPP
  27 
  28 #include "jfr/writers/jfrMemoryWriterHost.hpp"
  29 
  30 template <typename Adapter, typename AP, typename AccessAssert>
  31 inline void MemoryWriterHost<Adapter, AP, AccessAssert>::bytes(void* dest, const void* buf, size_t len) {
  32   assert(dest != NULL, "invariant");
  33   memcpy(dest, buf, len); // no encoding
  34   this->set_current_pos(len);
  35 }
  36 
  37 template <typename Adapter, typename AP, typename AccessAssert>
  38 inline MemoryWriterHost<Adapter, AP, AccessAssert>::MemoryWriterHost(typename Adapter::StorageType* storage, Thread* thread) :
  39   StorageHost<Adapter, AP>(storage, thread) {
  40 }
  41 
  42 template <typename Adapter, typename AP, typename AccessAssert>
  43 inline MemoryWriterHost<Adapter, AP, AccessAssert>::MemoryWriterHost(typename Adapter::StorageType* storage, size_t size) :
  44   StorageHost<Adapter, AP>(storage, size) {
  45 }
  46 
  47 template <typename Adapter, typename AP, typename AccessAssert>
  48 inline MemoryWriterHost<Adapter, AP, AccessAssert>::MemoryWriterHost(Thread* thread) :
  49   StorageHost<Adapter, AP>(thread) {
  50 }
  51 
  52 template <typename Adapter, typename AP, typename AccessAssert>
  53 inline void MemoryWriterHost<Adapter, AP, AccessAssert>::acquire() {
  54   debug_only(_access.acquire();)
  55   if (!this->is_valid()) {
  56     this->flush();
  57   }
  58   debug_only(is_acquired();)
  59 }
  60 
  61 template <typename Adapter, typename AP, typename AccessAssert>
  62 inline void MemoryWriterHost<Adapter, AP, AccessAssert>::release() {
  63   debug_only(is_acquired();)
  64   StorageHost<Adapter, AP>::release();
  65   debug_only(_access.release();)
  66 }
  67 
  68 #ifdef ASSERT
  69 template <typename Adapter, typename AP, typename AccessAssert>
  70 inline bool MemoryWriterHost<Adapter, AP, AccessAssert>::is_acquired() const {
  71   return _access.is_acquired();
  72 }
  73 #endif
  74 
  75 template <typename Adapter, typename AP>
  76 inline AcquireReleaseMemoryWriterHost<Adapter, AP>::AcquireReleaseMemoryWriterHost(typename Adapter::StorageType* storage, Thread* thread) :
  77   MemoryWriterHost<Adapter, AP>(storage, thread) {
  78   this->acquire();
  79 }
  80 
  81 template <typename Adapter, typename AP>
  82 inline AcquireReleaseMemoryWriterHost<Adapter, AP>::AcquireReleaseMemoryWriterHost(typename Adapter::StorageType* storage, size_t size) :
  83   MemoryWriterHost<Adapter, AP>(storage, size) {
  84   this->acquire();
  85 }
  86 
  87 template <typename Adapter, typename AP>
  88 inline AcquireReleaseMemoryWriterHost<Adapter, AP>::AcquireReleaseMemoryWriterHost(Thread* thread) :
  89   MemoryWriterHost<Adapter, AP>(thread) {
  90   this->acquire();
  91 }
  92 
  93 template <typename Adapter, typename AP>
  94 inline AcquireReleaseMemoryWriterHost<Adapter, AP>::~AcquireReleaseMemoryWriterHost() {
  95   assert(this->is_acquired(), "invariant");
  96   this->release();
  97 }
  98 
  99 #endif // SHARE_VM_JFR_WRITERS_JFRMEMORYWRITERHOST_INLINE_HPP