1 /*
   2  * Copyright (c) 2012, 2014, 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_TRACE_TRACESTREAM_HPP
  26 #define SHARE_VM_TRACE_TRACESTREAM_HPP
  27 
  28 #include "utilities/macros.hpp"
  29 #if INCLUDE_TRACE
  30 #include "oops/klass.hpp"
  31 #include "oops/method.hpp"
  32 #include "oops/symbol.hpp"
  33 #include "utilities/ostream.hpp"
  34 
  35 class TraceStream : public StackObj {
  36  private:
  37   outputStream& _st;
  38 
  39  public:
  40   TraceStream(outputStream& stream): _st(stream) {}
  41 
  42   void print_val(const char* label, u1 val) {
  43     _st.print("%s = " UINT32_FORMAT, label, val);
  44   }
  45 
  46   void print_val(const char* label, u2 val) {
  47     _st.print("%s = " UINT32_FORMAT, label, val);
  48   }
  49 
  50   void print_val(const char* label, s2 val) {
  51     _st.print("%s = " INT32_FORMAT, label, val);
  52   }
  53 
  54   void print_val(const char* label, u4 val) {
  55     _st.print("%s = " UINT32_FORMAT, label, val);
  56   }
  57 
  58   void print_val(const char* label, s4 val) {
  59     _st.print("%s = " INT32_FORMAT, label, val);
  60   }
  61 
  62   void print_val(const char* label, u8 val) {
  63     _st.print("%s = " UINT64_FORMAT, label, val);
  64   }
  65 
  66   void print_val(const char* label, s8 val) {
  67     _st.print("%s = " INT64_FORMAT, label, (int64_t) val);
  68   }
  69 
  70   void print_val(const char* label, bool val) {
  71     _st.print("%s = %s", label, val ? "true" : "false");
  72   }
  73 
  74   void print_val(const char* label, float val) {
  75     _st.print("%s = %f", label, val);
  76   }
  77 
  78   void print_val(const char* label, double val) {
  79     _st.print("%s = %f", label, val);
  80   }
  81 
  82   // Caller is machine generated code located in traceEventClasses.hpp
  83   // Event<TraceId>::writeEvent() (pseudocode) contains the
  84   // necessary ResourceMark for the resource allocations below.
  85   // See traceEventClasses.xsl for details.
  86   void print_val(const char* label, const Klass* const val) {
  87     const char* description = "NULL";
  88     if (val != NULL) {
  89       Symbol* name = val->name();
  90       if (name != NULL) {
  91         description = name->as_C_string();
  92       }
  93     }
  94     _st.print("%s = %s", label, description);
  95   }
  96 
  97   // Caller is machine generated code located in traceEventClasses.hpp
  98   // Event<TraceId>::writeEvent() (pseudocode) contains the
  99   // necessary ResourceMark for the resource allocations below.
 100   // See traceEventClasses.xsl for details.
 101   void print_val(const char* label, const Method* const val) {
 102     const char* description = "NULL";
 103     if (val != NULL) {
 104       description = val->name_and_sig_as_C_string();
 105     }
 106     _st.print("%s = %s", label, description);
 107   }
 108 
 109   void print_val(const char* label, const char* val) {
 110     _st.print("%s = '%s'", label, val);
 111   }
 112 
 113   void print(const char* val) {
 114     _st.print("%s", val);
 115   }
 116 };
 117 
 118 #endif // INCLUDE_TRACE
 119 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP