1 /*
   2  * Copyright (c) 2012, 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 #if INCLUDE_TRACE
  29 
  30 #include "oops/klass.hpp"
  31 #include "oops/klassOop.hpp"
  32 #include "oops/methodOop.hpp"
  33 #include "oops/symbol.hpp"
  34 #include "utilities/ostream.hpp"
  35 
  36 class TraceStream : public StackObj {
  37  private:
  38   outputStream& _st;
  39 
  40  public:
  41   TraceStream(outputStream& stream): _st(stream) {}
  42 
  43   void print_val(const char* label, u1 val) {
  44     _st.print("%s = "UINT32_FORMAT, label, val);
  45   }
  46 
  47   void print_val(const char* label, u2 val) {
  48     _st.print("%s = "UINT32_FORMAT, label, val);
  49   }
  50 
  51   void print_val(const char* label, s2 val) {
  52     _st.print("%s = "INT32_FORMAT, label, val);
  53   }
  54 
  55   void print_val(const char* label, u4 val) {
  56     _st.print("%s = "UINT32_FORMAT, label, val);
  57   }
  58 
  59   void print_val(const char* label, s4 val) {
  60     _st.print("%s = "INT32_FORMAT, label, val);
  61   }
  62 
  63   void print_val(const char* label, u8 val) {
  64     _st.print("%s = "UINT64_FORMAT, label, val);
  65   }
  66 
  67   void print_val(const char* label, s8 val) {
  68     _st.print("%s = "INT64_FORMAT, label, val);
  69   }
  70 
  71   void print_val(const char* label, bool val) {
  72     _st.print("%s = %s", label, val ? "true" : "false");
  73   }
  74 
  75   void print_val(const char* label, float val) {
  76     _st.print("%s = %f", label, val);
  77   }
  78 
  79   void print_val(const char* label, double val) {
  80     _st.print("%s = %f", label, val);
  81   }
  82 
  83   void print_val(const char* label, klassOop& val) {
  84     const char* description = "NULL";
  85     if (val != NULL) {
  86       Klass* myklass = val->klass_part();
  87       Symbol* name = myklass->name();
  88       if (name != NULL) {
  89         description = name->as_C_string();
  90       }
  91     }
  92     _st.print("%s = %s", label, description);
  93   }
  94 
  95   void print_val(const char* label, methodOop& val) {
  96     const char* description = "NULL";
  97     if (val != NULL) {
  98       description = val->name_and_sig_as_C_string();
  99     }
 100     _st.print("%s = %s", label, description);
 101   }
 102 
 103   void print_val(const char* label, const char* val) {
 104     _st.print("%s = '%s'", label, val);
 105   }
 106 
 107   void print(const char* val) {
 108     _st.print(val);
 109   }
 110 };
 111 
 112 #endif
 113 #endif