src/share/vm/memory/metaspaceCounters.cpp

Fri, 17 May 2013 06:01:10 +0200

author
jwilhelm
date
Fri, 17 May 2013 06:01:10 +0200
changeset 5125
2958af1d8c5a
parent 5015
868d87ed63c8
child 5531
1a8fb39bdbc4
permissions
-rw-r--r--

Merge

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

mercurial