traceStream.hpp 3.6 KB
Newer Older
S
sla 已提交
1
/*
2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
S
sla 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_TRACE_TRACESTREAM_HPP
#define SHARE_VM_TRACE_TRACESTREAM_HPP

#include "utilities/macros.hpp"
#if INCLUDE_TRACE
#include "oops/klass.hpp"
#include "oops/method.hpp"
#include "oops/symbol.hpp"
#include "utilities/ostream.hpp"

class TraceStream : public StackObj {
 private:
  outputStream& _st;

 public:
  TraceStream(outputStream& stream): _st(stream) {}

  void print_val(const char* label, u1 val) {
43
    _st.print("%s = " UINT32_FORMAT, label, val);
S
sla 已提交
44 45 46
  }

  void print_val(const char* label, u2 val) {
47
    _st.print("%s = " UINT32_FORMAT, label, val);
S
sla 已提交
48 49 50
  }

  void print_val(const char* label, s2 val) {
51
    _st.print("%s = " INT32_FORMAT, label, val);
S
sla 已提交
52 53 54
  }

  void print_val(const char* label, u4 val) {
55
    _st.print("%s = " UINT32_FORMAT, label, val);
S
sla 已提交
56 57 58
  }

  void print_val(const char* label, s4 val) {
59
    _st.print("%s = " INT32_FORMAT, label, val);
S
sla 已提交
60 61 62
  }

  void print_val(const char* label, u8 val) {
63
    _st.print("%s = " UINT64_FORMAT, label, val);
S
sla 已提交
64 65 66
  }

  void print_val(const char* label, s8 val) {
67
    _st.print("%s = " INT64_FORMAT, label, (int64_t) val);
S
sla 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  }

  void print_val(const char* label, bool val) {
    _st.print("%s = %s", label, val ? "true" : "false");
  }

  void print_val(const char* label, float val) {
    _st.print("%s = %f", label, val);
  }

  void print_val(const char* label, double val) {
    _st.print("%s = %f", label, val);
  }

  // Caller is machine generated code located in traceEventClasses.hpp
  // Event<TraceId>::writeEvent() (pseudocode) contains the
  // necessary ResourceMark for the resource allocations below.
  // See traceEventClasses.xsl for details.
  void print_val(const char* label, const Klass* const val) {
    const char* description = "NULL";
    if (val != NULL) {
      Symbol* name = val->name();
      if (name != NULL) {
        description = name->as_C_string();
      }
    }
    _st.print("%s = %s", label, description);
  }

  // Caller is machine generated code located in traceEventClasses.hpp
  // Event<TraceId>::writeEvent() (pseudocode) contains the
  // necessary ResourceMark for the resource allocations below.
  // See traceEventClasses.xsl for details.
  void print_val(const char* label, const Method* const val) {
    const char* description = "NULL";
    if (val != NULL) {
      description = val->name_and_sig_as_C_string();
    }
    _st.print("%s = %s", label, description);
  }

  void print_val(const char* label, const char* val) {
    _st.print("%s = '%s'", label, val);
  }

  void print(const char* val) {
114
    _st.print("%s", val);
S
sla 已提交
115 116 117
  }
};

118 119
#endif // INCLUDE_TRACE
#endif // SHARE_VM_TRACE_TRACESTREAM_HPP