hotspot/src/share/vm/memory/metaspaceCounters.cpp
author jmasa
Tue, 12 Feb 2013 14:15:45 -0800
changeset 17109 90e6c31bbbe4
parent 15860 4375d0d48f37
child 19322 e35f9ed4f081
permissions -rw-r--r--
8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions Reviewed-by: mgerdin, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
14847
92a59a418262 8004982: JDK8 source with GPL header errors
katleman
parents: 13737
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    26
#include "memory/metaspaceCounters.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    27
#include "memory/resourceArea.hpp"
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    28
#include "utilities/exceptions.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    32
size_t MetaspaceCounters::calc_total_capacity() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    33
  // The total capacity is the sum of
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    34
  //   1) capacity of Metachunks in use by all Metaspaces
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    35
  //   2) unused space at the end of each Metachunk
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    36
  //   3) space in the freelist
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    37
  size_t total_capacity = MetaspaceAux::allocated_capacity_bytes()
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    38
    + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_in_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    39
  return total_capacity;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    40
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    41
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    42
MetaspaceCounters::MetaspaceCounters() :
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    43
    _capacity(NULL),
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    44
    _used(NULL),
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    45
    _max_capacity(NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
  if (UsePerfData) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    47
    size_t min_capacity = MetaspaceAux::min_chunk_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
    size_t max_capacity = MetaspaceAux::reserved_in_bytes();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    49
    size_t curr_capacity = calc_total_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    50
    size_t used = MetaspaceAux::allocated_used_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
    initialize(min_capacity, max_capacity, curr_capacity, used);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    55
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    56
static PerfVariable* create_ms_variable(const char *ns,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    57
                                        const char *name,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    58
                                        size_t value,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    59
                                        TRAPS) {
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    60
  const char *path = PerfDataManager::counter_name(ns, name);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    61
  PerfVariable *result =
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    62
      PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    63
                                       CHECK_NULL);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    64
  return result;
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    65
}
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    66
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    67
static void create_ms_constant(const char *ns,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    68
                               const char *name,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    69
                               size_t value,
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    70
                               TRAPS) {
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    71
  const char *path = PerfDataManager::counter_name(ns, name);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    72
  PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, CHECK);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    73
}
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    74
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    75
void MetaspaceCounters::initialize(size_t min_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    76
                                   size_t max_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    77
                                   size_t curr_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    78
                                   size_t used) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    79
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    80
  if (UsePerfData) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    81
    EXCEPTION_MARK;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    82
    ResourceMark rm;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    83
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    84
    const char *ms = "metaspace";
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    86
    create_ms_constant(ms, "minCapacity", min_capacity, CHECK);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    87
    _max_capacity = create_ms_variable(ms, "maxCapacity", max_capacity, CHECK);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    88
    _capacity = create_ms_variable(ms, "capacity", curr_capacity, CHECK);
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
    89
    _used = create_ms_variable(ms, "used", used, CHECK);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    91
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    92
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    93
void MetaspaceCounters::update_capacity() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    94
  assert(UsePerfData, "Should not be called unless being used");
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    95
  size_t total_capacity = calc_total_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
    96
  _capacity->set_value(total_capacity);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    97
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    98
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    99
void MetaspaceCounters::update_used() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   100
  assert(UsePerfData, "Should not be called unless being used");
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15860
diff changeset
   101
  size_t used_in_bytes = MetaspaceAux::allocated_used_bytes();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   102
  _used->set_value(used_in_bytes);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   103
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   104
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   105
void MetaspaceCounters::update_max_capacity() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   106
  assert(UsePerfData, "Should not be called unless being used");
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
   107
  assert(_max_capacity != NULL, "Should be initialized");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   108
  size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   109
  _max_capacity->set_value(reserved_in_bytes);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   110
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   111
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   112
void MetaspaceCounters::update_all() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
  if (UsePerfData) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   114
    update_used();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   115
    update_capacity();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   116
    update_max_capacity();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   117
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   118
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   119
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   120
void MetaspaceCounters::initialize_performance_counters() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   121
  if (UsePerfData) {
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
   122
    assert(_metaspace_counters == NULL, "Should only be initialized once");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   123
    _metaspace_counters = new MetaspaceCounters();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   125
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   126
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   127
void MetaspaceCounters::update_performance_counters() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
  if (UsePerfData) {
15860
4375d0d48f37 8004172: Update jstat counter names to reflect metaspace changes
ehelin
parents: 14847
diff changeset
   129
    assert(_metaspace_counters != NULL, "Should be initialized");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   130
    _metaspace_counters->update_all();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   133