hotspot/src/share/vm/trace/traceStream.cpp
author mgronlun
Wed, 07 Dec 2016 23:38:37 +0100
changeset 42643 f4b39e85487d
permissions -rw-r--r--
8170847: Refactor trace/traceStream.hpp Reviewed-by: coleenp, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42643
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     1
/*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     4
*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     7
* published by the Free Software Foundation.
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     8
*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    13
* accompanied this code).
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    14
*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    18
*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    21
* questions.
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    22
*
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    23
*/
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    24
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    25
#include "precompiled.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    26
#include "trace/traceStream.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    27
#if INCLUDE_TRACE
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    28
#include "classfile/classLoaderData.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    29
#include "classfile/javaClasses.inline.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    30
#include "memory/resourceArea.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    31
#include "oops/klass.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    32
#include "oops/method.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    33
#include "oops/symbol.hpp"
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    34
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    35
void TraceStream::print_val(const char* label, const Klass* val) const {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    36
  ResourceMark rm;
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    37
  const char* description = "NULL";
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    38
  if (val != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    39
    const Symbol* name = val->name();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    40
    if (name != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    41
      description = name->as_C_string();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    42
    }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    43
  }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    44
  tty->print("%s = %s", label, description);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    45
}
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    46
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    47
void TraceStream::print_val(const char* label, const Method* val) const {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    48
  ResourceMark rm;
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    49
  const char* description = "NULL";
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    50
  if (val != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    51
    description = val->name_and_sig_as_C_string();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    52
  }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    53
  tty->print("%s = %s", label, description);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    54
}
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    55
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    56
void TraceStream::print_val(const char* label, const ClassLoaderData* cld) const {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    57
  ResourceMark rm;
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    58
  if (cld == NULL || cld->is_anonymous()) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    59
    tty->print("%s = NULL", label);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    60
    return;
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    61
  }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    62
  const char* class_loader_name = "NULL";
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    63
  const char* class_loader_type_name = "NULL";
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    64
  const oop class_loader_oop = cld->class_loader();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    65
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    66
  if (class_loader_oop != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    67
    const Klass* k = class_loader_oop->klass();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    68
    assert(k != NULL, "invariant");
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    69
    const Symbol* klass_name_sym = k->name();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    70
    if (klass_name_sym != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    71
      class_loader_type_name = klass_name_sym->as_C_string();
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    72
    }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    73
    const oop class_loader_name_oop =
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    74
      java_lang_ClassLoader::name(class_loader_oop);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    75
    if (class_loader_name_oop != NULL) {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    76
      const char* class_loader_name_from_oop =
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    77
        java_lang_String::as_utf8_string(class_loader_name_oop);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    78
      if (class_loader_name_from_oop != NULL &&
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    79
            class_loader_name_from_oop[0] != '\0') {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    80
        class_loader_name = class_loader_name_from_oop;
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    81
      }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    82
    }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    83
  } else {
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    84
    assert(class_loader_oop == NULL, "invariant");
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    85
    // anonymous CLDs are excluded, this would be the boot loader
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    86
    class_loader_name = "boot";
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    87
  }
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    88
  tty->print("%s = name=%s class=%s", label, class_loader_name, class_loader_type_name);
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    89
}
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    90
f4b39e85487d 8170847: Refactor trace/traceStream.hpp
mgronlun
parents:
diff changeset
    91
#endif // INCLUDE_TRACE