1 /*
   2  * Copyright (c) 2016, 2018, 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_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
  26 #define SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
  27 
  28 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
  29 
  30 template <typename T>
  31 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
  32   _writer.write_unbuffered(data, size);
  33   _processed += size;
  34   return true;
  35 }
  36 
  37 template <typename T>
  38 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
  39   _processed += size;
  40   return true;
  41 }
  42 
  43 template <typename Operation>
  44 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
  45   const u1* const current_top = t->concurrent_top();
  46   const size_t unflushed_size = t->pos() - current_top;
  47   if (unflushed_size == 0) {
  48     t->set_concurrent_top(current_top);
  49     return true;
  50   }
  51   const bool result = _operation.write(t, current_top, unflushed_size);
  52   t->set_concurrent_top(current_top + unflushed_size);
  53   return result;
  54 }
  55 
  56 template <typename Operation>
  57 inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) {
  58   assert(t != NULL, "invariant");
  59   const u1* const current_top = t->top();
  60   const size_t unflushed_size = t->pos() - current_top;
  61   if (unflushed_size == 0) {
  62     return true;
  63   }
  64   const bool result = _operation.write(t, current_top, unflushed_size);
  65   t->set_top(current_top + unflushed_size);
  66   return result;
  67 }
  68 
  69 template <typename Operation>
  70 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
  71   assert(t != NULL, "invariant");
  72   const u1* const current_top = _mode == concurrent ? t->concurrent_top() : t->top();
  73   const size_t unflushed_size = t->pos() - current_top;
  74   if (unflushed_size == 0) {
  75     if (_mode == concurrent) {
  76       t->set_concurrent_top(current_top);
  77     }
  78     return true;
  79   }
  80   const bool result = _operation.discard(t, current_top, unflushed_size);
  81   if (_mode == concurrent) {
  82     t->set_concurrent_top(current_top + unflushed_size);
  83   } else {
  84     t->set_top(current_top + unflushed_size);
  85   }
  86   return result;
  87 }
  88 
  89 #endif // SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP