src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp
author simonis
Tue, 19 Jun 2018 09:43:53 +0200
changeset 50625 d9753e3db0c6
parent 50572 6d4332f746ad
child 50634 c349d409262a
permissions -rw-r--r--
8204965: Fix '--disable-cds' and disable CDS on AIX by default Reviewed-by: erikj, jiangli, stuefe, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     1
/*
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     3
 * Copyright (c) 2018 SAP SE. All rights reserved.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     5
 *
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
     9
 *
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    14
 * accompanied this code).
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    15
 *
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    19
 *
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    22
 * questions.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    23
 *
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    24
 */
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    25
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    26
#include "precompiled.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    27
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    28
#include "classfile/classLoaderData.inline.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    29
#include "classfile/classLoaderHierarchyDCmd.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    30
#include "memory/allocation.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    31
#include "memory/resourceArea.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    32
#include "runtime/safepoint.hpp"
50572
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
    33
#include "oops/reflectionAccessorImplKlassHelper.hpp"
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    34
#include "utilities/globalDefinitions.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    35
#include "utilities/ostream.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    36
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    37
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    38
ClassLoaderHierarchyDCmd::ClassLoaderHierarchyDCmd(outputStream* output, bool heap)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    39
  : DCmdWithParser(output, heap)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    40
  , _show_classes("show-classes", "Print loaded classes.", "BOOLEAN", false, "false")
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    41
  , _verbose("verbose", "Print detailed information.", "BOOLEAN", false, "false") {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    42
  _dcmdparser.add_dcmd_option(&_show_classes);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    43
  _dcmdparser.add_dcmd_option(&_verbose);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    44
}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    45
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    46
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    47
int ClassLoaderHierarchyDCmd::num_arguments() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    48
  ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    49
  ClassLoaderHierarchyDCmd* dcmd = new ClassLoaderHierarchyDCmd(NULL, false);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    50
  if (dcmd != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    51
    DCmdMark mark(dcmd);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    52
    return dcmd->_dcmdparser.num_arguments();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    53
  } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    54
    return 0;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    55
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    56
}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    57
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    58
// Helper class for drawing the branches to the left of a node.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    59
class BranchTracker : public StackObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    60
  //       "<x>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    61
  //       " |---<y>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    62
  //       " |    |
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    63
  //       " |   <z>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    64
  //       " |    |---<z1>
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    65
  //       " |    |---<z2>
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    66
  //       ^^^^^^^ ^^^
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    67
  //        A       B
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    68
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    69
  // Some terms for the graphics:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    70
  // - branch: vertical connection between a node's ancestor to a later sibling.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    71
  // - branchwork: (A) the string to print as a prefix at the start of each line, contains all branches.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    72
  // - twig (B): Length of the dashed line connecting a node to its branch.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    73
  // - branch spacing: how many spaces between branches are printed.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    74
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    75
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    76
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    77
  enum { max_depth = 64, twig_len = 2, branch_spacing = 5 };
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    78
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    79
private:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    80
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    81
  char _branches[max_depth];
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    82
  int _pos;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    83
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    84
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    85
  BranchTracker()
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    86
    : _pos(0) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    87
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    88
  void push(bool has_branch) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    89
    if (_pos < max_depth) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    90
      _branches[_pos] = has_branch ? '|' : ' ';
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    91
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    92
    _pos ++; // beyond max depth, omit branch drawing but do count on.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    93
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    94
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    95
  void pop() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    96
    assert(_pos > 0, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    97
    _pos --;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    98
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    99
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   100
  void print(outputStream* st) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   101
    for (int i = 0; i < _pos; i ++) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   102
      st->print("%c%.*s", _branches[i], branch_spacing, "          ");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   103
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   104
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   105
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   106
  class Mark {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   107
    BranchTracker& _tr;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   108
  public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   109
    Mark(BranchTracker& tr, bool has_branch_here)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   110
      : _tr(tr)  { _tr.push(has_branch_here); }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   111
    ~Mark() { _tr.pop(); }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   112
  };
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   113
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   114
}; // end: BranchTracker
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   115
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   116
struct LoadedClassInfo : public ResourceObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   117
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   118
  LoadedClassInfo* _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   119
  Klass* const _klass;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   120
  const ClassLoaderData* const _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   121
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   122
  LoadedClassInfo(Klass* klass, const ClassLoaderData* cld)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   123
    : _klass(klass), _cld(cld) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   124
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   125
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   126
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   127
class LoaderTreeNode : public ResourceObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   128
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   129
  // We walk the CLDG and, for each CLD which is non-anonymous, add
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   130
  // a tree node. To add a node we need its parent node; if it itself
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   131
  // does not exist yet, we add a preliminary node for it. This preliminary
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   132
  // node just contains its loader oop; later, when encountering its CLD in
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   133
  // our CLDG walk, we complete the missing information in this node.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   134
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   135
  const oop _loader_oop;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   136
  const ClassLoaderData* _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   137
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   138
  LoaderTreeNode* _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   139
  LoaderTreeNode* _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   140
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   141
  LoadedClassInfo* _classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   142
  int _num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   143
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   144
  LoadedClassInfo* _anon_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   145
  int _num_anon_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   146
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   147
  void print_with_childs(outputStream* st, BranchTracker& branchtracker,
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   148
      bool print_classes, bool verbose) const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   149
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   150
    ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   151
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   152
    if (_cld == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   153
      // Not sure how this could happen: we added a preliminary node for a parent but then never encountered
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   154
      // its CLD?
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   155
      return;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   156
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   157
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   158
    // Retrieve information.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   159
    const Klass* const loader_klass = _cld->class_loader_klass();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   160
    const Symbol* const loader_name = _cld->class_loader_name();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   161
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   162
    branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   163
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   164
    // e.g. "+--- jdk.internal.reflect.DelegatingClassLoader"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   165
    st->print("+%.*s", BranchTracker::twig_len, "----------");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   166
    if (_cld->is_the_null_class_loader_data()) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   167
      st->print(" <bootstrap>");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   168
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   169
      if (loader_name != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   170
        st->print(" \"%s\",", loader_name->as_C_string());
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   171
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   172
      st->print(" %s", loader_klass != NULL ? loader_klass->external_name() : "??");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   173
      st->print(" {" PTR_FORMAT "}", p2i(_loader_oop));
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   174
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   175
    st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   176
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   177
    // Output following this node (node details and child nodes) - up to the next sibling node
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   178
    // needs to be prefixed with "|" if there is a follow up sibling.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   179
    const bool have_sibling = _next != NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   180
    BranchTracker::Mark trm(branchtracker, have_sibling);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   181
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   182
    {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   183
      // optional node details following this node needs to be prefixed with "|"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   184
      // if there are follow up child nodes.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   185
      const bool have_child = _child != NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   186
      BranchTracker::Mark trm(branchtracker, have_child);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   187
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   188
      // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   189
      branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   190
      st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   191
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   192
      const int indentation = 18;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   193
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   194
      if (verbose) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   195
        branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   196
        st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Data:", p2i(_cld));
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   197
        branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   198
        st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Klass:", p2i(loader_klass));
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   199
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   200
        // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   201
        branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   202
        st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   203
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   204
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   205
      if (print_classes) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   206
        if (_classes != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   207
          for (LoadedClassInfo* lci = _classes; lci; lci = lci->_next) {
50572
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   208
            // Non-anonymous classes should live in the primary CLD of its loader
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   209
            assert(lci->_cld == _cld, "must be");
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   210
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   211
            branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   212
            if (lci == _classes) { // first iteration
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   213
              st->print("%*s ", indentation, "Classes:");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   214
            } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   215
              st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   216
            }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   217
            st->print("%s", lci->_klass->external_name());
50572
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   218
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   219
            // Special treatment for generated core reflection accessor classes: print invocation target.
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   220
            if (ReflectionAccessorImplKlassHelper::is_generated_accessor(lci->_klass)) {
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   221
              st->print(" (invokes: ");
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   222
              ReflectionAccessorImplKlassHelper::print_invocation_target(st, lci->_klass);
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   223
              st->print(")");
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   224
            }
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   225
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   226
            st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   227
          }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   228
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   229
          st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   230
          st->print_cr("(%u class%s)", _num_classes, (_num_classes == 1) ? "" : "es");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   231
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   232
          // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   233
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   234
          st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   235
        }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   236
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   237
        if (_anon_classes != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   238
          for (LoadedClassInfo* lci = _anon_classes; lci; lci = lci->_next) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   239
            branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   240
            if (lci == _anon_classes) { // first iteration
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   241
              st->print("%*s ", indentation, "Anonymous Classes:");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   242
            } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   243
              st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   244
            }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   245
            st->print("%s", lci->_klass->external_name());
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   246
            // For anonymous classes, also print CLD if verbose. Should be a different one than the primary CLD.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   247
            assert(lci->_cld != _cld, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   248
            if (verbose) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   249
              st->print("  (CLD: " PTR_FORMAT ")", p2i(lci->_cld));
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   250
            }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   251
            st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   252
          }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   253
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   254
          st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   255
          st->print_cr("(%u anonymous class%s)", _num_anon_classes, (_num_anon_classes == 1) ? "" : "es");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   256
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   257
          // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   258
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   259
          st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   260
        }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   261
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   262
      } // end: print_classes
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   263
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   264
    } // Pop branchtracker mark
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   265
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   266
    // Print children, recursively
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   267
    LoaderTreeNode* c = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   268
    while (c != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   269
      c->print_with_childs(st, branchtracker, print_classes, verbose);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   270
      c = c->_next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   271
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   272
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   273
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   274
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   275
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   276
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   277
  LoaderTreeNode(const oop loader_oop)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   278
    : _loader_oop(loader_oop), _cld(NULL)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   279
    , _child(NULL), _next(NULL)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   280
    , _classes(NULL), _anon_classes(NULL)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   281
    , _num_classes(0), _num_anon_classes(0) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   282
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   283
  void set_cld(const ClassLoaderData* cld) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   284
    _cld = cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   285
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   286
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   287
  void add_child(LoaderTreeNode* info) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   288
    info->_next = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   289
    _child = info;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   290
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   291
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   292
  void add_sibling(LoaderTreeNode* info) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   293
    assert(info->_next == NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   294
    info->_next = _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   295
    _next = info;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   296
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   297
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   298
  void add_classes(LoadedClassInfo* first_class, int num_classes, bool anonymous) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   299
    LoadedClassInfo** p_list_to_add_to = anonymous ? &_anon_classes : &_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   300
    // Search tail.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   301
    while ((*p_list_to_add_to) != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   302
      p_list_to_add_to = &(*p_list_to_add_to)->_next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   303
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   304
    *p_list_to_add_to = first_class;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   305
    if (anonymous) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   306
      _num_anon_classes += num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   307
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   308
      _num_classes += num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   309
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   310
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   311
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   312
  const ClassLoaderData* cld() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   313
    return _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   314
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   315
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   316
  const oop loader_oop() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   317
    return _loader_oop;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   318
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   319
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   320
  LoaderTreeNode* find(const oop loader_oop) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   321
    LoaderTreeNode* result = NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   322
    if (_loader_oop == loader_oop) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   323
      result = this;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   324
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   325
      LoaderTreeNode* c = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   326
      while (c != NULL && result == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   327
        result = c->find(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   328
        c = c->_next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   329
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   330
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   331
    return result;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   332
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   333
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   334
  void print_with_childs(outputStream* st, bool print_classes, bool print_add_info) const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   335
    BranchTracker bwt;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   336
    print_with_childs(st, bwt, print_classes, print_add_info);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   337
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   338
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   339
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   340
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   341
class LoadedClassCollectClosure : public KlassClosure {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   342
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   343
  LoadedClassInfo* _list;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   344
  const ClassLoaderData* _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   345
  int _num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   346
  LoadedClassCollectClosure(const ClassLoaderData* cld)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   347
    : _list(NULL), _cld(cld), _num_classes(0) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   348
  void do_klass(Klass* k) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   349
    LoadedClassInfo* lki = new LoadedClassInfo(k, _cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   350
    lki->_next = _list;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   351
    _list = lki;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   352
    _num_classes ++;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   353
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   354
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   355
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   356
class LoaderInfoScanClosure : public CLDClosure {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   357
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   358
  const bool _print_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   359
  const bool _verbose;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   360
  LoaderTreeNode* _root;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   361
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   362
  static void fill_in_classes(LoaderTreeNode* info, const ClassLoaderData* cld) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   363
    assert(info != NULL && cld != NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   364
    LoadedClassCollectClosure lccc(cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   365
    const_cast<ClassLoaderData*>(cld)->classes_do(&lccc);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   366
    if (lccc._num_classes > 0) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   367
      info->add_classes(lccc._list, lccc._num_classes, cld->is_anonymous());
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   368
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   369
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   370
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   371
  LoaderTreeNode* find_node_or_add_empty_node(oop loader_oop) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   372
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   373
    assert(_root != NULL, "root node must exist");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   374
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   375
    if (loader_oop == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   376
      return _root;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   377
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   378
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   379
    // Check if a node for this oop already exists.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   380
    LoaderTreeNode* info = _root->find(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   381
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   382
    if (info == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   383
      // It does not. Create a node.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   384
      info = new LoaderTreeNode(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   385
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   386
      // Add it to tree.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   387
      LoaderTreeNode* parent_info = NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   388
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   389
      // Recursively add parent nodes if needed.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   390
      const oop parent_oop = java_lang_ClassLoader::parent(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   391
      if (parent_oop == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   392
        parent_info = _root;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   393
      } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   394
        parent_info = find_node_or_add_empty_node(parent_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   395
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   396
      assert(parent_info != NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   397
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   398
      parent_info->add_child(info);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   399
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   400
    return info;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   401
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   402
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   403
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   404
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   405
  LoaderInfoScanClosure(bool print_classes, bool verbose)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   406
    : _print_classes(print_classes), _verbose(verbose), _root(NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   407
    _root = new LoaderTreeNode(NULL);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   408
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   409
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   410
  void print_results(outputStream* st) const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   411
    _root->print_with_childs(st, _print_classes, _verbose);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   412
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   413
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   414
  void do_cld (ClassLoaderData* cld) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   415
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   416
    // We do not display unloading loaders, for now.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   417
    if (cld->is_unloading()) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   418
      return;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   419
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   420
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   421
    const oop loader_oop = cld->class_loader();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   422
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   423
    LoaderTreeNode* info = find_node_or_add_empty_node(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   424
    assert(info != NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   425
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   426
    // Update CLD in node, but only if this is the primary CLD for this loader.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   427
    if (cld->is_anonymous() == false) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   428
      assert(info->cld() == NULL, "there should be only one primary CLD per loader");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   429
      info->set_cld(cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   430
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   431
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   432
    // Add classes.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   433
    fill_in_classes(info, cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   434
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   435
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   436
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   437
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   438
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   439
class ClassLoaderHierarchyVMOperation : public VM_Operation {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   440
  outputStream* const _out;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   441
  const bool _show_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   442
  const bool _verbose;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   443
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   444
  ClassLoaderHierarchyVMOperation(outputStream* out, bool show_classes, bool verbose) :
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   445
    _out(out), _show_classes(show_classes), _verbose(verbose)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   446
  {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   447
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   448
  VMOp_Type type() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   449
    return VMOp_ClassLoaderHierarchyOperation;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   450
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   451
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   452
  void doit() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   453
    assert(SafepointSynchronize::is_at_safepoint(), "must be a safepoint");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   454
    ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   455
    LoaderInfoScanClosure cl (_show_classes, _verbose);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   456
    ClassLoaderDataGraph::cld_do(&cl);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   457
    cl.print_results(_out);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   458
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   459
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   460
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   461
// This command needs to be executed at a safepoint.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   462
void ClassLoaderHierarchyDCmd::execute(DCmdSource source, TRAPS) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   463
  ClassLoaderHierarchyVMOperation op(output(), _show_classes.value(), _verbose.value());
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   464
  VMThread::execute(&op);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   465
}