src/share/vm/trace/traceStream.hpp

Print this page
rev 12373 : 8170847: Refactor trace/traceStream.hpp
Reviewed-by:


  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   }
  52 
  53   void print_val(const char* label, s2 val) {
  54     _st.print("%s = " INT32_FORMAT, label, val);
  55   }
  56 
  57   void print_val(const char* label, u4 val) {
  58     _st.print("%s = " UINT32_FORMAT, label, val);
  59   }
  60 
  61   void print_val(const char* label, s4 val) {
  62     _st.print("%s = " INT32_FORMAT, label, val);
  63   }
  64 
  65   void print_val(const char* label, u8 val) {
  66     _st.print("%s = " UINT64_FORMAT, label, val);
  67   }
  68 
  69   void print_val(const char* label, s8 val) {
  70     _st.print("%s = " INT64_FORMAT, label, (int64_t) val);
  71   }
  72 
  73   void print_val(const char* label, bool val) {
  74     _st.print("%s = %s", label, val ? "true" : "false");
  75   }
  76 
  77   void print_val(const char* label, float val) {
  78     _st.print("%s = %f", label, val);
  79   }
  80 
  81   void print_val(const char* label, double val) {
  82     _st.print("%s = %f", label, val);
  83   }
  84 
  85   void print_val(const char* label, const Klass* const val) {
  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


  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/allocation.hpp"
  31 #include "utilities/debug.hpp"




  32 #include "utilities/ostream.hpp"
  33 
  34 class Klass;
  35 class Method;
  36 class ClassLoaderData;
  37 
  38 class TraceStream : public StackObj {
  39  public:
  40   TraceStream() {
  41     assert(tty != NULL, "invariant");


  42   }
  43 
  44   void print(const char* val) const {
  45     tty->print("%s", val);
  46   }
  47 
  48   void print_val(const char* label, u1 val) const {
  49     tty->print("%s = " UINT32_FORMAT, label, val);
  50   }
  51 
  52   void print_val(const char* label, u2 val) const {
  53     tty->print("%s = " UINT32_FORMAT, label, val);
  54   }
  55 
  56   void print_val(const char* label, s2 val) const {
  57     tty->print("%s = " INT32_FORMAT, label, val);
  58   }
  59 
  60   void print_val(const char* label, u4 val) const {
  61     tty->print("%s = " UINT32_FORMAT, label, val);
  62   }
  63 
  64   void print_val(const char* label, s4 val) const {
  65     tty->print("%s = " INT32_FORMAT, label, val);
  66   }
  67 
  68   void print_val(const char* label, u8 val) const {
  69     tty->print("%s = " UINT64_FORMAT, label, val);
  70   }
  71 
  72   void print_val(const char* label, s8 val) const {
  73     tty->print("%s = " INT64_FORMAT, label, (int64_t) val);
  74   }
  75 
  76   void print_val(const char* label, bool val) const {
  77     tty->print("%s = %s", label, val ? "true" : "false");
  78   }
  79 
  80   void print_val(const char* label, float val) const {
  81     tty->print("%s = %f", label, val);








  82   }
  83 
  84   void print_val(const char* label, double val) const {
  85     tty->print("%s = %f", label, val);





  86   }
  87 
  88   void print_val(const char* label, const char* val) const {
  89     tty->print("%s = '%s'", label, val);























  90   }
  91 
  92   void print_val(const char* label, const Klass* val) const;
  93   void print_val(const char* label, const Method* val)const ;
  94   void print_val(const char* label, const ClassLoaderData* cld) const;




  95 };
  96 
  97 #endif // INCLUDE_TRACE
  98 #endif // SHARE_VM_TRACE_TRACESTREAM_HPP