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