annotate src/share/vm/runtime/perfData.cpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents 78bbf4d43a14
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 10405
diff changeset
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/vmSymbols.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/java.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/mutex.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/perfData.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "utilities/exceptions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "utilities/globalDefinitions.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 10405
diff changeset
37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 10405
diff changeset
38
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 PerfDataList* PerfDataManager::_all = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 PerfDataList* PerfDataManager::_sampled = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 PerfDataList* PerfDataManager::_constants = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
44 * The jvmstat global and subsysem jvmstat counter name spaces. The top
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * level name spaces imply the interface stability level of the counter,
a61af66fc99e Initial load
duke
parents:
diff changeset
46 * which generally follows the Java package, class, and property naming
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * conventions. The CounterNS enumeration values should be used to index
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * into this array.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 */
a61af66fc99e Initial load
duke
parents:
diff changeset
50 const char* PerfDataManager::_name_spaces[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // top level name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
52 "java", // stable and supported name space
a61af66fc99e Initial load
duke
parents:
diff changeset
53 "com.sun", // unstable but supported name space
a61af66fc99e Initial load
duke
parents:
diff changeset
54 "sun", // unstable and unsupported name space
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // subsystem name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
56 "java.gc", // Garbage Collection name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
57 "com.sun.gc",
a61af66fc99e Initial load
duke
parents:
diff changeset
58 "sun.gc",
a61af66fc99e Initial load
duke
parents:
diff changeset
59 "java.ci", // Compiler name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
60 "com.sun.ci",
a61af66fc99e Initial load
duke
parents:
diff changeset
61 "sun.ci",
a61af66fc99e Initial load
duke
parents:
diff changeset
62 "java.cls", // Class Loader name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
63 "com.sun.cls",
a61af66fc99e Initial load
duke
parents:
diff changeset
64 "sun.cls",
a61af66fc99e Initial load
duke
parents:
diff changeset
65 "java.rt", // Runtime name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
66 "com.sun.rt",
a61af66fc99e Initial load
duke
parents:
diff changeset
67 "sun.rt",
a61af66fc99e Initial load
duke
parents:
diff changeset
68 "java.os", // Operating System name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
69 "com.sun.os",
a61af66fc99e Initial load
duke
parents:
diff changeset
70 "sun.os",
a61af66fc99e Initial load
duke
parents:
diff changeset
71 "java.threads", // Threads System name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
72 "com.sun.threads",
a61af66fc99e Initial load
duke
parents:
diff changeset
73 "sun.threads",
a61af66fc99e Initial load
duke
parents:
diff changeset
74 "java.property", // Java Property name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
75 "com.sun.property",
a61af66fc99e Initial load
duke
parents:
diff changeset
76 "sun.property",
a61af66fc99e Initial load
duke
parents:
diff changeset
77 "",
a61af66fc99e Initial load
duke
parents:
diff changeset
78 };
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 PerfData::PerfData(CounterNS ns, const char* name, Units u, Variability v)
a61af66fc99e Initial load
duke
parents:
diff changeset
81 : _name(NULL), _u(u), _v(v), _valuep(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _on_c_heap(false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 const char* prefix = PerfDataManager::ns_to_string(ns);
a61af66fc99e Initial load
duke
parents:
diff changeset
85
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
86 _name = NEW_C_HEAP_ARRAY(char, strlen(name) + strlen(prefix) + 2, mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 assert(_name != NULL && strlen(name) != 0, "invalid name");
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (ns == NULL_NS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // No prefix is added to counters with the NULL_NS namespace.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 strcpy(_name, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // set the F_Supported flag based on the counter name prefix.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (PerfDataManager::is_stable_supported(_name) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
94 PerfDataManager::is_unstable_supported(_name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _flags = F_Supported;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _flags = F_None;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 sprintf(_name, "%s.%s", prefix, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // set the F_Supported flag based on the given namespace.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (PerfDataManager::is_stable_supported(ns) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
105 PerfDataManager::is_unstable_supported(ns)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _flags = F_Supported;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 _flags = F_None;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 PerfData::~PerfData() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (_name != NULL) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
116 FREE_C_HEAP_ARRAY(char, _name, mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (is_on_c_heap()) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
119 FREE_C_HEAP_ARRAY(PerfDataEntry, _pdep, mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 void PerfData::create_entry(BasicType dtype, size_t dsize, size_t vlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 size_t dlen = vlen==0 ? 1 : vlen;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 size_t namelen = strlen(name()) + 1; // include null terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
128 size_t size = sizeof(PerfDataEntry) + namelen;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 size_t pad_length = ((size % dsize) == 0) ? 0 : dsize - (size % dsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 size += pad_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 size_t data_start = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 size += (dsize * dlen);
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // align size to assure allocation in units of 8 bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int align = sizeof(jlong) - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 size = ((size + align) & ~align);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 char* psmp = PerfMemory::alloc(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (psmp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // out of PerfMemory memory resources. allocate on the C heap
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // to avoid vm termination.
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
142 psmp = NEW_C_HEAP_ARRAY(char, size, mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _on_c_heap = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // compute the addresses for the name and data
a61af66fc99e Initial load
duke
parents:
diff changeset
147 char* cname = psmp + sizeof(PerfDataEntry);
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // data is in the last dsize*dlen bytes of the entry
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void* valuep = (void*) (psmp + data_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 assert(is_on_c_heap() || PerfMemory::contains(cname), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(is_on_c_heap() || PerfMemory::contains((char*)valuep), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // copy the name, including null terminator, into PerfData memory
a61af66fc99e Initial load
duke
parents:
diff changeset
156 strcpy(cname, name());
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // set the header values in PerfData memory
a61af66fc99e Initial load
duke
parents:
diff changeset
160 PerfDataEntry* pdep = (PerfDataEntry*)psmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 pdep->entry_length = (jint)size;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 pdep->name_offset = (jint) ((uintptr_t) cname - (uintptr_t) psmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 pdep->vector_length = (jint)vlen;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 pdep->data_type = (jbyte) type2char(dtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 pdep->data_units = units();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 pdep->data_variability = variability();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 pdep->flags = (jbyte)flags();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 pdep->data_offset = (jint) data_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (PerfTraceDataCreation) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 tty->print("name = %s, dtype = %d, variability = %d,"
a61af66fc99e Initial load
duke
parents:
diff changeset
172 " units = %d, dsize = %d, vlen = %d,"
a61af66fc99e Initial load
duke
parents:
diff changeset
173 " pad_length = %d, size = %d, on_c_heap = %s,"
a61af66fc99e Initial load
duke
parents:
diff changeset
174 " address = " INTPTR_FORMAT ","
a61af66fc99e Initial load
duke
parents:
diff changeset
175 " data address = " INTPTR_FORMAT "\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
176 cname, dtype, variability(),
a61af66fc99e Initial load
duke
parents:
diff changeset
177 units(), dsize, vlen,
a61af66fc99e Initial load
duke
parents:
diff changeset
178 pad_length, size, is_on_c_heap() ? "TRUE":"FALSE",
a61af66fc99e Initial load
duke
parents:
diff changeset
179 psmp, valuep);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // record the start of the entry and the location of the data field.
a61af66fc99e Initial load
duke
parents:
diff changeset
183 _pdep = pdep;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 _valuep = valuep;
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // mark the PerfData memory region as having been updated.
a61af66fc99e Initial load
duke
parents:
diff changeset
187 PerfMemory::mark_updated();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 PerfLong::PerfLong(CounterNS ns, const char* namep, Units u, Variability v)
a61af66fc99e Initial load
duke
parents:
diff changeset
191 : PerfData(ns, namep, u, v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 create_entry(T_LONG, sizeof(jlong));
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int PerfLong::format(char* buffer, int length) {
7623
203f64878aab 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 6854
diff changeset
197 return jio_snprintf(buffer, length, JLONG_FORMAT, *(jlong*)_valuep);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 PerfLongVariant::PerfLongVariant(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Variability v, jlong* sampled)
a61af66fc99e Initial load
duke
parents:
diff changeset
202 : PerfLong(ns, namep, u, v),
a61af66fc99e Initial load
duke
parents:
diff changeset
203 _sampled(sampled), _sample_helper(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 sample();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 PerfLongVariant::PerfLongVariant(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
209 Variability v, PerfLongSampleHelper* helper)
a61af66fc99e Initial load
duke
parents:
diff changeset
210 : PerfLong(ns, namep, u, v),
a61af66fc99e Initial load
duke
parents:
diff changeset
211 _sampled(NULL), _sample_helper(helper) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 sample();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void PerfLongVariant::sample() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
218 // JJJ - This should not happen. Maybe the first sample is taken
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
219 // while the _sample_helper is being null'ed out.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
220 // assert(_sample_helper != NULL || _sampled != NULL, "unexpected state");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
221 if (_sample_helper == NULL) return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (_sample_helper != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 *(jlong*)_valuep = _sample_helper->take_sample();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 else if (_sampled != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 *(jlong*)_valuep = *_sampled;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 PerfByteArray::PerfByteArray(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
232 Variability v, jint length)
a61af66fc99e Initial load
duke
parents:
diff changeset
233 : PerfData(ns, namep, u, v), _length(length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 create_entry(T_BYTE, sizeof(jbyte), (size_t)_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 void PerfString::set_string(const char* s2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // copy n bytes of the string, assuring the null string is
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // copied if s2 == NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
242 strncpy((char *)_valuep, s2 == NULL ? "" : s2, _length);
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // assure the string is null terminated when strlen(s2) >= _length
a61af66fc99e Initial load
duke
parents:
diff changeset
245 ((char*)_valuep)[_length-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 int PerfString::format(char* buffer, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 return jio_snprintf(buffer, length, "%s", (char*)_valuep);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 PerfStringConstant::PerfStringConstant(CounterNS ns, const char* namep,
a61af66fc99e Initial load
duke
parents:
diff changeset
253 const char* initial_value)
a61af66fc99e Initial load
duke
parents:
diff changeset
254 : PerfString(ns, namep, V_Constant,
a61af66fc99e Initial load
duke
parents:
diff changeset
255 initial_value == NULL ? 1 :
a61af66fc99e Initial load
duke
parents:
diff changeset
256 MIN2((jint)(strlen((char*)initial_value)+1),
a61af66fc99e Initial load
duke
parents:
diff changeset
257 (jint)(PerfMaxStringConstLength+1)),
a61af66fc99e Initial load
duke
parents:
diff changeset
258 initial_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (PrintMiscellaneous && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (is_valid() && initial_value != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
262 ((jint)strlen(initial_value) > (jint)PerfMaxStringConstLength)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 warning("Truncating PerfStringConstant: name = %s,"
a61af66fc99e Initial load
duke
parents:
diff changeset
265 " length = " INT32_FORMAT ","
a61af66fc99e Initial load
duke
parents:
diff changeset
266 " PerfMaxStringConstLength = " INT32_FORMAT "\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
267 namep,
a61af66fc99e Initial load
duke
parents:
diff changeset
268 (jint)strlen(initial_value),
a61af66fc99e Initial load
duke
parents:
diff changeset
269 (jint)PerfMaxStringConstLength);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 void PerfDataManager::destroy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 if (_all == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // destroy already called, or initialization never happened
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 for (int index = 0; index < _all->length(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 PerfData* p = _all->at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 delete(_all);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 delete(_sampled);
a61af66fc99e Initial load
duke
parents:
diff changeset
292 delete(_constants);
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 _all = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 _sampled = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 _constants = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 void PerfDataManager::add_item(PerfData* p, bool sampled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 MutexLocker ml(PerfDataManager_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (_all == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 _all = new PerfDataList(100);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 assert(!_all->contains(p->name()), "duplicate name added");
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // add to the list of all perf data items
a61af66fc99e Initial load
duke
parents:
diff changeset
310 _all->append(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (p->variability() == PerfData::V_Constant) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (_constants == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 _constants = new PerfDataList(25);
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 _constants->append(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (sampled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (_sampled == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 _sampled = new PerfDataList(25);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
324 _sampled->append(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 7623
diff changeset
328 PerfData* PerfDataManager::find_by_name(const char* name) {
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 7623
diff changeset
329 return _all->find_by_name(name);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 7623
diff changeset
330 }
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 7623
diff changeset
331
0
a61af66fc99e Initial load
duke
parents:
diff changeset
332 PerfDataList* PerfDataManager::all() {
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 MutexLocker ml(PerfDataManager_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (_all == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 PerfDataList* clone = _all->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return clone;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 PerfDataList* PerfDataManager::sampled() {
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 MutexLocker ml(PerfDataManager_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 if (_sampled == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
348 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 PerfDataList* clone = _sampled->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 return clone;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 PerfDataList* PerfDataManager::constants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 MutexLocker ml(PerfDataManager_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (_constants == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 PerfDataList* clone = _constants->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return clone;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 char* PerfDataManager::counter_name(const char* ns, const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 assert(ns != NULL, "ns string required");
a61af66fc99e Initial load
duke
parents:
diff changeset
367 assert(name != NULL, "name string required");
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369 size_t len = strlen(ns) + strlen(name) + 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 char* result = NEW_RESOURCE_ARRAY(char, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 sprintf(result, "%s.%s", ns, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375 char* PerfDataManager::name_space(const char* ns, const char* sub,
a61af66fc99e Initial load
duke
parents:
diff changeset
376 int instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 char intbuf[40];
a61af66fc99e Initial load
duke
parents:
diff changeset
378 jio_snprintf(intbuf, 40, UINT32_FORMAT, instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 return name_space(ns, name_space(sub, intbuf));
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 char *PerfDataManager::name_space(const char* ns, int instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 char intbuf[40];
a61af66fc99e Initial load
duke
parents:
diff changeset
384 jio_snprintf(intbuf, 40, UINT32_FORMAT, instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return name_space(ns, intbuf);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 PerfStringConstant* PerfDataManager::create_string_constant(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
389 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
390 const char* s,
a61af66fc99e Initial load
duke
parents:
diff changeset
391 TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 PerfStringConstant* p = new PerfStringConstant(ns, name, s);
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
397 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
398 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400
a61af66fc99e Initial load
duke
parents:
diff changeset
401 add_item(p, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 PerfLongConstant* PerfDataManager::create_long_constant(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
407 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
408 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
409 jlong val, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 PerfLongConstant* p = new PerfLongConstant(ns, name, u, val);
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
415 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 add_item(p, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 PerfStringVariable* PerfDataManager::create_string_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
425 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
426 jint max_length,
a61af66fc99e Initial load
duke
parents:
diff changeset
427 const char* s,
a61af66fc99e Initial load
duke
parents:
diff changeset
428 TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 if (max_length == 0 && s != NULL) max_length = (jint)strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 assert(max_length != 0, "PerfStringVariable with length 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 PerfStringVariable* p = new PerfStringVariable(ns, name, max_length, s);
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
438 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 add_item(p, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
448 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
449 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
450 jlong ival, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 PerfLongVariable* p = new PerfLongVariable(ns, name, u, ival);
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
456 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 add_item(p, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
466 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
467 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
468 jlong* sp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // Sampled counters not supported if UsePerfData is false
a61af66fc99e Initial load
duke
parents:
diff changeset
471 if (!UsePerfData) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 PerfLongVariable* p = new PerfLongVariable(ns, name, u, sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
477 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
478 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 add_item(p, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
487 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
488 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
489 PerfSampleHelper* sh,
a61af66fc99e Initial load
duke
parents:
diff changeset
490 TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // Sampled counters not supported if UsePerfData is false
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (!UsePerfData) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495 PerfLongVariable* p = new PerfLongVariable(ns, name, u, sh);
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
499 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 add_item(p, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
509 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
510 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
511 jlong ival, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 PerfLongCounter* p = new PerfLongCounter(ns, name, u, ival);
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
517 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 add_item(p, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 }
a61af66fc99e Initial load
duke
parents:
diff changeset
525
a61af66fc99e Initial load
duke
parents:
diff changeset
526 PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
527 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
528 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
529 jlong* sp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // Sampled counters not supported if UsePerfData is false
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (!UsePerfData) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 PerfLongCounter* p = new PerfLongCounter(ns, name, u, sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
538 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
539 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 add_item(p, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547 PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
548 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
549 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
550 PerfSampleHelper* sh,
a61af66fc99e Initial load
duke
parents:
diff changeset
551 TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // Sampled counters not supported if UsePerfData is false
a61af66fc99e Initial load
duke
parents:
diff changeset
554 if (!UsePerfData) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 PerfLongCounter* p = new PerfLongCounter(ns, name, u, sh);
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 if (!p->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
559 // allocation of native resources failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
560 delete p;
a61af66fc99e Initial load
duke
parents:
diff changeset
561 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 add_item(p, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569 PerfDataList::PerfDataList(int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
571 _set = new(ResourceObj::C_HEAP, mtInternal) PerfDataArray(length, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574 PerfDataList::PerfDataList(PerfDataList* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
576 _set = new(ResourceObj::C_HEAP, mtInternal) PerfDataArray(p->length(), true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 _set->appendAll(p->get_impl());
a61af66fc99e Initial load
duke
parents:
diff changeset
579 }
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 PerfDataList::~PerfDataList() {
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 delete _set;
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587 bool PerfDataList::by_name(void* name, PerfData* pd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 if (pd == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
590 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 return strcmp((const char*)name, pd->name()) == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 PerfData* PerfDataList::find_by_name(const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
597 // if add_item hasn't been called the list won't be initialized
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
598 if (this == NULL)
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
599 return NULL;
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
600
0
a61af66fc99e Initial load
duke
parents:
diff changeset
601 int i = _set->find((void*)name, PerfDataList::by_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if (i >= 0 && i <= _set->length())
a61af66fc99e Initial load
duke
parents:
diff changeset
604 return _set->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 else
a61af66fc99e Initial load
duke
parents:
diff changeset
606 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 PerfDataList* PerfDataList::clone() {
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 PerfDataList* copy = new PerfDataList(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 assert(copy != NULL, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
614
a61af66fc99e Initial load
duke
parents:
diff changeset
615 return copy;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 }