traceStream.hpp 3.2 KB
Newer Older
S
sla 已提交
1
/*
2
 * Copyright (c) 2012, 2018, 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
 * 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
30
#include "memory/resourceArea.hpp"
S
sla 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43
#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) {
44
    _st.print("%s = " UINT32_FORMAT, label, val);
S
sla 已提交
45 46 47
  }

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

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

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

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

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

  void print_val(const char* label, s8 val) {
68
    _st.print("%s = " INT64_FORMAT, label, (int64_t) val);
S
sla 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  }

  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);
  }

  void print_val(const char* label, const Klass* const val) {
84
    ResourceMark rm;
S
sla 已提交
85 86 87 88 89 90 91 92 93 94 95
    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);
  }

  void print_val(const char* label, const Method* const val) {
96
    ResourceMark rm;
S
sla 已提交
97 98 99 100 101 102 103 104 105 106 107 108
    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) {
109
    _st.print("%s", val);
S
sla 已提交
110 111 112
  }
};

113 114
#endif // INCLUDE_TRACE
#endif // SHARE_VM_TRACE_TRACESTREAM_HPP