src/hotspot/share/memory/metaspace/metaspaceDCmd.cpp
author dcubed
Sat, 21 Sep 2019 10:13:25 -0400
changeset 58252 14c1ff687621
parent 51334 cc2c79d22508
child 58063 bdf136b8ae0e
permissions -rw-r--r--
8231323: ProblemList jdk/jfr/jcmd/TestJcmdConfigure.java Reviewed-by: ysuenaga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     1
/*
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
50309
37ebfe8bac7f 8203219: VM.metaspace jcmd should optionally show loaded classes for loaders
stuefe
parents: 50021
diff changeset
     3
 * Copyright (c) 2018, SAP and/or its affiliates.
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     5
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     8
 * published by the Free Software Foundation.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
     9
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    14
 * accompanied this code).
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    15
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    19
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    22
 * questions.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    23
 *
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    24
 */
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    25
#include "precompiled.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    26
#include "memory/metaspace.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    27
#include "memory/metaspace/metaspaceDCmd.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    28
#include "memory/resourceArea.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    29
#include "services/diagnosticCommand.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    30
#include "services/nmtCommon.hpp"
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    31
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    32
namespace metaspace {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    33
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    34
MetaspaceDCmd::MetaspaceDCmd(outputStream* output, bool heap)
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    35
  : DCmdWithParser(output, heap)
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    36
  , _basic("basic", "Prints a basic summary (does not need a safepoint).", "BOOLEAN", false, "false")
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    37
  , _show_loaders("show-loaders", "Shows usage by class loader.", "BOOLEAN", false, "false")
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50309
diff changeset
    38
  , _by_spacetype("by-spacetype", "Break down numbers by loader type.", "BOOLEAN", false, "false")
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    39
  , _by_chunktype("by-chunktype", "Break down numbers by chunk type.", "BOOLEAN", false, "false")
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    40
  , _show_vslist("vslist", "Shows details about the underlying virtual space.", "BOOLEAN", false, "false")
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    41
  , _show_vsmap("vsmap", "Shows chunk composition of the underlying virtual spaces", "BOOLEAN", false, "false")
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    42
  , _scale("scale", "Memory usage in which to scale. Valid values are: 1, KB, MB or GB (fixed scale) "
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    43
           "or \"dynamic\" for a dynamically choosen scale.",
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50309
diff changeset
    44
           "STRING", false, "dynamic")
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50309
diff changeset
    45
  , _show_classes("show-classes", "If show-loaders is set, shows loaded classes for each loader.", "BOOLEAN", false, "false")
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    46
{
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    47
  _dcmdparser.add_dcmd_option(&_basic);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    48
  _dcmdparser.add_dcmd_option(&_show_loaders);
50309
37ebfe8bac7f 8203219: VM.metaspace jcmd should optionally show loaded classes for loaders
stuefe
parents: 50021
diff changeset
    49
  _dcmdparser.add_dcmd_option(&_show_classes);
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    50
  _dcmdparser.add_dcmd_option(&_by_chunktype);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    51
  _dcmdparser.add_dcmd_option(&_by_spacetype);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    52
  _dcmdparser.add_dcmd_option(&_show_vslist);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    53
  _dcmdparser.add_dcmd_option(&_show_vsmap);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    54
  _dcmdparser.add_dcmd_option(&_scale);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    55
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    56
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    57
int MetaspaceDCmd::num_arguments() {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    58
  ResourceMark rm;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    59
  MetaspaceDCmd* dcmd = new MetaspaceDCmd(NULL, false);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    60
  if (dcmd != NULL) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    61
    DCmdMark mark(dcmd);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    62
    return dcmd->_dcmdparser.num_arguments();
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    63
  } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    64
    return 0;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    65
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    66
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    67
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    68
void MetaspaceDCmd::execute(DCmdSource source, TRAPS) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    69
  // Parse scale value.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    70
  const char* scale_value = _scale.value();
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    71
  size_t scale = 0;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    72
  if (scale_value != NULL) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    73
    if (strcasecmp("dynamic", scale_value) == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    74
      scale = 0;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    75
    } else {
50021
b8308d6356e7 8202684: Minimal VM build is broken after JDK-8199067, JDK-8202638
shade
parents: 49980
diff changeset
    76
      scale = NMT_ONLY(NMTUtil::scale_from_name(scale_value)) NOT_NMT(0);
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    77
      if (scale == 0) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    78
        output()->print_cr("Invalid scale: \"%s\". Will use dynamic scaling.", scale_value);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    79
      }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    80
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    81
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    82
  if (_basic.value() == true) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    83
    if (_show_loaders.value() || _by_chunktype.value() || _by_spacetype.value() ||
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    84
        _show_vslist.value() || _show_vsmap.value()) {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    85
      // Basic mode. Just print essentials. Does not need to be at a safepoint.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    86
      output()->print_cr("In basic mode, additional arguments are ignored.");
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    87
    }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    88
    MetaspaceUtils::print_basic_report(output(), scale);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    89
  } else {
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    90
    // Full mode. Requires safepoint.
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    91
    int flags = 0;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    92
    if (_show_loaders.value())         flags |= MetaspaceUtils::rf_show_loaders;
50309
37ebfe8bac7f 8203219: VM.metaspace jcmd should optionally show loaded classes for loaders
stuefe
parents: 50021
diff changeset
    93
    if (_show_classes.value())         flags |= MetaspaceUtils::rf_show_classes;
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    94
    if (_by_chunktype.value())         flags |= MetaspaceUtils::rf_break_down_by_chunktype;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    95
    if (_by_spacetype.value())         flags |= MetaspaceUtils::rf_break_down_by_spacetype;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    96
    if (_show_vslist.value())          flags |= MetaspaceUtils::rf_show_vslist;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    97
    if (_show_vsmap.value())           flags |= MetaspaceUtils::rf_show_vsmap;
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    98
    VM_PrintMetadata op(output(), scale, flags);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
    99
    VMThread::execute(&op);
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   100
  }
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   101
}
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   102
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   103
} // namespace metaspace
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents:
diff changeset
   104