1 /*
   2  * Copyright (c) 2012, 2016, 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 "memory/allocation.hpp"
  31 #include "utilities/debug.hpp"
  32 #include "utilities/ostream.hpp"
  33 
  34 class Klass;
  35 class Method;
  36 class ClassLoaderData;
  37 
  38 class TraceStream : public StackObj {
  39  public:
  40   TraceStream() {
  41     assert(tty != NULL, "invariant");
  42   }
  43 
  44   void print(const char* val) const {
  45     tty->print("%s", val);
  46   }
  47 
  48   void print_val(const char* label, u1 val) const {
  49     tty->print("%s = " UINT32_FORMAT, label, val);
  50   }
  51 
  52   void print_val(const char* label, u2 val) const {
  53     tty->print("%s = " UINT32_FORMAT, label, val);
  54   }
  55 
  56   void print_val(const char* label, s2 val) const {
  57     tty->print("%s = " INT32_FORMAT, label, val);
  58   }
  59 
  60   void print_val(const char* label, u4 val) const {
  61     tty->print("%s = " UINT32_FORMAT, label, val);
  62   }
  63 
  64   void print_val(const char* label, s4 val) const {
  65     tty->print("%s = " INT32_FORMAT, label, val);
  66   }
  67 
  68   void print_val(const char* label, u8 val) const {
  69     tty->print("%s = " UINT64_FORMAT, label, val);
  70   }
  71 
  72   void print_val(const char* label, s8 val) const {
  73     tty->print("%s = " INT64_FORMAT, label, (int64_t) val);
  74   }
  75 
  76   void print_val(const char* label, bool val) const {
  77     tty->print("%s = %s", label, val ? "true" : "false");
  78   }
  79 
  80   void print_val(const char* label, float val) const {
  81     tty->print("%s = %f", label, val);
  82   }
  83 
  84   void print_val(const char* label, double val) const {
  85     tty->print("%s = %f", label, val);
  86   }
  87 
  88   void print_val(const char* label, const char* val) const {
  89     tty->print("%s = '%s'", label, val);
  90   }
  91 
  92   void print_val(const char* label, const Klass* val) const;
  93   void print_val(const char* label, const Method* val)const ;
  94   void print_val(const char* label, const ClassLoaderData* cld) const;
  95 };
  96 
  97 #endif // INCLUDE_TRACE
  98 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP