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