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