src/share/vm/runtime/perfData.hpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1907
c18cbe5936b8
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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

mercurial