1 /*
   2 * Copyright (c) 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 #include "precompiled.hpp"
  26 #include "trace/traceStream.hpp"
  27 #if INCLUDE_TRACE
  28 #include "classfile/classLoaderData.hpp"
  29 #include "classfile/javaClasses.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/klass.hpp"
  32 #include "oops/method.hpp"
  33 #include "oops/symbol.hpp"
  34 
  35 void TraceStream::print_val(const char* label, const Klass* val) const {
  36   ResourceMark rm;
  37   const char* description = "NULL";
  38   if (val != NULL) {
  39     const Symbol* name = val->name();
  40     if (name != NULL) {
  41       description = name->as_C_string();
  42     }
  43   }
  44   tty->print("%s = %s", label, description);
  45 }
  46 
  47 void TraceStream::print_val(const char* label, const Method* val) const {
  48   ResourceMark rm;
  49   const char* description = "NULL";
  50   if (val != NULL) {
  51     description = val->name_and_sig_as_C_string();
  52   }
  53   tty->print("%s = %s", label, description);
  54 }
  55 
  56 void TraceStream::print_val(const char* label, const ClassLoaderData* cld) const {
  57 /* guangyu.zgy not implemented yet
  58   ResourceMark rm;
  59   if (cld == NULL || cld->is_anonymous()) {
  60     tty->print("%s = NULL", label);
  61     return;
  62   }
  63   const char* class_loader_name = "NULL";
  64   const char* class_loader_type_name = "NULL";
  65   const oop class_loader_oop = cld->class_loader();
  66 
  67   if (class_loader_oop != NULL) {
  68     const Klass* k = class_loader_oop->klass();
  69     assert(k != NULL, "invariant");
  70     const Symbol* klass_name_sym = k->name();
  71     if (klass_name_sym != NULL) {
  72       class_loader_type_name = klass_name_sym->as_C_string();
  73     }
  74     const oop class_loader_name_oop =
  75       java_lang_ClassLoader::name(class_loader_oop);
  76     if (class_loader_name_oop != NULL) {
  77       const char* class_loader_name_from_oop =
  78         java_lang_String::as_utf8_string(class_loader_name_oop);
  79       if (class_loader_name_from_oop != NULL &&
  80             class_loader_name_from_oop[0] != '\0') {
  81         class_loader_name = class_loader_name_from_oop;
  82       }
  83     }
  84   } else {
  85     assert(class_loader_oop == NULL, "invariant");
  86     // anonymous CLDs are excluded, this would be the boot loader
  87     class_loader_name = "boot";
  88   }
  89   tty->print("%s = name=%s class=%s", label, class_loader_name, class_loader_type_name);
  90 */
  91 }
  92 
  93 #endif // INCLUDE_TRACE