src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 52586 74109912c738
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
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"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51681
diff changeset
    29
#include "classfile/classLoaderDataGraph.hpp"
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    30
#include "classfile/classLoaderHierarchyDCmd.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    31
#include "memory/allocation.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    32
#include "memory/resourceArea.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    33
#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
    34
#include "oops/reflectionAccessorImplKlassHelper.hpp"
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    35
#include "utilities/globalDefinitions.hpp"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    36
#include "utilities/ostream.hpp"
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
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    39
ClassLoaderHierarchyDCmd::ClassLoaderHierarchyDCmd(outputStream* output, bool heap)
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
    40
  : DCmdWithParser(output, heap),
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
    41
   _show_classes("show-classes", "Print loaded classes.", "BOOLEAN", false, "false"),
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
    42
  _verbose("verbose", "Print detailed information.", "BOOLEAN", false, "false"),
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
    43
  _fold("fold", "Show loaders of the same name and class as one.", "BOOLEAN", true, "true") {
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    44
  _dcmdparser.add_dcmd_option(&_show_classes);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    45
  _dcmdparser.add_dcmd_option(&_verbose);
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
    46
  _dcmdparser.add_dcmd_option(&_fold);
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    47
}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    48
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    49
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    50
int ClassLoaderHierarchyDCmd::num_arguments() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    51
  ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    52
  ClassLoaderHierarchyDCmd* dcmd = new ClassLoaderHierarchyDCmd(NULL, false);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    53
  if (dcmd != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    54
    DCmdMark mark(dcmd);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    55
    return dcmd->_dcmdparser.num_arguments();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    56
  } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    57
    return 0;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    58
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    59
}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    60
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    61
// 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
    62
