1 /*
   2  * Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
   3  *
   4  * This file is part of the Lock Contention Tracing Subsystem for the HotSpot
   5  * Virtual Machine, which is developed at Christian Doppler Laboratory on
   6  * Monitoring and Evolution of Very-Large-Scale Software Systems. Please
   7  * contact us at <http://mevss.jku.at/> if you need additional information
   8  * or have any questions.
   9  *
  10  * This code is free software; you can redistribute it and/or modify it
  11  * under the terms of the GNU General Public License version 2 only, as
  12  * published by the Free Software Foundation.
  13  *
  14  * This code is distributed in the hope that it will be useful, but WITHOUT
  15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17  * version 2 for more details (a copy is included in the LICENSE file that
  18  * accompanied this code).
  19  *
  20  * You should have received a copy of the GNU General Public License version
  21  * 2 along with this work. If not, see <http://www.gnu.org/licenses/>.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_EVTRACE_TRACEWRITER_H
  26 #define SHARE_VM_EVTRACE_TRACEWRITER_H
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/gcLocker.hpp"
  30 
  31 class TraceWriterBase: public StackObj {
  32 private:
  33   u1  *_writer_top;
  34   No_Safepoint_Verifier _nsv;
  35 
  36   void assert_reserved(size_t nbytes);
  37   void reserve(size_t nbytes);
  38 
  39 protected:
  40   TraceWriterBase(size_t nbytes);
  41   ~TraceWriterBase();
  42 
  43 public:
  44   void put_u1(u1 v);
  45   void put_u2(u2 v);
  46   void put_u4(u4 v);
  47   void put_u8(u8 v);
  48   void put_s4(s4 v);
  49   void put_s8(s8 v);
  50   void put_data(void *data, size_t length);
  51   void put_utf8str(const char *s, size_t bytes);
  52   static size_t nbytes_for_utf8str(const char *s, size_t maxbytes);
  53 };
  54 
  55 class TraceWriter: public TraceWriterBase {
  56 public:
  57   TraceWriter(size_t nbytes) : TraceWriterBase(nbytes) { }
  58 
  59 #define TRACE_TYPE_DEFINE_PUT_METHOD(primitive, name) \
  60   void put_##name(TraceTypes::name val) { put_##primitive(val); }
  61 TRACE_TYPES_DO(TRACE_TYPE_DEFINE_PUT_METHOD)
  62 #undef TRACE_TYPE_DEFINE_PUT_METHOD
  63 };
  64 
  65 #include "evtrace/traceWriter.inline.hpp"
  66 
  67 #endif /* SHARE_VM_EVTRACE_TRACEWRITER_H */