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