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