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_JFRWRITERHOST_HPP
  26 #define SHARE_VM_JFR_WRITERS_JFRWRITERHOST_HPP
  27 
  28 #include "jni.h"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 class ClassLoaderData;
  32 class Klass;
  33 class Method;
  34 class Thread;
  35 
  36 // BE == Base Encoder
  37 // IE == Integer Encoder
  38 template <typename BE, typename IE, typename WriterPolicyImpl >
  39 class WriterHost : public WriterPolicyImpl {
  40  private:
  41   const bool _compressed_integers;
  42 
  43   template <typename T>
  44   void write_padded(T value);
  45   template <typename T>
  46   void write_padded(const T* value, size_t len);
  47   template <typename T>
  48   u1* write_padded(const T* value, size_t len, u1* pos);
  49   template <typename T>
  50   void write(const T* value, size_t len);
  51   template <typename T>
  52   u1* write(const T* value, size_t len, u1* pos);
  53   void write_utf8(const char* value);
  54   void write_utf16(const jchar* value, jint len);
  55 
  56  protected:
  57   template <typename T>
  58   void be_write(T value);
  59   template <typename T>
  60   void be_write(const T* value, size_t len);
  61   template <typename StorageType>
  62   WriterHost(StorageType* storage, Thread* thread);
  63   template <typename StorageType>
  64   WriterHost(StorageType* storage, size_t size);
  65   WriterHost(Thread* thread);
  66   u1* ensure_size(size_t requested_size);
  67 
  68  public:
  69   template <typename T>
  70   void write(T value);
  71   void write(bool value);
  72   void write(float value);
  73   void write(double value);
  74   void write(const char* value);
  75   void write(char* value);
  76   void write(jstring value);
  77   void write(const ClassLoaderData* cld);
  78   void write(const Klass* klass);
  79   void write(const Method* method);
  80   void write(const Symbol* symbol);
  81   void write(const Ticks& time);
  82   void write(const Tickspan& time);
  83   void bytes(const void* buf, size_t len);
  84   void write_utf8_u2_len(const char* value);
  85   template <typename T>
  86   void write_padded_at_offset(T value, intptr_t offset);
  87   template <typename T>
  88   void write_at_offset(T value, intptr_t offset);
  89   template <typename T>
  90   void write_be_at_offset(T value, intptr_t offset);
  91   intptr_t reserve(size_t size);
  92 };
  93 
  94 #endif // SHARE_VM_JFR_WRITERS_JFRWRITERHOST_HPP