annotate src/share/vm/runtime/perfData.hpp @ 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 55fb97c4c58d
children 63a4eb8bcd23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 10405
diff changeset
2 * Copyright (c) 2001, 2013, 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: 948
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 948
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: 948
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 #ifndef SHARE_VM_RUNTIME_PERFDATA_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_RUNTIME_PERFDATA_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/perfMemory.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/timer.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "utilities/growableArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 /* jvmstat global and subsystem counter name space - enumeration value
a61af66fc99e Initial load
duke
parents:
diff changeset
34 * serve as an index into the PerfDataManager::_name_space[] array
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * containing the corresponding name space string. Only the top level
a61af66fc99e Initial load
duke
parents:
diff changeset
36 * subsystem name spaces are represented here.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 */
a61af66fc99e Initial load
duke
parents:
diff changeset
38 enum CounterNS {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // top level name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
40 JAVA_NS,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 COM_NS,
a61af66fc99e Initial load
duke
parents:
diff changeset
42 SUN_NS,
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // subsystem name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
44 JAVA_GC, // Garbage Collection name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
45 COM_GC,
a61af66fc99e Initial load
duke
parents:
diff changeset
46 SUN_GC,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 JAVA_CI, // Compiler name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
48 COM_CI,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 SUN_CI,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 JAVA_CLS, // Class Loader name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
51 COM_CLS,
a61af66fc99e Initial load
duke
parents:
diff changeset
52 SUN_CLS,
a61af66fc99e Initial load
duke
parents:
diff changeset
53 JAVA_RT, // Runtime name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
54 COM_RT,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 SUN_RT,
a61af66fc99e Initial load
duke
parents:
diff changeset
56 JAVA_OS, // Operating System name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
57 COM_OS,
a61af66fc99e Initial load
duke
parents:
diff changeset
58 SUN_OS,
a61af66fc99e Initial load
duke
parents:
diff changeset
59 JAVA_THREADS, // Threads System name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
60 COM_THREADS,
a61af66fc99e Initial load
duke
parents:
diff changeset
61 SUN_THREADS,
a61af66fc99e Initial load
duke
parents:
diff changeset
62 JAVA_PROPERTY, // Java Property name spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
63 COM_PROPERTY,
a61af66fc99e Initial load
duke
parents:
diff changeset
64 SUN_PROPERTY,
a61af66fc99e Initial load
duke
parents:
diff changeset
65 NULL_NS,
a61af66fc99e Initial load
duke
parents:
diff changeset
66 COUNTERNS_LAST = NULL_NS
a61af66fc99e Initial load
duke
parents:
diff changeset
67 };
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
70 * Classes to support access to production performance data
a61af66fc99e Initial load
duke
parents:
diff changeset
71 *
a61af66fc99e Initial load
duke
parents:
diff changeset
72 * The PerfData class structure is provided for creation, access, and update
a61af66fc99e Initial load
duke
parents:
diff changeset
73 * of performance data (a.k.a. instrumentation) in a specific memory region
a61af66fc99e Initial load
duke
parents:
diff changeset
74 * which is possibly accessible as shared memory. Although not explicitly
a61af66fc99e Initial load
duke
parents:
diff changeset
75 * prevented from doing so, developers should not use the values returned
a61af66fc99e Initial load
duke
parents:
diff changeset
76 * by accessor methods to make algorithmic decisions as they are potentially
a61af66fc99e Initial load
duke
parents:
diff changeset
77 * extracted from a shared memory region. Although any shared memory region
a61af66fc99e Initial load
duke
parents:
diff changeset
78 * created is with appropriate access restrictions, allowing read-write access
a61af66fc99e Initial load
duke
parents:
diff changeset
79 * only to the principal that created the JVM, it is believed that a the
a61af66fc99e Initial load
duke
parents:
diff changeset
80 * shared memory region facilitates an easier attack path than attacks
a61af66fc99e Initial load
duke
parents:
diff changeset
81 * launched through mechanisms such as /proc. For this reason, it is
a61af66fc99e Initial load
duke
parents:
diff changeset
82 * recommended that data returned by PerfData accessor methods be used
a61af66fc99e Initial load
duke
parents:
diff changeset
83 * cautiously.
a61af66fc99e Initial load
duke
parents:
diff changeset
84 *
a61af66fc99e Initial load
duke
parents:
diff changeset
85 * There are three variability classifications of performance data
a61af66fc99e Initial load
duke
parents:
diff changeset
86 * Constants - value is written to the PerfData memory once, on creation
a61af66fc99e Initial load
duke
parents:
diff changeset
87 * Variables - value is modifiable, with no particular restrictions
a61af66fc99e Initial load
duke
parents:
diff changeset
88 * Counters - value is monotonically changing (increasing or decreasing)
a61af66fc99e Initial load
duke
parents:
diff changeset
89 *
a61af66fc99e Initial load
duke
parents:
diff changeset
90 * The performance data items can also have various types. The class
a61af66fc99e Initial load
duke
parents:
diff changeset
91 * hierarchy and the structure of the memory region are designed to
a61af66fc99e Initial load
duke
parents:
diff changeset
92 * accommodate new types as they are needed. Types are specified in
a61af66fc99e Initial load
duke
parents:
diff changeset
93 * terms of Java basic types, which accommodates client applications
a61af66fc99e Initial load
duke
parents:
diff changeset
94 * written in the Java programming language. The class hierarchy is:
a61af66fc99e Initial load
duke
parents:
diff changeset
95 *
a61af66fc99e Initial load
duke
parents:
diff changeset
96 * - PerfData (Abstract)
a61af66fc99e Initial load
duke
parents:
diff changeset
97 * - PerfLong (Abstract)
a61af66fc99e Initial load
duke
parents:
diff changeset
98 * - PerfLongConstant (alias: PerfConstant)
a61af66fc99e Initial load
duke
parents:
diff changeset
99 * - PerfLongVariant (Abstract)
a61af66fc99e Initial load
duke
parents:
diff changeset
100 * - PerfLongVariable (alias: PerfVariable)
a61af66fc99e Initial load
duke
parents:
diff changeset
101 * - PerfLongCounter (alias: PerfCounter)
a61af66fc99e Initial load
duke
parents:
diff changeset
102 *
a61af66fc99e Initial load
duke
parents:
diff changeset
103 * - PerfByteArray (Abstract)
a61af66fc99e Initial load
duke
parents:
diff changeset
104 * - PerfString (Abstract)
a61af66fc99e Initial load
duke
parents:
diff changeset
105 * - PerfStringVariable
a61af66fc99e Initial load
duke
parents:
diff changeset
106 * - PerfStringConstant
a61af66fc99e Initial load
duke
parents:
diff changeset
107 *
a61af66fc99e Initial load
duke
parents:
diff changeset
108 *
a61af66fc99e Initial load
duke
parents:
diff changeset
109 * As seen in the class hierarchy, the initially supported types are:
a61af66fc99e Initial load
duke
parents:
diff changeset
110 *
a61af66fc99e Initial load
duke
parents:
diff changeset
111 * Long - performance data holds a Java long type
a61af66fc99e Initial load
duke
parents:
diff changeset
112 * ByteArray - performance data holds an array of Java bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
113 * used for holding C++ char arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 *
a61af66fc99e Initial load
duke
parents:
diff changeset
115 * The String type is derived from the ByteArray type.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 *
a61af66fc99e Initial load
duke
parents:
diff changeset
117 * A PerfData subtype is not required to provide an implementation for
a61af66fc99e Initial load
duke
parents:
diff changeset
118 * each variability classification. For example, the String type provides
a61af66fc99e Initial load
duke
parents:
diff changeset
119 * Variable and Constant variablility classifications in the PerfStringVariable
a61af66fc99e Initial load
duke
parents:
diff changeset
120 * and PerfStringConstant classes, but does not provide a counter type.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 *
a61af66fc99e Initial load
duke
parents:
diff changeset
122 * Performance data are also described by a unit of measure. Units allow
a61af66fc99e Initial load
duke
parents:
diff changeset
123 * client applications to make reasonable decisions on how to treat
a61af66fc99e Initial load
duke
parents:
diff changeset
124 * performance data generically, preventing the need to hard-code the
a61af66fc99e Initial load
duke
parents:
diff changeset
125 * specifics of a particular data item in client applications. The current
a61af66fc99e Initial load
duke
parents:
diff changeset
126 * set of units are:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 *
a61af66fc99e Initial load
duke
parents:
diff changeset
128 * None - the data has no units of measure
a61af66fc99e Initial load
duke
parents:
diff changeset
129 * Bytes - data is measured in bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
130 * Ticks - data is measured in clock ticks
a61af66fc99e Initial load
duke
parents:
diff changeset
131 * Events - data is measured in events. For example,
a61af66fc99e Initial load
duke
parents:
diff changeset
132 * the number of garbage collection events or the
a61af66fc99e Initial load
duke
parents:
diff changeset
133 * number of methods compiled.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 * String - data is not numerical. For example,
a61af66fc99e Initial load
duke
parents:
diff changeset
135 * the java command line options
a61af66fc99e Initial load
duke
parents:
diff changeset
136 * Hertz - data is a frequency
a61af66fc99e Initial load
duke
parents:
diff changeset
137 *
a61af66fc99e Initial load
duke
parents:
diff changeset
138 * The performance counters also provide a support attribute, indicating
a61af66fc99e Initial load
duke
parents:
diff changeset
139 * the stability of the counter as a programmatic interface. The support
a61af66fc99e Initial load
duke
parents:
diff changeset
140 * level is also implied by the name space in which the counter is created.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 * The counter name space support conventions follow the Java package, class,
a61af66fc99e Initial load
duke
parents:
diff changeset
142 * and property support conventions:
a61af66fc99e Initial load
duke
parents:
diff changeset
143 *
a61af66fc99e Initial load
duke
parents:
diff changeset
144 * java.* - stable, supported interface
a61af66fc99e Initial load
duke
parents:
diff changeset
145 * com.sun.* - unstable, supported interface
a61af66fc99e Initial load
duke
parents:
diff changeset
146 * sun.* - unstable, unsupported interface
a61af66fc99e Initial load
duke
parents:
diff changeset
147 *
a61af66fc99e Initial load
duke
parents:
diff changeset
148 * In the above context, unstable is a measure of the interface support
a61af66fc99e Initial load
duke
parents:
diff changeset
149 * level, not the implementation stability level.
a61af66fc99e Initial load
duke
parents:
diff changeset
150 *
a61af66fc99e Initial load
duke
parents:
diff changeset
151 * Currently, instances of PerfData subtypes are considered to have
a61af66fc99e Initial load
duke
parents:
diff changeset
152 * a life time equal to that of the VM and are managed by the
a61af66fc99e Initial load
duke
parents:
diff changeset
153 * PerfDataManager class. All constructors for the PerfData class and
a61af66fc99e Initial load
duke
parents:
diff changeset
154 * its subtypes have protected constructors. Creation of PerfData
a61af66fc99e Initial load
duke
parents:
diff changeset
155 * instances is performed by invoking various create methods on the
a61af66fc99e Initial load
duke
parents:
diff changeset
156 * PerfDataManager class. Users should not attempt to delete these
a61af66fc99e Initial load
duke
parents:
diff changeset
157 * instances as the PerfDataManager class expects to perform deletion
a61af66fc99e Initial load
duke
parents:
diff changeset
158 * operations on exit of the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 *
a61af66fc99e Initial load
duke
parents:
diff changeset
160 * Examples:
a61af66fc99e Initial load
duke
parents:
diff changeset
161 *
a61af66fc99e Initial load
duke
parents:
diff changeset
162 * Creating performance counter that holds a monotonically increasing
a61af66fc99e Initial load
duke
parents:
diff changeset
163 * long data value with units specified in U_Bytes in the "java.gc.*"
a61af66fc99e Initial load
duke
parents:
diff changeset
164 * name space.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 *
a61af66fc99e Initial load
duke
parents:
diff changeset
166 * PerfLongCounter* foo_counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 *
a61af66fc99e Initial load
duke
parents:
diff changeset
168 * foo_counter = PerfDataManager::create_long_counter(JAVA_GC, "foo",
a61af66fc99e Initial load
duke
parents:
diff changeset
169 * PerfData::U_Bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
170 * optionalInitialValue,
a61af66fc99e Initial load
duke
parents:
diff changeset
171 * CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 * foo_counter->inc();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 *
a61af66fc99e Initial load
duke
parents:
diff changeset
174 * Creating a performance counter that holds a variably change long
a61af66fc99e Initial load
duke
parents:
diff changeset
175 * data value with untis specified in U_Bytes in the "com.sun.ci
a61af66fc99e Initial load
duke
parents:
diff changeset
176 * name space.
a61af66fc99e Initial load
duke
parents:
diff changeset
177 *
a61af66fc99e Initial load
duke
parents:
diff changeset
178 * PerfLongVariable* bar_varible;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 * bar_variable = PerfDataManager::create_long_variable(COM_CI, "bar",
a61af66fc99e Initial load
duke
parents:
diff changeset
180 .* PerfData::U_Bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
181 * optionalInitialValue,
a61af66fc99e Initial load
duke
parents:
diff changeset
182 * CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 *
a61af66fc99e Initial load
duke
parents:
diff changeset
184 * bar_variable->inc();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 * bar_variable->set_value(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 *
a61af66fc99e Initial load
duke
parents:
diff changeset
187 * Creating a performance counter that holds a constant string value in
a61af66fc99e Initial load
duke
parents:
diff changeset
188 * the "sun.cls.*" name space.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 *
a61af66fc99e Initial load
duke
parents:
diff changeset
190 * PerfDataManager::create_string_constant(SUN_CLS, "foo", string, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 *
a61af66fc99e Initial load
duke
parents:
diff changeset
192 * Although the create_string_constant() factory method returns a pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
193 * to the PerfStringConstant object, it can safely be ignored. Developers
a61af66fc99e Initial load
duke
parents:
diff changeset
194 * are not encouraged to access the string constant's value via this
a61af66fc99e Initial load
duke
parents:
diff changeset
195 * pointer at this time due to security concerns.
a61af66fc99e Initial load
duke
parents:
diff changeset
196 *
a61af66fc99e Initial load
duke
parents:
diff changeset
197 * Creating a performance counter in an arbitrary name space that holds a
a61af66fc99e Initial load
duke
parents:
diff changeset
198 * value that is sampled by the StatSampler periodic task.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 *
a61af66fc99e Initial load
duke
parents:
diff changeset
200 * PerfDataManager::create_counter("foo.sampled", PerfData::U_Events,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 * &my_jlong, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 *
a61af66fc99e Initial load
duke
parents:
diff changeset
203 * In this example, the PerfData pointer can be ignored as the caller
a61af66fc99e Initial load
duke
parents:
diff changeset
204 * is relying on the StatSampler PeriodicTask to sample the given
a61af66fc99e Initial load
duke
parents:
diff changeset
205 * address at a regular interval. The interval is defined by the
a61af66fc99e Initial load
duke
parents:
diff changeset
206 * PerfDataSamplingInterval global variable, and is applyied on
a61af66fc99e Initial load
duke
parents:
diff changeset
207 * a system wide basis, not on an per-counter basis.
a61af66fc99e Initial load
duke
parents:
diff changeset
208 *
a61af66fc99e Initial load
duke
parents:
diff changeset
209 * Creating a performance counter in an arbitrary name space that utilizes
a61af66fc99e Initial load
duke
parents:
diff changeset
210 * a helper object to return a value to the StatSampler via the take_sample()
a61af66fc99e Initial load
duke
parents:
diff changeset
211 * method.
a61af66fc99e Initial load
duke
parents:
diff changeset
212 *
a61af66fc99e Initial load
duke
parents:
diff changeset
213 * class MyTimeSampler : public PerfLongSampleHelper {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 * public:
a61af66fc99e Initial load
duke
parents:
diff changeset
215 * jlong take_sample() { return os::elapsed_counter(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 * };
a61af66fc99e Initial load
duke
parents:
diff changeset
217 *
a61af66fc99e Initial load
duke
parents:
diff changeset
218 * PerfDataManager::create_counter(SUN_RT, "helped",
a61af66fc99e Initial load
duke
parents:
diff changeset
219 * PerfData::U_Ticks,
a61af66fc99e Initial load
duke
parents:
diff changeset
220 * new MyTimeSampler(), CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 *
a61af66fc99e Initial load
duke
parents:
diff changeset
222 * In this example, a subtype of PerfLongSampleHelper is instantiated
a61af66fc99e Initial load
duke
parents:
diff changeset
223 * and its take_sample() method is overridden to perform whatever
a61af66fc99e Initial load
duke
parents:
diff changeset
224 * operation is necessary to generate the data sample. This method
a61af66fc99e Initial load
duke
parents:
diff changeset
225 * will be called by the StatSampler at a regular interval, defined
a61af66fc99e Initial load
duke
parents:
diff changeset
226 * by the PerfDataSamplingInterval global variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
227 *
a61af66fc99e Initial load
duke
parents:
diff changeset
228 * As before, PerfSampleHelper is an alias for PerfLongSampleHelper.
a61af66fc99e Initial load
duke
parents:
diff changeset
229 *
a61af66fc99e Initial load
duke
parents:
diff changeset
230 * For additional uses of PerfData subtypes, see the utility classes
a61af66fc99e Initial load
duke
parents:
diff changeset
231 * PerfTraceTime and PerfTraceTimedEvent below.
a61af66fc99e Initial load
duke
parents:
diff changeset
232 *
a61af66fc99e Initial load
duke
parents:
diff changeset
233 * Always-on non-sampled counters can be created independent of
a61af66fc99e Initial load
duke
parents:
diff changeset
234 * the UsePerfData flag. Counters will be created on the c-heap
a61af66fc99e Initial load
duke
parents:
diff changeset
235 * if UsePerfData is false.
a61af66fc99e Initial load
duke
parents:
diff changeset
236 *
a61af66fc99e Initial load
duke
parents:
diff changeset
237 * Until further noice, all PerfData objects should be created and
a61af66fc99e Initial load
duke
parents:
diff changeset
238 * manipulated within a guarded block. The guard variable is
a61af66fc99e Initial load
duke
parents:
diff changeset
239 * UsePerfData, a product flag set to true by default. This flag may
a61af66fc99e Initial load
duke
parents:
diff changeset
240 * be removed from the product in the future.
a61af66fc99e Initial load
duke
parents:
diff changeset
241 *
a61af66fc99e Initial load
duke
parents:
diff changeset
242 */
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
243 class PerfData : public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 friend class StatSampler; // for access to protected void sample()
a61af66fc99e Initial load
duke
parents:
diff changeset
246 friend class PerfDataManager; // for access to protected destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // the Variability enum must be kept in synchronization with the
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // the com.sun.hotspot.perfdata.Variability class
a61af66fc99e Initial load
duke
parents:
diff changeset
252 enum Variability {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 V_Constant = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
254 V_Monotonic = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
255 V_Variable = 3,
a61af66fc99e Initial load
duke
parents:
diff changeset
256 V_last = V_Variable
a61af66fc99e Initial load
duke
parents:
diff changeset
257 };
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // the Units enum must be kept in synchronization with the
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // the com.sun.hotspot.perfdata.Units class
a61af66fc99e Initial load
duke
parents:
diff changeset
261 enum Units {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 U_None = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
263 U_Bytes = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
264 U_Ticks = 3,
a61af66fc99e Initial load
duke
parents:
diff changeset
265 U_Events = 4,
a61af66fc99e Initial load
duke
parents:
diff changeset
266 U_String = 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
267 U_Hertz = 6,
a61af66fc99e Initial load
duke
parents:
diff changeset
268 U_Last = U_Hertz
a61af66fc99e Initial load
duke
parents:
diff changeset
269 };
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Miscellaneous flags
a61af66fc99e Initial load
duke
parents:
diff changeset
272 enum Flags {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 F_None = 0x0,
a61af66fc99e Initial load
duke
parents:
diff changeset
274 F_Supported = 0x1 // interface is supported - java.* and com.sun.*
a61af66fc99e Initial load
duke
parents:
diff changeset
275 };
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
278 char* _name;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 Variability _v;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 Units _u;
a61af66fc99e Initial load
duke
parents:
diff changeset
281 bool _on_c_heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 Flags _flags;
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 PerfDataEntry* _pdep;
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 void *_valuep;
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 PerfData(CounterNS ns, const char* name, Units u, Variability v);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 ~PerfData();
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // create the entry for the PerfData item in the PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // this region is maintained separately from the PerfData objects to
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // facilitate its use by external processes.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 void create_entry(BasicType dtype, size_t dsize, size_t dlen = 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // sample the data item given at creation time and write its value
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // into the its corresponding PerfMemory location.
a61af66fc99e Initial load
duke
parents:
diff changeset
300 virtual void sample() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // returns a boolean indicating the validity of this object.
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // the object is valid if and only if memory in PerfMemory
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // region was successfully allocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 inline bool is_valid() { return _valuep != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // returns a boolean indicating whether the underlying object
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // was allocated in the PerfMemory region or on the C heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
311 inline bool is_on_c_heap() { return _on_c_heap; }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // returns a pointer to a char* containing the name of the item.
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // The pointer returned is the pointer to a copy of the name
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // passed to the constructor, not the pointer to the name in the
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // PerfData memory region. This redundancy is maintained for
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // security reasons as the PerfMemory region may be in shared
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
319 const char* name() { return _name; }
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // returns the variability classification associated with this item
a61af66fc99e Initial load
duke
parents:
diff changeset
322 Variability variability() { return _v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // returns the units associated with this item.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 Units units() { return _u; }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // returns the flags associated with this item.
a61af66fc99e Initial load
duke
parents:
diff changeset
328 Flags flags() { return _flags; }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // returns the address of the data portion of the item in the
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
332 inline void* get_address() { return _valuep; }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // returns the value of the data portion of the item in the
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // PerfData memory region formatted as a string.
a61af66fc99e Initial load
duke
parents:
diff changeset
336 virtual int format(char* cp, int length) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 };
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
340 * PerfLongSampleHelper, and its alias PerfSamplerHelper, is a base class
a61af66fc99e Initial load
duke
parents:
diff changeset
341 * for helper classes that rely upon the StatSampler periodic task to
a61af66fc99e Initial load
duke
parents:
diff changeset
342 * invoke the take_sample() method and write the value returned to its
a61af66fc99e Initial load
duke
parents:
diff changeset
343 * appropriate location in the PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
344 */
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
345 class PerfLongSampleHelper : public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
346 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
347 virtual jlong take_sample() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 };
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 typedef PerfLongSampleHelper PerfSampleHelper;
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
354 * PerfLong is the base class for the various Long PerfData subtypes.
a61af66fc99e Initial load
duke
parents:
diff changeset
355 * it contains implementation details that are common among its derived
a61af66fc99e Initial load
duke
parents:
diff changeset
356 * types.
a61af66fc99e Initial load
duke
parents:
diff changeset
357 */
a61af66fc99e Initial load
duke
parents:
diff changeset
358 class PerfLong : public PerfData {
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 PerfLong(CounterNS ns, const char* namep, Units u, Variability v);
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
365 int format(char* buffer, int length);
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // returns the value of the data portion of the item in the
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 inline jlong get_value() { return *(jlong*)_valuep; }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 };
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
373 * The PerfLongConstant class, and its alias PerfConstant, implement
a61af66fc99e Initial load
duke
parents:
diff changeset
374 * a PerfData subtype that holds a jlong data value that is set upon
a61af66fc99e Initial load
duke
parents:
diff changeset
375 * creation of an instance of this class. This class provides no
a61af66fc99e Initial load
duke
parents:
diff changeset
376 * methods for changing the data value stored in PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
377 */
a61af66fc99e Initial load
duke
parents:
diff changeset
378 class PerfLongConstant : public PerfLong {
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 friend class PerfDataManager; // for access to protected constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // hide sample() - no need to sample constants
a61af66fc99e Initial load
duke
parents:
diff changeset
384 void sample() { }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 PerfLongConstant(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
389 jlong initial_value=0)
a61af66fc99e Initial load
duke
parents:
diff changeset
390 : PerfLong(ns, namep, u, V_Constant) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (is_valid()) *(jlong*)_valuep = initial_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394 };
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 typedef PerfLongConstant PerfConstant;
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
399 * The PerfLongVariant class, and its alias PerfVariant, implement
a61af66fc99e Initial load
duke
parents:
diff changeset
400 * a PerfData subtype that holds a jlong data value that can be modified
a61af66fc99e Initial load
duke
parents:
diff changeset
401 * in an unrestricted manner. This class provides the implementation details
a61af66fc99e Initial load
duke
parents:
diff changeset
402 * for common functionality among its derived types.
a61af66fc99e Initial load
duke
parents:
diff changeset
403 */
a61af66fc99e Initial load
duke
parents:
diff changeset
404 class PerfLongVariant : public PerfLong {
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
407 jlong* _sampled;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 PerfLongSampleHelper* _sample_helper;
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v,
a61af66fc99e Initial load
duke
parents:
diff changeset
411 jlong initial_value=0)
a61af66fc99e Initial load
duke
parents:
diff changeset
412 : PerfLong(ns, namep, u, v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (is_valid()) *(jlong*)_valuep = initial_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v,
a61af66fc99e Initial load
duke
parents:
diff changeset
417 jlong* sampled);
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v,
a61af66fc99e Initial load
duke
parents:
diff changeset
420 PerfLongSampleHelper* sample_helper);
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 void sample();
a61af66fc99e Initial load
duke
parents:
diff changeset
423
a61af66fc99e Initial load
duke
parents:
diff changeset
424 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
425 inline void inc() { (*(jlong*)_valuep)++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 inline void inc(jlong val) { (*(jlong*)_valuep) += val; }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 inline void add(jlong val) { (*(jlong*)_valuep) += val; }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
428 void clear_sample_helper() { _sample_helper = NULL; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
429 };
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
432 * The PerfLongCounter class, and its alias PerfCounter, implement
a61af66fc99e Initial load
duke
parents:
diff changeset
433 * a PerfData subtype that holds a jlong data value that can (should)
a61af66fc99e Initial load
duke
parents:
diff changeset
434 * be modified in a monotonic manner. The inc(jlong) and add(jlong)
a61af66fc99e Initial load
duke
parents:
diff changeset
435 * methods can be passed negative values to implement a monotonically
a61af66fc99e Initial load
duke
parents:
diff changeset
436 * decreasing value. However, we rely upon the programmer to honor
a61af66fc99e Initial load
duke
parents:
diff changeset
437 * the notion that this counter always moves in the same direction -
a61af66fc99e Initial load
duke
parents:
diff changeset
438 * either increasing or decreasing.
a61af66fc99e Initial load
duke
parents:
diff changeset
439 */
a61af66fc99e Initial load
duke
parents:
diff changeset
440 class PerfLongCounter : public PerfLongVariant {
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 friend class PerfDataManager; // for access to protected constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 PerfLongCounter(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
447 jlong initial_value=0)
a61af66fc99e Initial load
duke
parents:
diff changeset
448 : PerfLongVariant(ns, namep, u, V_Monotonic,
a61af66fc99e Initial load
duke
parents:
diff changeset
449 initial_value) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 PerfLongCounter(CounterNS ns, const char* namep, Units u, jlong* sampled)
a61af66fc99e Initial load
duke
parents:
diff changeset
452 : PerfLongVariant(ns, namep, u, V_Monotonic, sampled) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 PerfLongCounter(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
455 PerfLongSampleHelper* sample_helper)
a61af66fc99e Initial load
duke
parents:
diff changeset
456 : PerfLongVariant(ns, namep, u, V_Monotonic,
a61af66fc99e Initial load
duke
parents:
diff changeset
457 sample_helper) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 };
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 typedef PerfLongCounter PerfCounter;
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
463 * The PerfLongVariable class, and its alias PerfVariable, implement
a61af66fc99e Initial load
duke
parents:
diff changeset
464 * a PerfData subtype that holds a jlong data value that can
a61af66fc99e Initial load
duke
parents:
diff changeset
465 * be modified in an unrestricted manner.
a61af66fc99e Initial load
duke
parents:
diff changeset
466 */
a61af66fc99e Initial load
duke
parents:
diff changeset
467 class PerfLongVariable : public PerfLongVariant {
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469 friend class PerfDataManager; // for access to protected constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 PerfLongVariable(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
474 jlong initial_value=0)
a61af66fc99e Initial load
duke
parents:
diff changeset
475 : PerfLongVariant(ns, namep, u, V_Variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
476 initial_value) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
477
a61af66fc99e Initial load
duke
parents:
diff changeset
478 PerfLongVariable(CounterNS ns, const char* namep, Units u, jlong* sampled)
a61af66fc99e Initial load
duke
parents:
diff changeset
479 : PerfLongVariant(ns, namep, u, V_Variable, sampled) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
480
a61af66fc99e Initial load
duke
parents:
diff changeset
481 PerfLongVariable(CounterNS ns, const char* namep, Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
482 PerfLongSampleHelper* sample_helper)
a61af66fc99e Initial load
duke
parents:
diff changeset
483 : PerfLongVariant(ns, namep, u, V_Variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
484 sample_helper) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
487 inline void set_value(jlong val) { (*(jlong*)_valuep) = val; }
a61af66fc99e Initial load
duke
parents:
diff changeset
488 };
a61af66fc99e Initial load
duke
parents:
diff changeset
489
a61af66fc99e Initial load
duke
parents:
diff changeset
490 typedef PerfLongVariable PerfVariable;
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
493 * The PerfByteArray provides a PerfData subtype that allows the creation
a61af66fc99e Initial load
duke
parents:
diff changeset
494 * of a contiguous region of the PerfData memory region for storing a vector
a61af66fc99e Initial load
duke
parents:
diff changeset
495 * of bytes. This class is currently intended to be a base class for
a61af66fc99e Initial load
duke
parents:
diff changeset
496 * the PerfString class, and cannot be instantiated directly.
a61af66fc99e Initial load
duke
parents:
diff changeset
497 */
a61af66fc99e Initial load
duke
parents:
diff changeset
498 class PerfByteArray : public PerfData {
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
501 jint _length;
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 PerfByteArray(CounterNS ns, const char* namep, Units u, Variability v,
a61af66fc99e Initial load
duke
parents:
diff changeset
504 jint length);
a61af66fc99e Initial load
duke
parents:
diff changeset
505 };
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 class PerfString : public PerfByteArray {
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 void set_string(const char* s2);
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 PerfString(CounterNS ns, const char* namep, Variability v, jint length,
a61af66fc99e Initial load
duke
parents:
diff changeset
514 const char* initial_value)
a61af66fc99e Initial load
duke
parents:
diff changeset
515 : PerfByteArray(ns, namep, U_String, v, length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 if (is_valid()) set_string(initial_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 int format(char* buffer, int length);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 };
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
525 * The PerfStringConstant class provides a PerfData sub class that
a61af66fc99e Initial load
duke
parents:
diff changeset
526 * allows a null terminated string of single byte characters to be
a61af66fc99e Initial load
duke
parents:
diff changeset
527 * stored in the PerfData memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
528 */
a61af66fc99e Initial load
duke
parents:
diff changeset
529 class PerfStringConstant : public PerfString {
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 friend class PerfDataManager; // for access to protected constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // hide sample() - no need to sample constants
a61af66fc99e Initial load
duke
parents:
diff changeset
536 void sample() { }
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // Restrict string constant lengths to be <= PerfMaxStringConstLength.
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // This prevents long string constants, as can occur with very
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // long classpaths or java command lines, from consuming too much
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // PerfData memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
544 PerfStringConstant(CounterNS ns, const char* namep,
a61af66fc99e Initial load
duke
parents:
diff changeset
545 const char* initial_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
546 };
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
549 * The PerfStringVariable class provides a PerfData sub class that
a61af66fc99e Initial load
duke
parents:
diff changeset
550 * allows a null terminated string of single byte character data
a61af66fc99e Initial load
duke
parents:
diff changeset
551 * to be stored in PerfData memory region. The string value can be reset
a61af66fc99e Initial load
duke
parents:
diff changeset
552 * after initialization. If the string value is >= max_length, then
a61af66fc99e Initial load
duke
parents:
diff changeset
553 * it will be truncated to max_length characters. The copied string
a61af66fc99e Initial load
duke
parents:
diff changeset
554 * is always null terminated.
a61af66fc99e Initial load
duke
parents:
diff changeset
555 */
a61af66fc99e Initial load
duke
parents:
diff changeset
556 class PerfStringVariable : public PerfString {
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 friend class PerfDataManager; // for access to protected constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 // sampling of string variables are not yet supported
a61af66fc99e Initial load
duke
parents:
diff changeset
563 void sample() { }
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 PerfStringVariable(CounterNS ns, const char* namep, jint max_length,
a61af66fc99e Initial load
duke
parents:
diff changeset
566 const char* initial_value)
a61af66fc99e Initial load
duke
parents:
diff changeset
567 : PerfString(ns, namep, V_Variable, max_length+1,
a61af66fc99e Initial load
duke
parents:
diff changeset
568 initial_value) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
571 inline void set_value(const char* val) { set_string(val); }
a61af66fc99e Initial load
duke
parents:
diff changeset
572 };
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574
a61af66fc99e Initial load
duke
parents:
diff changeset
575 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
576 * The PerfDataList class is a container class for managing lists
a61af66fc99e Initial load
duke
parents:
diff changeset
577 * of PerfData items. The intention of this class is to allow for
a61af66fc99e Initial load
duke
parents:
diff changeset
578 * alternative implementations for management of list of PerfData
a61af66fc99e Initial load
duke
parents:
diff changeset
579 * items without impacting the code that uses the lists.
a61af66fc99e Initial load
duke
parents:
diff changeset
580 *
a61af66fc99e Initial load
duke
parents:
diff changeset
581 * The initial implementation is based upon GrowableArray. Searches
a61af66fc99e Initial load
duke
parents:
diff changeset
582 * on GrowableArray types is linear in nature and this may become
a61af66fc99e Initial load
duke
parents:
diff changeset
583 * a performance issue for creation of PerfData items, particularly
a61af66fc99e Initial load
duke
parents:
diff changeset
584 * from Java code where a test for existence is implemented as a
a61af66fc99e Initial load
duke
parents:
diff changeset
585 * search over all existing PerfData items.
a61af66fc99e Initial load
duke
parents:
diff changeset
586 *
a61af66fc99e Initial load
duke
parents:
diff changeset
587 * The abstraction is not complete. A more general container class
a61af66fc99e Initial load
duke
parents:
diff changeset
588 * would provide an Iterator abstraction that could be used to
a61af66fc99e Initial load
duke
parents:
diff changeset
589 * traverse the lists. This implementation still relys upon integer
a61af66fc99e Initial load
duke
parents:
diff changeset
590 * iterators and the at(int index) method. However, the GrowableArray
a61af66fc99e Initial load
duke
parents:
diff changeset
591 * is not directly visible outside this class and can be replaced by
a61af66fc99e Initial load
duke
parents:
diff changeset
592 * some other implementation, as long as that implementation provides
a61af66fc99e Initial load
duke
parents:
diff changeset
593 * a mechanism to iterate over the container by index.
a61af66fc99e Initial load
duke
parents:
diff changeset
594 */
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
595 class PerfDataList : public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
598
a61af66fc99e Initial load
duke
parents:
diff changeset
599 // GrowableArray implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
600 typedef GrowableArray<PerfData*> PerfDataArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 PerfDataArray* _set;
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // method to search for a instrumentation object by name
a61af66fc99e Initial load
duke
parents:
diff changeset
605 static bool by_name(void* name, PerfData* pd);
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // we expose the implementation here to facilitate the clone
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // method.
a61af66fc99e Initial load
duke
parents:
diff changeset
610 PerfDataArray* get_impl() { return _set; }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // create a PerfDataList with the given initial length
a61af66fc99e Initial load
duke
parents:
diff changeset
615 PerfDataList(int length);
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // create a PerfDataList as a shallow copy of the given PerfDataList
a61af66fc99e Initial load
duke
parents:
diff changeset
618 PerfDataList(PerfDataList* p);
a61af66fc99e Initial load
duke
parents:
diff changeset
619
a61af66fc99e Initial load
duke
parents:
diff changeset
620 ~PerfDataList();
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // return the PerfData item indicated by name,
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // or NULL if it doesn't exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
624 PerfData* find_by_name(const char* name);
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // return true if a PerfData item with the name specified in the
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // argument exists, otherwise return false.
a61af66fc99e Initial load
duke
parents:
diff changeset
628 bool contains(const char* name) { return find_by_name(name) != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // return the number of PerfData items in this list
a61af66fc99e Initial load
duke
parents:
diff changeset
631 int length() { return _set->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // add a PerfData item to this list
a61af66fc99e Initial load
duke
parents:
diff changeset
634 void append(PerfData *p) { _set->append(p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 // remove the given PerfData item from this list. When called
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // while iterating over the list, this method will result in a
a61af66fc99e Initial load
duke
parents:
diff changeset
638 // change in the length of the container. The at(int index)
a61af66fc99e Initial load
duke
parents:
diff changeset
639 // method is also impacted by this method as elements with an
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // index greater than the index of the element removed by this
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // method will be shifted down by one.
a61af66fc99e Initial load
duke
parents:
diff changeset
642 void remove(PerfData *p) { _set->remove(p); }
a61af66fc99e Initial load
duke
parents:
diff changeset
643
a61af66fc99e Initial load
duke
parents:
diff changeset
644 // create a new PerfDataList from this list. The new list is
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // a shallow copy of the original list and care should be taken
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // with respect to delete operations on the elements of the list
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // as the are likely in use by another copy of the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
648 PerfDataList* clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
649
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // for backward compatibility with GrowableArray - need to implement
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // some form of iterator to provide a cleaner abstraction for
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // iteration over the container.
a61af66fc99e Initial load
duke
parents:
diff changeset
653 PerfData* at(int index) { return _set->at(index); }
a61af66fc99e Initial load
duke
parents:
diff changeset
654 };
a61af66fc99e Initial load
duke
parents:
diff changeset
655
a61af66fc99e Initial load
duke
parents:
diff changeset
656
a61af66fc99e Initial load
duke
parents:
diff changeset
657 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
658 * The PerfDataManager class is responsible for creating PerfData
a61af66fc99e Initial load
duke
parents:
diff changeset
659 * subtypes via a set a factory methods and for managing lists
a61af66fc99e Initial load
duke
parents:
diff changeset
660 * of the various PerfData types.
a61af66fc99e Initial load
duke
parents:
diff changeset
661 */
a61af66fc99e Initial load
duke
parents:
diff changeset
662 class PerfDataManager : AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
663
a61af66fc99e Initial load
duke
parents:
diff changeset
664 friend class StatSampler; // for access to protected PerfDataList methods
a61af66fc99e Initial load
duke
parents:
diff changeset
665
a61af66fc99e Initial load
duke
parents:
diff changeset
666 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
667 static PerfDataList* _all;
a61af66fc99e Initial load
duke
parents:
diff changeset
668 static PerfDataList* _sampled;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 static PerfDataList* _constants;
a61af66fc99e Initial load
duke
parents:
diff changeset
670 static const char* _name_spaces[];
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // add a PerfData item to the list(s) of know PerfData objects
a61af66fc99e Initial load
duke
parents:
diff changeset
673 static void add_item(PerfData* p, bool sampled);
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // return the list of all known PerfData items
a61af66fc99e Initial load
duke
parents:
diff changeset
677 static PerfDataList* all();
a61af66fc99e Initial load
duke
parents:
diff changeset
678 static int count() { return _all->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // return the list of all known PerfData items that are to be
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // sampled by the StatSampler.
a61af66fc99e Initial load
duke
parents:
diff changeset
682 static PerfDataList* sampled();
a61af66fc99e Initial load
duke
parents:
diff changeset
683 static int sampled_count() { return _sampled->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // return the list of all known PerfData items that have a
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // variability classification of type Constant
a61af66fc99e Initial load
duke
parents:
diff changeset
687 static PerfDataList* constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
688 static int constants_count() { return _constants->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
691
a61af66fc99e Initial load
duke
parents:
diff changeset
692 // method to check for the existence of a PerfData item with
a61af66fc99e Initial load
duke
parents:
diff changeset
693 // the given name.
a61af66fc99e Initial load
duke
parents:
diff changeset
694 static bool exists(const char* name) { return _all->contains(name); }
a61af66fc99e Initial load
duke
parents:
diff changeset
695
10405
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 6725
diff changeset
696 // method to search for a instrumentation object by name
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 6725
diff changeset
697 static PerfData* find_by_name(const char* name);
f2110083203d 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 6725
diff changeset
698
0
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // method to map a CounterNS enumeration to a namespace string
a61af66fc99e Initial load
duke
parents:
diff changeset
700 static const char* ns_to_string(CounterNS ns) {
a61af66fc99e Initial load
duke
parents:
diff changeset
701 return _name_spaces[ns];
a61af66fc99e Initial load
duke
parents:
diff changeset
702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // methods to test the interface stability of a given counter namespace
a61af66fc99e Initial load
duke
parents:
diff changeset
705 //
a61af66fc99e Initial load
duke
parents:
diff changeset
706 static bool is_stable_supported(CounterNS ns) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 return (ns != NULL_NS) && ((ns % 3) == JAVA_NS);
a61af66fc99e Initial load
duke
parents:
diff changeset
708 }
a61af66fc99e Initial load
duke
parents:
diff changeset
709 static bool is_unstable_supported(CounterNS ns) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 return (ns != NULL_NS) && ((ns % 3) == COM_NS);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712 static bool is_unstable_unsupported(CounterNS ns) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 return (ns == NULL_NS) || ((ns % 3) == SUN_NS);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715
a61af66fc99e Initial load
duke
parents:
diff changeset
716 // methods to test the interface stability of a given counter name
a61af66fc99e Initial load
duke
parents:
diff changeset
717 //
a61af66fc99e Initial load
duke
parents:
diff changeset
718 static bool is_stable_supported(const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 const char* javadot = "java.";
a61af66fc99e Initial load
duke
parents:
diff changeset
720 return strncmp(name, javadot, strlen(javadot)) == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722 static bool is_unstable_supported(const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
723 const char* comdot = "com.sun.";
a61af66fc99e Initial load
duke
parents:
diff changeset
724 return strncmp(name, comdot, strlen(comdot)) == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726 static bool is_unstable_unsupported(const char* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 return !(is_stable_supported(name) && is_unstable_supported(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 // method to construct counter name strings in a given name space.
a61af66fc99e Initial load
duke
parents:
diff changeset
731 // The string object is allocated from the Resource Area and calls
a61af66fc99e Initial load
duke
parents:
diff changeset
732 // to this method must be made within a ResourceMark.
a61af66fc99e Initial load
duke
parents:
diff changeset
733 //
a61af66fc99e Initial load
duke
parents:
diff changeset
734 static char* counter_name(const char* name_space, const char* name);
a61af66fc99e Initial load
duke
parents:
diff changeset
735
a61af66fc99e Initial load
duke
parents:
diff changeset
736 // method to construct name space strings in a given name space.
a61af66fc99e Initial load
duke
parents:
diff changeset
737 // The string object is allocated from the Resource Area and calls
a61af66fc99e Initial load
duke
parents:
diff changeset
738 // to this method must be made within a ResourceMark.
a61af66fc99e Initial load
duke
parents:
diff changeset
739 //
a61af66fc99e Initial load
duke
parents:
diff changeset
740 static char* name_space(const char* name_space, const char* sub_space) {
a61af66fc99e Initial load
duke
parents:
diff changeset
741 return counter_name(name_space, sub_space);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 // same as above, but appends the instance number to the name space
a61af66fc99e Initial load
duke
parents:
diff changeset
745 //
a61af66fc99e Initial load
duke
parents:
diff changeset
746 static char* name_space(const char* name_space, const char* sub_space,
a61af66fc99e Initial load
duke
parents:
diff changeset
747 int instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 static char* name_space(const char* name_space, int instance);
a61af66fc99e Initial load
duke
parents:
diff changeset
749
a61af66fc99e Initial load
duke
parents:
diff changeset
750
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // these methods provide the general interface for creating
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // performance data resources. The types of performance data
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // resources can be extended by adding additional create<type>
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
755
a61af66fc99e Initial load
duke
parents:
diff changeset
756 // Constant Types
a61af66fc99e Initial load
duke
parents:
diff changeset
757 static PerfStringConstant* create_string_constant(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
758 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
759 const char *s, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 static PerfLongConstant* create_long_constant(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
762 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
763 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
764 jlong val, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
765
a61af66fc99e Initial load
duke
parents:
diff changeset
766
a61af66fc99e Initial load
duke
parents:
diff changeset
767 // Variable Types
a61af66fc99e Initial load
duke
parents:
diff changeset
768 static PerfStringVariable* create_string_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
769 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
770 int max_length,
a61af66fc99e Initial load
duke
parents:
diff changeset
771 const char *s, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 static PerfStringVariable* create_string_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
774 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
775 const char *s, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 return create_string_variable(ns, name, 0, s, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
777 };
a61af66fc99e Initial load
duke
parents:
diff changeset
778
a61af66fc99e Initial load
duke
parents:
diff changeset
779 static PerfLongVariable* create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
780 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
781 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
782 jlong ival, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 static PerfLongVariable* create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
785 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
786 PerfData::Units u, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
787 return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 };
a61af66fc99e Initial load
duke
parents:
diff changeset
789
a61af66fc99e Initial load
duke
parents:
diff changeset
790 static PerfLongVariable* create_long_variable(CounterNS, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
791 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
792 jlong* sp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
793
a61af66fc99e Initial load
duke
parents:
diff changeset
794 static PerfLongVariable* create_long_variable(CounterNS ns,
a61af66fc99e Initial load
duke
parents:
diff changeset
795 const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
796 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
797 PerfLongSampleHelper* sh,
a61af66fc99e Initial load
duke
parents:
diff changeset
798 TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
799
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 // Counter Types
a61af66fc99e Initial load
duke
parents:
diff changeset
802 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
803 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
804 jlong ival, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
807 PerfData::Units u, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
809 };
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
812 PerfData::Units u, jlong* sp,
a61af66fc99e Initial load
duke
parents:
diff changeset
813 TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
814
a61af66fc99e Initial load
duke
parents:
diff changeset
815 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
816 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
817 PerfLongSampleHelper* sh,
a61af66fc99e Initial load
duke
parents:
diff changeset
818 TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
819
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // these creation methods are provided for ease of use. These allow
a61af66fc99e Initial load
duke
parents:
diff changeset
822 // Long performance data types to be created with a shorthand syntax.
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824 static PerfConstant* create_constant(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
825 PerfData::Units u, jlong val, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
826 return create_long_constant(ns, name, u, val, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 }
a61af66fc99e Initial load
duke
parents:
diff changeset
828
a61af66fc99e Initial load
duke
parents:
diff changeset
829 static PerfVariable* create_variable(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
830 PerfData::Units u, jlong ival, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 return create_long_variable(ns, name, u, ival, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 static PerfVariable* create_variable(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
835 PerfData::Units u, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
836 return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 static PerfVariable* create_variable(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
840 PerfData::Units u, jlong* sp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
841 return create_long_variable(ns, name, u, sp, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 static PerfVariable* create_variable(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
845 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
846 PerfSampleHelper* sh, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 return create_long_variable(ns, name, u, sh, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 static PerfCounter* create_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
851 PerfData::Units u, jlong ival, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 return create_long_counter(ns, name, u, ival, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 static PerfCounter* create_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
856 PerfData::Units u, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859
a61af66fc99e Initial load
duke
parents:
diff changeset
860 static PerfCounter* create_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
861 PerfData::Units u, jlong* sp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
862 return create_long_counter(ns, name, u, sp, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864
a61af66fc99e Initial load
duke
parents:
diff changeset
865 static PerfCounter* create_counter(CounterNS ns, const char* name,
a61af66fc99e Initial load
duke
parents:
diff changeset
866 PerfData::Units u,
a61af66fc99e Initial load
duke
parents:
diff changeset
867 PerfSampleHelper* sh, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 return create_long_counter(ns, name, u, sh, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
870
a61af66fc99e Initial load
duke
parents:
diff changeset
871 static void destroy();
a61af66fc99e Initial load
duke
parents:
diff changeset
872 };
a61af66fc99e Initial load
duke
parents:
diff changeset
873
a61af66fc99e Initial load
duke
parents:
diff changeset
874 // Useful macros to create the performance counters
a61af66fc99e Initial load
duke
parents:
diff changeset
875 #define NEWPERFTICKCOUNTER(counter, counter_ns, counter_name) \
a61af66fc99e Initial load
duke
parents:
diff changeset
876 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
a61af66fc99e Initial load
duke
parents:
diff changeset
877 PerfData::U_Ticks,CHECK);}
a61af66fc99e Initial load
duke
parents:
diff changeset
878
a61af66fc99e Initial load
duke
parents:
diff changeset
879 #define NEWPERFEVENTCOUNTER(counter, counter_ns, counter_name) \
a61af66fc99e Initial load
duke
parents:
diff changeset
880 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
a61af66fc99e Initial load
duke
parents:
diff changeset
881 PerfData::U_Events,CHECK);}
a61af66fc99e Initial load
duke
parents:
diff changeset
882
875
6a93908f268f 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 0
diff changeset
883 #define NEWPERFBYTECOUNTER(counter, counter_ns, counter_name) \
6a93908f268f 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 0
diff changeset
884 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
6a93908f268f 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 0
diff changeset
885 PerfData::U_Bytes,CHECK);}
6a93908f268f 6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents: 0
diff changeset
886
0
a61af66fc99e Initial load
duke
parents:
diff changeset
887 // Utility Classes
a61af66fc99e Initial load
duke
parents:
diff changeset
888
a61af66fc99e Initial load
duke
parents:
diff changeset
889 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
890 * this class will administer a PerfCounter used as a time accumulator
a61af66fc99e Initial load
duke
parents:
diff changeset
891 * for a basic block much like the TraceTime class.
a61af66fc99e Initial load
duke
parents:
diff changeset
892 *
a61af66fc99e Initial load
duke
parents:
diff changeset
893 * Example:
a61af66fc99e Initial load
duke
parents:
diff changeset
894 *
a61af66fc99e Initial load
duke
parents:
diff changeset
895 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, 0LL, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
896 *
a61af66fc99e Initial load
duke
parents:
diff changeset
897 * {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 * PerfTraceTime ptt(my_time_counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 * // perform the operation you want to measure
a61af66fc99e Initial load
duke
parents:
diff changeset
900 * }
a61af66fc99e Initial load
duke
parents:
diff changeset
901 *
a61af66fc99e Initial load
duke
parents:
diff changeset
902 * Note: use of this class does not need to occur within a guarded
a61af66fc99e Initial load
duke
parents:
diff changeset
903 * block. The UsePerfData guard is used with the implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
904 * of this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
905 */
a61af66fc99e Initial load
duke
parents:
diff changeset
906 class PerfTraceTime : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
909 elapsedTimer _t;
a61af66fc99e Initial load
duke
parents:
diff changeset
910 PerfLongCounter* _timerp;
a61af66fc99e Initial load
duke
parents:
diff changeset
911 // pointer to thread-local or global recursion counter variable
a61af66fc99e Initial load
duke
parents:
diff changeset
912 int* _recursion_counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
915 inline PerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp), _recursion_counter(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 if (!UsePerfData) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
917 _t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
918 }
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920 inline PerfTraceTime(PerfLongCounter* timerp, int* recursion_counter) : _timerp(timerp), _recursion_counter(recursion_counter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
921 if (!UsePerfData || (_recursion_counter != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
922 (*_recursion_counter)++ > 0)) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
923 _t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925
a61af66fc99e Initial load
duke
parents:
diff changeset
926 inline void suspend() { if (!UsePerfData) return; _t.stop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
927 inline void resume() { if (!UsePerfData) return; _t.start(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
928
a61af66fc99e Initial load
duke
parents:
diff changeset
929 inline ~PerfTraceTime() {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 if (!UsePerfData || (_recursion_counter != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
931 --(*_recursion_counter) > 0)) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
932 _t.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
933 _timerp->inc(_t.ticks());
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935 };
a61af66fc99e Initial load
duke
parents:
diff changeset
936
a61af66fc99e Initial load
duke
parents:
diff changeset
937 /* The PerfTraceTimedEvent class is responsible for counting the
a61af66fc99e Initial load
duke
parents:
diff changeset
938 * occurrence of some event and measuring the the elapsed time of
a61af66fc99e Initial load
duke
parents:
diff changeset
939 * the event in two separate PerfCounter instances.
a61af66fc99e Initial load
duke
parents:
diff changeset
940 *
a61af66fc99e Initial load
duke
parents:
diff changeset
941 * Example:
a61af66fc99e Initial load
duke
parents:
diff changeset
942 *
a61af66fc99e Initial load
duke
parents:
diff changeset
943 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
944 * static PerfCounter* my_event_counter = PerfDataManager::create_counter("my.event.counter", PerfData::U_Events, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
945 *
a61af66fc99e Initial load
duke
parents:
diff changeset
946 * {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 * PerfTraceTimedEvent ptte(my_time_counter, my_event_counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
948 * // perform the operation you want to count and measure
a61af66fc99e Initial load
duke
parents:
diff changeset
949 * }
a61af66fc99e Initial load
duke
parents:
diff changeset
950 *
a61af66fc99e Initial load
duke
parents:
diff changeset
951 * Note: use of this class does not need to occur within a guarded
a61af66fc99e Initial load
duke
parents:
diff changeset
952 * block. The UsePerfData guard is used with the implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
953 * of this class.
a61af66fc99e Initial load
duke
parents:
diff changeset
954 *
a61af66fc99e Initial load
duke
parents:
diff changeset
955 */
a61af66fc99e Initial load
duke
parents:
diff changeset
956 class PerfTraceTimedEvent : public PerfTraceTime {
a61af66fc99e Initial load
duke
parents:
diff changeset
957
a61af66fc99e Initial load
duke
parents:
diff changeset
958 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
959 PerfLongCounter* _eventp;
a61af66fc99e Initial load
duke
parents:
diff changeset
960
a61af66fc99e Initial load
duke
parents:
diff changeset
961 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
962 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp): PerfTraceTime(timerp), _eventp(eventp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (!UsePerfData) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
964 _eventp->inc();
a61af66fc99e Initial load
duke
parents:
diff changeset
965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
966
a61af66fc99e Initial load
duke
parents:
diff changeset
967 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp, int* recursion_counter): PerfTraceTime(timerp, recursion_counter), _eventp(eventp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 if (!UsePerfData) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
969 _eventp->inc();
a61af66fc99e Initial load
duke
parents:
diff changeset
970 }
a61af66fc99e Initial load
duke
parents:
diff changeset
971 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
973 #endif // SHARE_VM_RUNTIME_PERFDATA_HPP