src/share/vm/trace/traceStream.hpp

Thu, 23 Aug 2018 22:56:32 +0000

author
phh
date
Thu, 23 Aug 2018 22:56:32 +0000
changeset 9482
80ee2541504e
parent 9327
f96fcd9e1e1b
child 9572
624a0741915c
permissions
-rw-r--r--

8145788: JVM crashes with -XX:+EnableTracing
Summary: Events can trigger before ResourceMark is usable: move use from writeEvent() to print_val().
Reviewed-by: dholmes, ysuenaga, mlarsson

sla@5237 1 /*
phh@9482 2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
sla@5237 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sla@5237 4 *
sla@5237 5 * This code is free software; you can redistribute it and/or modify it
sla@5237 6 * under the terms of the GNU General Public License version 2 only, as
sla@5237 7 * published by the Free Software Foundation.
sla@5237 8 *
sla@5237 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sla@5237 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sla@5237 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sla@5237 12 * version 2 for more details (a copy is included in the LICENSE file that
sla@5237 13 * accompanied this code).
sla@5237 14 *
sla@5237 15 * You should have received a copy of the GNU General Public License version
sla@5237 16 * 2 along with this work; if not, write to the Free Software Foundation,
sla@5237 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sla@5237 18 *
sla@5237 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sla@5237 20 * or visit www.oracle.com if you need additional information or have any
sla@5237 21 * questions.
sla@5237 22 *
sla@5237 23 */
sla@5237 24
sla@5237 25 #ifndef SHARE_VM_TRACE_TRACESTREAM_HPP
sla@5237 26 #define SHARE_VM_TRACE_TRACESTREAM_HPP
sla@5237 27
sla@5237 28 #include "utilities/macros.hpp"
sla@5237 29 #if INCLUDE_TRACE
phh@9482 30 #include "memory/resourceArea.hpp"
sla@5237 31 #include "oops/klass.hpp"
sla@5237 32 #include "oops/method.hpp"
sla@5237 33 #include "oops/symbol.hpp"
sla@5237 34 #include "utilities/ostream.hpp"
sla@5237 35
sla@5237 36 class TraceStream : public StackObj {
sla@5237 37 private:
sla@5237 38 outputStream& _st;
sla@5237 39
sla@5237 40 public:
sla@5237 41 TraceStream(outputStream& stream): _st(stream) {}
sla@5237 42
sla@5237 43 void print_val(const char* label, u1 val) {
kevinw@9327 44 _st.print("%s = " UINT32_FORMAT, label, val);
sla@5237 45 }
sla@5237 46
sla@5237 47 void print_val(const char* label, u2 val) {
kevinw@9327 48 _st.print("%s = " UINT32_FORMAT, label, val);
sla@5237 49 }
sla@5237 50
sla@5237 51 void print_val(const char* label, s2 val) {
kevinw@9327 52 _st.print("%s = " INT32_FORMAT, label, val);
sla@5237 53 }
sla@5237 54
sla@5237 55 void print_val(const char* label, u4 val) {
kevinw@9327 56 _st.print("%s = " UINT32_FORMAT, label, val);
sla@5237 57 }
sla@5237 58
sla@5237 59 void print_val(const char* label, s4 val) {
kevinw@9327 60 _st.print("%s = " INT32_FORMAT, label, val);
sla@5237 61 }
sla@5237 62
sla@5237 63 void print_val(const char* label, u8 val) {
kevinw@9327 64 _st.print("%s = " UINT64_FORMAT, label, val);
sla@5237 65 }
sla@5237 66
sla@5237 67 void print_val(const char* label, s8 val) {
kevinw@9327 68 _st.print("%s = " INT64_FORMAT, label, (int64_t) val);
sla@5237 69 }
sla@5237 70
sla@5237 71 void print_val(const char* label, bool val) {
sla@5237 72 _st.print("%s = %s", label, val ? "true" : "false");
sla@5237 73 }
sla@5237 74
sla@5237 75 void print_val(const char* label, float val) {
sla@5237 76 _st.print("%s = %f", label, val);
sla@5237 77 }
sla@5237 78
sla@5237 79 void print_val(const char* label, double val) {
sla@5237 80 _st.print("%s = %f", label, val);
sla@5237 81 }
sla@5237 82
sla@5237 83 void print_val(const char* label, const Klass* const val) {
phh@9482 84 ResourceMark rm;
sla@5237 85 const char* description = "NULL";
sla@5237 86 if (val != NULL) {
sla@5237 87 Symbol* name = val->name();
sla@5237 88 if (name != NULL) {
sla@5237 89 description = name->as_C_string();
sla@5237 90 }
sla@5237 91 }
sla@5237 92 _st.print("%s = %s", label, description);
sla@5237 93 }
sla@5237 94
sla@5237 95 void print_val(const char* label, const Method* const val) {
phh@9482 96 ResourceMark rm;
sla@5237 97 const char* description = "NULL";
sla@5237 98 if (val != NULL) {
sla@5237 99 description = val->name_and_sig_as_C_string();
sla@5237 100 }
sla@5237 101 _st.print("%s = %s", label, description);
sla@5237 102 }
sla@5237 103
sla@5237 104 void print_val(const char* label, const char* val) {
sla@5237 105 _st.print("%s = '%s'", label, val);
sla@5237 106 }
sla@5237 107
sla@5237 108 void print(const char* val) {
drchase@6680 109 _st.print("%s", val);
sla@5237 110 }
sla@5237 111 };
sla@5237 112
mgronlun@7367 113 #endif // INCLUDE_TRACE
mgronlun@7367 114 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP

mercurial