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/resourceArea.hpp"
31 #include "oops/klass.hpp"
32 #include "oops/method.hpp"
33 #include "oops/symbol.hpp"
34 #include "utilities/ostream.hpp"
35
36 class TraceStream : public StackObj {
37 private:
38 outputStream& _st;
39
40 public:
41 TraceStream(outputStream& stream): _st(stream) {}
42
43 void print_val(const char* label, u1 val) {
44 _st.print("%s = " UINT32_FORMAT, label, val);
45 }
46
47 void print_val(const char* label, u2 val) {
48 _st.print("%s = " UINT32_FORMAT, label, val);
49 }
84 ResourceMark rm;
85 const char* description = "NULL";
86 if (val != NULL) {
87 Symbol* name = val->name();
88 if (name != NULL) {
89 description = name->as_C_string();
90 }
91 }
92 _st.print("%s = %s", label, description);
93 }
94
95 void print_val(const char* label, const Method* const val) {
96 ResourceMark rm;
97 const char* description = "NULL";
98 if (val != NULL) {
99 description = val->name_and_sig_as_C_string();
100 }
101 _st.print("%s = %s", label, description);
102 }
103
104 void print_val(const char* label, const char* val) {
105 _st.print("%s = '%s'", label, val);
106 }
107
108 void print(const char* val) {
109 _st.print("%s", val);
110 }
111 };
112
113 #endif // INCLUDE_TRACE
114 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP
|
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 "classfile/classLoaderData.hpp"
31 #include "classfile/javaClasses.inline.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "oops/klass.hpp"
34 #include "oops/method.hpp"
35 #include "oops/symbol.hpp"
36 #include "utilities/ostream.hpp"
37
38 class TraceStream : public StackObj {
39 private:
40 outputStream& _st;
41
42 public:
43 TraceStream(outputStream& stream): _st(stream) {}
44
45 void print_val(const char* label, u1 val) {
46 _st.print("%s = " UINT32_FORMAT, label, val);
47 }
48
49 void print_val(const char* label, u2 val) {
50 _st.print("%s = " UINT32_FORMAT, label, val);
51 }
86 ResourceMark rm;
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 void print_val(const char* label, const Method* const val) {
98 ResourceMark rm;
99 const char* description = "NULL";
100 if (val != NULL) {
101 description = val->name_and_sig_as_C_string();
102 }
103 _st.print("%s = %s", label, description);
104 }
105
106 void print_val(const char* label, const ClassLoaderData* const cld) {
107 ResourceMark rm;
108 if (cld == NULL || cld->is_anonymous()) {
109 _st.print("%s = NULL", label);
110 return;
111 }
112 const oop class_loader_oop = cld->class_loader();
113 if (class_loader_oop == NULL) {
114 _st.print("%s = NULL", label);
115 return;
116 }
117 const char* class_loader_name = "NULL";
118 const char* klass_name = "NULL";
119 const oop class_loader_name_oop =
120 java_lang_ClassLoader::name(class_loader_oop);
121 if (class_loader_name_oop != NULL) {
122 class_loader_name =
123 java_lang_String::as_utf8_string(class_loader_name_oop);
124 }
125 const Klass* const k = class_loader_oop->klass();
126 const Symbol* klass_name_sym = k->name();
127 if (klass_name_sym != NULL) {
128 klass_name = klass_name_sym->as_C_string();
129 }
130 _st.print("%s = name=%s class=%s", label, class_loader_name, klass_name);
131 }
132
133 void print_val(const char* label, const char* val) {
134 _st.print("%s = '%s'", label, val);
135 }
136
137 void print(const char* val) {
138 _st.print("%s", val);
139 }
140 };
141
142 #endif // INCLUDE_TRACE
143 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP
|