class BranchTracker : public StackObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    63
  //       "<x>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    64
  //       " |---<y>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    65
  //       " |    |
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    66
  //       " |   <z>"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    67
  //       " |    |---<z1>
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    68
  //       " |    |---<z2>
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    69
  //       ^^^^^^^ ^^^
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    70
  //        A       B
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    71
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    72
  // Some terms for the graphics:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    73
  // - 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
    74
  // - 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
    75
  // - 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
    76
  // - 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
    77
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    78
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    79
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    80
  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
    81
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    82
private:
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
  char _branches[max_depth];
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    85
  int _pos;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    86
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    87
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    88
  BranchTracker()
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    89
    : _pos(0) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    90
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    91
  void push(bool has_branch) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    92
    if (_pos < max_depth) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    93
      _branches[_pos] = has_branch ? '|' : ' ';
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
    _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
    96
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    97
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    98
  void pop() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
    99
    assert(_pos > 0, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   100
    _pos --;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   101
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   102
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   103
  void print(outputStream* st) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   104
    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
   105
      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
   106
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   107
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   108
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   109
  class Mark {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   110
    BranchTracker& _tr;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   111
  public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   112
    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
   113
      : _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
   114
    ~Mark() { _tr.pop(); }
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
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   117
}; // end: BranchTracker
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   118
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   119
struct LoadedClassInfo : public ResourceObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   120
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   121
  LoadedClassInfo* _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   122
  Klass* const _klass;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   123
  const ClassLoaderData* const _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
  LoadedClassInfo(Klass* klass, const ClassLoaderData* cld)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   126
    : _klass(klass), _cld(cld) {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   127
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
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   130
class LoaderTreeNode : public ResourceObj {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   131
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   132
  // We walk the CLDG and, for each CLD which is non-unsafe_anonymous, add
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   133
  // a tree node.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   134
  // To add a node we need its parent node; if the parent node does not yet
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   135
  // exist - because we have not yet encountered the CLD for the parent loader -
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   136
  // we add a preliminary empty LoaderTreeNode for it. This preliminary node
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   137
  // just contains the loader oop and nothing else. Once we encounter the CLD of
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   138
  // this parent loader, we fill in all the other details.
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   139
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   140
  const oop _loader_oop;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   141
  const ClassLoaderData* _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   142
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   143
  LoaderTreeNode* _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   144
  LoaderTreeNode* _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   145
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   146
  LoadedClassInfo* _classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   147
  int _num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   148
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   149
  LoadedClassInfo* _anon_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   150
  int _num_anon_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   151
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   152
  // In default view, similar tree nodes (same loader class, same name or no name)
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   153
  // are folded into each other to make the output more readable.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   154
  // _num_folded contains the number of nodes which have been folded into this
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   155
  // one.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   156
  int _num_folded;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   157
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   158
  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
   159
      bool print_classes, bool verbose) const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   160
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   161
    ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   162
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   163
    if (_cld == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   164
      // 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
   165
      // its CLD?
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   166
      return;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   167
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   168
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   169
    // Retrieve information.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   170
    const Klass* const loader_klass = _cld->class_loader_klass();
50634
c349d409262a 8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents: 50572
diff changeset
   171
    const Symbol* const loader_name = _cld->name();
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   172
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   173
    branchtracker.print(st);
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
    // e.g. "+--- jdk.internal.reflect.DelegatingClassLoader"
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   176
    st->print("+%.*s", BranchTracker::twig_len, "----------");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   177
    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
   178
      st->print(" <bootstrap>");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   179
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   180
      if (loader_name != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   181
        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
   182
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   183
      st->print(" %s", loader_klass != NULL ? loader_klass->external_name() : "??");
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   184
      if (_num_folded > 0) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   185
        st->print(" (+ %d more)", _num_folded);
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   186
      }
50443
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
    st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   189
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   190
    // 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
   191
    // 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
   192
    const bool have_sibling = _next != NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   193
    BranchTracker::Mark trm(branchtracker, have_sibling);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   194
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   195
    {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   196
      // 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
   197
      // 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
   198
      const bool have_child = _child != NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   199
      BranchTracker::Mark trm(branchtracker, have_child);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   200
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   201
      // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   202
      branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   203
      st->cr();
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
      const int indentation = 18;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   206
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   207
      if (verbose) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   208
        branchtracker.print(st);
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   209
        st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Oop:", p2i(_loader_oop));
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   210
        branchtracker.print(st);
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   211
        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
   212
        branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   213
        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
   214
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   215
        // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   216
        branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   217
        st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   218
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   219
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   220
      if (print_classes) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   221
        if (_classes != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   222
          for (LoadedClassInfo* lci = _classes; lci; lci = lci->_next) {
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   223
            // Non-unsafe anonymous classes should live in the primary CLD of its loader
50572
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   224
            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
   225
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   226
            branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   227
            if (lci == _classes) { // first iteration
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   228
              st->print("%*s ", indentation, "Classes:");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   229
            } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   230
              st->print("%*s ", indentation, "");
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
            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
   233
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   234
            // 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
   235
            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
   236
              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
   237
              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
   238
              st->print(")");
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   239
            }
6d4332f746ad 8203343: VM.{metaspace|classloaders|classhierarchy...} jcmd should show invocation targets for Generated{Method|Constructor}AccessorImpl classes
stuefe
parents: 50443
diff changeset
   240
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   241
            st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   242
          }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   243
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   244
          st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   245
          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
   246
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   247
          // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   248
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   249
          st->cr();
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
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   252
        if (_anon_classes != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   253
          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
   254
            branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   255
            if (lci == _anon_classes) { // first iteration
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   256
              st->print("%*s ", indentation, "Unsafe Anonymous Classes:");
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   257
            } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   258
              st->print("%*s ", indentation, "");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   259
            }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   260
            st->print("%s", lci->_klass->external_name());
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   261
            // For unsafe anonymous classes, also print CLD if verbose. Should be a different one than the primary CLD.
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   262
            assert(lci->_cld != _cld, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   263
            if (verbose) {
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   264
              st->print("  (Loader Data: " PTR_FORMAT ")", p2i(lci->_cld));
50443
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
            st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   267
          }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   268
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   269
          st->print("%*s ", indentation, "");
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   270
          st->print_cr("(%u unsafe anonymous class%s)", _num_anon_classes, (_num_anon_classes == 1) ? "" : "es");
50443
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
          // Empty line
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   273
          branchtracker.print(st);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   274
          st->cr();
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   275
        }
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
      } // end: print_classes
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   278
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   279
    } // Pop branchtracker mark
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   280
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   281
    // Print children, recursively
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   282
    LoaderTreeNode* c = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   283
    while (c != NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   284
      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
   285
      c = c->_next;
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
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   288
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   289
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   290
  // Helper: Attempt to fold this node into the target node. If success, returns true.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   291
  // Folding can be done if both nodes are leaf nodes and they refer to the same loader class
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   292
  // and they have the same name or no name (note: leaf check is done by caller).
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   293
  bool can_fold_into(LoaderTreeNode* target_node) const {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   294
    assert(is_leaf() && target_node->is_leaf(), "must be leaf");
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   295
    return _cld->class_loader_klass() == target_node->_cld->class_loader_klass() &&
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   296
           _cld->name() == target_node->_cld->name();
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   297
  }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   298
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   299
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   300
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   301
  LoaderTreeNode(const oop loader_oop)
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   302
    : _loader_oop(loader_oop), _cld(NULL), _child(NULL), _next(NULL),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50863
diff changeset
   303
      _classes(NULL), _num_classes(0), _anon_classes(NULL), _num_anon_classes(0),
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   304
      _num_folded(0)
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   305
    {}
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   306
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   307
  void set_cld(const ClassLoaderData* cld) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   308
    _cld = cld;
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
  void add_child(LoaderTreeNode* info) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   312
    info->_next = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   313
    _child = info;
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
  void add_sibling(LoaderTreeNode* info) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   317
    assert(info->_next == NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   318
    info->_next = _next;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   319
    _next = info;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   320
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   321
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   322
  void add_classes(LoadedClassInfo* first_class, int num_classes, bool is_unsafe_anonymous) {
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   323
    LoadedClassInfo** p_list_to_add_to = is_unsafe_anonymous ? &_anon_classes : &_classes;
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   324
    // Search tail.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   325
    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
   326
      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
   327
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   328
    *p_list_to_add_to = first_class;
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   329
    if (is_unsafe_anonymous) {
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   330
      _num_anon_classes += num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   331
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   332
      _num_classes += num_classes;
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
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   335
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   336
  const ClassLoaderData* cld() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   337
    return _cld;
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
  const oop loader_oop() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   341
    return _loader_oop;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   342
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   343
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   344
  LoaderTreeNode* find(const oop loader_oop) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   345
    LoaderTreeNode* result = NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   346
    if (_loader_oop == loader_oop) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   347
      result = this;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   348
    } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   349
      LoaderTreeNode* c = _child;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   350
      while (c != NULL && result == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   351
        result = c->find(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   352
        c = c->_next;
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
    return result;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   356
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   357
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   358
  bool is_leaf() const { return _child == NULL; }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   359
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   360
  // Attempt to fold similar nodes among this node's children. We only fold leaf nodes
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   361
  // (no child class loaders).
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   362
  // For non-leaf nodes (class loaders with child class loaders), do this recursivly.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   363
  void fold_children() {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   364
    LoaderTreeNode* node = _child;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   365
    LoaderTreeNode* prev = NULL;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   366
    while (node != NULL) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   367
      LoaderTreeNode* matching_node = NULL;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   368
      if (node->is_leaf()) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   369
        // Look among the preceeding node siblings for a match.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   370
        for (LoaderTreeNode* node2 = _child; node2 != node && matching_node == NULL;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   371
            node2 = node2->_next) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   372
          if (node2->is_leaf() && node->can_fold_into(node2)) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   373
            matching_node = node2;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   374
          }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   375
        }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   376
      } else {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   377
        node->fold_children();
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   378
      }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   379
      if (matching_node != NULL) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   380
        // Increase fold count for the matching node and remove folded node from the child list.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   381
        matching_node->_num_folded ++;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   382
        assert(prev != NULL, "Sanity"); // can never happen since we do not fold the first node.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   383
        prev->_next = node->_next;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   384
      } else {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   385
        prev = node;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   386
      }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   387
      node = node->_next;
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   388
    }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   389
  }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   390
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   391
  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
   392
    BranchTracker bwt;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   393
    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
   394
  }
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
};
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
class LoadedClassCollectClosure : public KlassClosure {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   399
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   400
  LoadedClassInfo* _list;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   401
  const ClassLoaderData* _cld;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   402
  int _num_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   403
  LoadedClassCollectClosure(const ClassLoaderData* cld)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   404
    : _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
   405
  void do_klass(Klass* k) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   406
    LoadedClassInfo* lki = new LoadedClassInfo(k, _cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   407
    lki->_next = _list;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   408
    _list = lki;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   409
    _num_classes ++;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   410
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   411
};
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
class LoaderInfoScanClosure : public CLDClosure {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   414
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   415
  const bool _print_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   416
  const bool _verbose;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   417
  LoaderTreeNode* _root;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   418
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   419
  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
   420
    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
   421
    LoadedClassCollectClosure lccc(cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   422
    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
   423
    if (lccc._num_classes > 0) {
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   424
      info->add_classes(lccc._list, lccc._num_classes, cld->is_unsafe_anonymous());
50443
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
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   427
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   428
  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
   429
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   430
    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
   431
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   432
    if (loader_oop == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   433
      return _root;
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
    // 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
   437
    LoaderTreeNode* info = _root->find(loader_oop);
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
    if (info == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   440
      // It does not. Create a node.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   441
      info = new LoaderTreeNode(loader_oop);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   442
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   443
      // Add it to tree.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   444
      LoaderTreeNode* parent_info = NULL;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   445
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   446
      // Recursively add parent nodes if needed.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   447
      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
   448
      if (parent_oop == NULL) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   449
        parent_info = _root;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   450
      } else {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   451
        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
   452
      }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   453
      assert(parent_info != NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   454
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   455
      parent_info->add_child(info);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   456
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   457
    return info;
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
public:
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   462
  LoaderInfoScanClosure(bool print_classes, bool verbose)
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   463
    : _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
   464
    _root = new LoaderTreeNode(NULL);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   465
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   466
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   467
  void print_results(outputStream* st) const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   468
    _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
   469
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   470
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   471
  void do_cld (ClassLoaderData* cld) {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   472
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   473
    // We do not display unloading loaders, for now.
51681
72bdaf11dd6a 8210233: Prepare Klass::is_loader_alive() for concurrent class unloading
eosterlund
parents: 51444
diff changeset
   474
    if (!cld->is_alive()) {
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   475
      return;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   476
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   477
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   478
    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
   479
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   480
    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
   481
    assert(info != NULL, "must be");
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   482
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   483
    // Update CLD in node, but only if this is the primary CLD for this loader.
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51334
diff changeset
   484
    if (cld->is_unsafe_anonymous() == false) {
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   485
      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
   486
      info->set_cld(cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   487
    }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   488
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   489
    // Add classes.
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   490
    fill_in_classes(info, cld);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   491
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   492
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   493
  void fold() {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   494
    _root->fold_children();
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   495
  }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   496
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   497
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   498
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   499
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   500
class ClassLoaderHierarchyVMOperation : public VM_Operation {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   501
  outputStream* const _out;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   502
  const bool _show_classes;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   503
  const bool _verbose;
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   504
  const bool _fold;
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   505
public:
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   506
  ClassLoaderHierarchyVMOperation(outputStream* out, bool show_classes, bool verbose, bool fold) :
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   507
    _out(out), _show_classes(show_classes), _verbose(verbose), _fold(fold)
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   508
  {}
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   509
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   510
  VMOp_Type type() const {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   511
    return VMOp_ClassLoaderHierarchyOperation;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   512
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   513
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   514
  void doit() {
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   515
    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
   516
    ResourceMark rm;
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   517
    LoaderInfoScanClosure cl (_show_classes, _verbose);
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 51959
diff changeset
   518
    ClassLoaderDataGraph::loaded_cld_do(&cl);
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   519
    // In non-verbose and non-show-classes mode, attempt to fold the tree.
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   520
    if (_fold) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   521
      if (!_verbose && !_show_classes) {
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   522
        cl.fold();
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   523
      }
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   524
    }
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   525
    cl.print_results(_out);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   526
  }
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   527
};
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   528
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   529
// 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
   530
void ClassLoaderHierarchyDCmd::execute(DCmdSource source, TRAPS) {
50863
9084fd587141 8205531: jcmd VM.classloaders should fold similar loaders
stuefe
parents: 50634
diff changeset
   531
  ClassLoaderHierarchyVMOperation op(output(), _show_classes.value(), _verbose.value(), _fold.value());
50443
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   532
  VMThread::execute(&op);
8e56de95ce10 8203682: Add jcmd "VM.classloaders" command to print out class loader hierarchy, details
stuefe
parents:
diff changeset
   533
}