src/share/vm/runtime/perfData.hpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

duke@435 1 /*
mikael@6198 2 * Copyright (c) 2001, 2013, 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 */
zgu@3900 243 class PerfData : public CHeapObj<mtInternal> {
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 */
zgu@3900 345 class PerfLongSampleHelper : public CHeapObj<mtInternal> {
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; }
coleenp@4037 428 void clear_sample_helper() { _sample_helper = NULL; }
duke@435 429 };
duke@435 430
duke@435 431 /*
duke@435 432 * The PerfLongCounter class, and its alias PerfCounter, implement
duke@435 433 * a PerfData subtype that holds a jlong data value that can (should)
duke@435 434 * be modified in a monotonic manner. The inc(jlong) and add(jlong)
duke@435 435 * methods can be passed negative values to implement a monotonically
duke@435 436 * decreasing value. However, we rely upon the programmer to honor
duke@435 437 * the notion that this counter always moves in the same direction -
duke@435 438 * either increasing or decreasing.
duke@435 439 */
duke@435 440 class PerfLongCounter : public PerfLongVariant {
duke@435 441
duke@435 442 friend class PerfDataManager; // for access to protected constructor
duke@435 443
duke@435 444 protected:
duke@435 445
duke@435 446 PerfLongCounter(CounterNS ns, const char* namep, Units u,
duke@435 447 jlong initial_value=0)
duke@435 448 : PerfLongVariant(ns, namep, u, V_Monotonic,
duke@435 449 initial_value) { }
duke@435 450
duke@435 451 PerfLongCounter(CounterNS ns, const char* namep, Units u, jlong* sampled)
duke@435 452 : PerfLongVariant(ns, namep, u, V_Monotonic, sampled) { }
duke@435 453
duke@435 454 PerfLongCounter(CounterNS ns, const char* namep, Units u,
duke@435 455 PerfLongSampleHelper* sample_helper)
duke@435 456 : PerfLongVariant(ns, namep, u, V_Monotonic,
duke@435 457 sample_helper) { }
duke@435 458 };
duke@435 459
duke@435 460 typedef PerfLongCounter PerfCounter;
duke@435 461
duke@435 462 /*
duke@435 463 * The PerfLongVariable class, and its alias PerfVariable, implement
duke@435 464 * a PerfData subtype that holds a jlong data value that can
duke@435 465 * be modified in an unrestricted manner.
duke@435 466 */
duke@435 467 class PerfLongVariable : public PerfLongVariant {
duke@435 468
duke@435 469 friend class PerfDataManager; // for access to protected constructor
duke@435 470
duke@435 471 protected:
duke@435 472
duke@435 473 PerfLongVariable(CounterNS ns, const char* namep, Units u,
duke@435 474 jlong initial_value=0)
duke@435 475 : PerfLongVariant(ns, namep, u, V_Variable,
duke@435 476 initial_value) { }
duke@435 477
duke@435 478 PerfLongVariable(CounterNS ns, const char* namep, Units u, jlong* sampled)
duke@435 479 : PerfLongVariant(ns, namep, u, V_Variable, sampled) { }
duke@435 480
duke@435 481 PerfLongVariable(CounterNS ns, const char* namep, Units u,
duke@435 482 PerfLongSampleHelper* sample_helper)
duke@435 483 : PerfLongVariant(ns, namep, u, V_Variable,
duke@435 484 sample_helper) { }
duke@435 485
duke@435 486 public:
duke@435 487 inline void set_value(jlong val) { (*(jlong*)_valuep) = val; }
duke@435 488 };
duke@435 489
duke@435 490 typedef PerfLongVariable PerfVariable;
duke@435 491
duke@435 492 /*
duke@435 493 * The PerfByteArray provides a PerfData subtype that allows the creation
duke@435 494 * of a contiguous region of the PerfData memory region for storing a vector
duke@435 495 * of bytes. This class is currently intended to be a base class for
duke@435 496 * the PerfString class, and cannot be instantiated directly.
duke@435 497 */
duke@435 498 class PerfByteArray : public PerfData {
duke@435 499
duke@435 500 protected:
duke@435 501 jint _length;
duke@435 502
duke@435 503 PerfByteArray(CounterNS ns, const char* namep, Units u, Variability v,
duke@435 504 jint length);
duke@435 505 };
duke@435 506
duke@435 507 class PerfString : public PerfByteArray {
duke@435 508
duke@435 509 protected:
duke@435 510
duke@435 511 void set_string(const char* s2);
duke@435 512
duke@435 513 PerfString(CounterNS ns, const char* namep, Variability v, jint length,
duke@435 514 const char* initial_value)
duke@435 515 : PerfByteArray(ns, namep, U_String, v, length) {
duke@435 516 if (is_valid()) set_string(initial_value);
duke@435 517 }
duke@435 518
duke@435 519 public:
duke@435 520
duke@435 521 int format(char* buffer, int length);
duke@435 522 };
duke@435 523
duke@435 524 /*
duke@435 525 * The PerfStringConstant class provides a PerfData sub class that
duke@435 526 * allows a null terminated string of single byte characters to be
duke@435 527 * stored in the PerfData memory region.
duke@435 528 */
duke@435 529 class PerfStringConstant : public PerfString {
duke@435 530
duke@435 531 friend class PerfDataManager; // for access to protected constructor
duke@435 532
duke@435 533 private:
duke@435 534
duke@435 535 // hide sample() - no need to sample constants
duke@435 536 void sample() { }
duke@435 537
duke@435 538 protected:
duke@435 539
duke@435 540 // Restrict string constant lengths to be <= PerfMaxStringConstLength.
duke@435 541 // This prevents long string constants, as can occur with very
duke@435 542 // long classpaths or java command lines, from consuming too much
duke@435 543 // PerfData memory.
duke@435 544 PerfStringConstant(CounterNS ns, const char* namep,
duke@435 545 const char* initial_value);
duke@435 546 };
duke@435 547
duke@435 548 /*
duke@435 549 * The PerfStringVariable class provides a PerfData sub class that
duke@435 550 * allows a null terminated string of single byte character data
duke@435 551 * to be stored in PerfData memory region. The string value can be reset
duke@435 552 * after initialization. If the string value is >= max_length, then
duke@435 553 * it will be truncated to max_length characters. The copied string
duke@435 554 * is always null terminated.
duke@435 555 */
duke@435 556 class PerfStringVariable : public PerfString {
duke@435 557
duke@435 558 friend class PerfDataManager; // for access to protected constructor
duke@435 559
duke@435 560 protected:
duke@435 561
duke@435 562 // sampling of string variables are not yet supported
duke@435 563 void sample() { }
duke@435 564
duke@435 565 PerfStringVariable(CounterNS ns, const char* namep, jint max_length,
duke@435 566 const char* initial_value)
duke@435 567 : PerfString(ns, namep, V_Variable, max_length+1,
duke@435 568 initial_value) { }
duke@435 569
duke@435 570 public:
duke@435 571 inline void set_value(const char* val) { set_string(val); }
duke@435 572 };
duke@435 573
duke@435 574
duke@435 575 /*
duke@435 576 * The PerfDataList class is a container class for managing lists
duke@435 577 * of PerfData items. The intention of this class is to allow for
duke@435 578 * alternative implementations for management of list of PerfData
duke@435 579 * items without impacting the code that uses the lists.
duke@435 580 *
duke@435 581 * The initial implementation is based upon GrowableArray. Searches
duke@435 582 * on GrowableArray types is linear in nature and this may become
duke@435 583 * a performance issue for creation of PerfData items, particularly
duke@435 584 * from Java code where a test for existence is implemented as a
duke@435 585 * search over all existing PerfData items.
duke@435 586 *
duke@435 587 * The abstraction is not complete. A more general container class
duke@435 588 * would provide an Iterator abstraction that could be used to
duke@435 589 * traverse the lists. This implementation still relys upon integer
duke@435 590 * iterators and the at(int index) method. However, the GrowableArray
duke@435 591 * is not directly visible outside this class and can be replaced by
duke@435 592 * some other implementation, as long as that implementation provides
duke@435 593 * a mechanism to iterate over the container by index.
duke@435 594 */
zgu@3900 595 class PerfDataList : public CHeapObj<mtInternal> {
duke@435 596
duke@435 597 private:
duke@435 598
duke@435 599 // GrowableArray implementation
duke@435 600 typedef GrowableArray<PerfData*> PerfDataArray;
duke@435 601
duke@435 602 PerfDataArray* _set;
duke@435 603
duke@435 604 // method to search for a instrumentation object by name
duke@435 605 static bool by_name(void* name, PerfData* pd);
duke@435 606
duke@435 607 protected:
duke@435 608 // we expose the implementation here to facilitate the clone
duke@435 609 // method.
duke@435 610 PerfDataArray* get_impl() { return _set; }
duke@435 611
duke@435 612 public:
duke@435 613
duke@435 614 // create a PerfDataList with the given initial length
duke@435 615 PerfDataList(int length);
duke@435 616
duke@435 617 // create a PerfDataList as a shallow copy of the given PerfDataList
duke@435 618 PerfDataList(PerfDataList* p);
duke@435 619
duke@435 620 ~PerfDataList();
duke@435 621
duke@435 622 // return the PerfData item indicated by name,
duke@435 623 // or NULL if it doesn't exist.
duke@435 624 PerfData* find_by_name(const char* name);
duke@435 625
duke@435 626 // return true if a PerfData item with the name specified in the
duke@435 627 // argument exists, otherwise return false.
duke@435 628 bool contains(const char* name) { return find_by_name(name) != NULL; }
duke@435 629
duke@435 630 // return the number of PerfData items in this list
duke@435 631 int length() { return _set->length(); }
duke@435 632
duke@435 633 // add a PerfData item to this list
duke@435 634 void append(PerfData *p) { _set->append(p); }
duke@435 635
duke@435 636 // remove the given PerfData item from this list. When called
duke@435 637 // while iterating over the list, this method will result in a
duke@435 638 // change in the length of the container. The at(int index)
duke@435 639 // method is also impacted by this method as elements with an
duke@435 640 // index greater than the index of the element removed by this
duke@435 641 // method will be shifted down by one.
duke@435 642 void remove(PerfData *p) { _set->remove(p); }
duke@435 643
duke@435 644 // create a new PerfDataList from this list. The new list is
duke@435 645 // a shallow copy of the original list and care should be taken
duke@435 646 // with respect to delete operations on the elements of the list
duke@435 647 // as the are likely in use by another copy of the list.
duke@435 648 PerfDataList* clone();
duke@435 649
duke@435 650 // for backward compatibility with GrowableArray - need to implement
duke@435 651 // some form of iterator to provide a cleaner abstraction for
duke@435 652 // iteration over the container.
duke@435 653 PerfData* at(int index) { return _set->at(index); }
duke@435 654 };
duke@435 655
duke@435 656
duke@435 657 /*
duke@435 658 * The PerfDataManager class is responsible for creating PerfData
duke@435 659 * subtypes via a set a factory methods and for managing lists
duke@435 660 * of the various PerfData types.
duke@435 661 */
duke@435 662 class PerfDataManager : AllStatic {
duke@435 663
duke@435 664 friend class StatSampler; // for access to protected PerfDataList methods
duke@435 665
duke@435 666 private:
duke@435 667 static PerfDataList* _all;
duke@435 668 static PerfDataList* _sampled;
duke@435 669 static PerfDataList* _constants;
duke@435 670 static const char* _name_spaces[];
duke@435 671
duke@435 672 // add a PerfData item to the list(s) of know PerfData objects
duke@435 673 static void add_item(PerfData* p, bool sampled);
duke@435 674
duke@435 675 protected:
duke@435 676 // return the list of all known PerfData items
duke@435 677 static PerfDataList* all();
duke@435 678 static int count() { return _all->length(); }
duke@435 679
duke@435 680 // return the list of all known PerfData items that are to be
duke@435 681 // sampled by the StatSampler.
duke@435 682 static PerfDataList* sampled();
duke@435 683 static int sampled_count() { return _sampled->length(); }
duke@435 684
duke@435 685 // return the list of all known PerfData items that have a
duke@435 686 // variability classification of type Constant
duke@435 687 static PerfDataList* constants();
duke@435 688 static int constants_count() { return _constants->length(); }
duke@435 689
duke@435 690 public:
duke@435 691
duke@435 692 // method to check for the existence of a PerfData item with
duke@435 693 // the given name.
duke@435 694 static bool exists(const char* name) { return _all->contains(name); }
duke@435 695
sla@5237 696 // method to search for a instrumentation object by name
sla@5237 697 static PerfData* find_by_name(const char* name);
sla@5237 698
duke@435 699 // method to map a CounterNS enumeration to a namespace string
duke@435 700 static const char* ns_to_string(CounterNS ns) {
duke@435 701 return _name_spaces[ns];
duke@435 702 }
duke@435 703
duke@435 704 // methods to test the interface stability of a given counter namespace
duke@435 705 //
duke@435 706 static bool is_stable_supported(CounterNS ns) {
duke@435 707 return (ns != NULL_NS) && ((ns % 3) == JAVA_NS);
duke@435 708 }
duke@435 709 static bool is_unstable_supported(CounterNS ns) {
duke@435 710 return (ns != NULL_NS) && ((ns % 3) == COM_NS);
duke@435 711 }
duke@435 712 static bool is_unstable_unsupported(CounterNS ns) {
duke@435 713 return (ns == NULL_NS) || ((ns % 3) == SUN_NS);
duke@435 714 }
duke@435 715
duke@435 716 // methods to test the interface stability of a given counter name
duke@435 717 //
duke@435 718 static bool is_stable_supported(const char* name) {
duke@435 719 const char* javadot = "java.";
duke@435 720 return strncmp(name, javadot, strlen(javadot)) == 0;
duke@435 721 }
duke@435 722 static bool is_unstable_supported(const char* name) {
duke@435 723 const char* comdot = "com.sun.";
duke@435 724 return strncmp(name, comdot, strlen(comdot)) == 0;
duke@435 725 }
duke@435 726 static bool is_unstable_unsupported(const char* name) {
duke@435 727 return !(is_stable_supported(name) && is_unstable_supported(name));
duke@435 728 }
duke@435 729
duke@435 730 // method to construct counter name strings in a given name space.
duke@435 731 // The string object is allocated from the Resource Area and calls
duke@435 732 // to this method must be made within a ResourceMark.
duke@435 733 //
duke@435 734 static char* counter_name(const char* name_space, const char* name);
duke@435 735
duke@435 736 // method to construct name space strings in a given name space.
duke@435 737 // The string object is allocated from the Resource Area and calls
duke@435 738 // to this method must be made within a ResourceMark.
duke@435 739 //
duke@435 740 static char* name_space(const char* name_space, const char* sub_space) {
duke@435 741 return counter_name(name_space, sub_space);
duke@435 742 }
duke@435 743
duke@435 744 // same as above, but appends the instance number to the name space
duke@435 745 //
duke@435 746 static char* name_space(const char* name_space, const char* sub_space,
duke@435 747 int instance);
duke@435 748 static char* name_space(const char* name_space, int instance);
duke@435 749
duke@435 750
duke@435 751 // these methods provide the general interface for creating
duke@435 752 // performance data resources. The types of performance data
duke@435 753 // resources can be extended by adding additional create<type>
duke@435 754 // methods.
duke@435 755
duke@435 756 // Constant Types
duke@435 757 static PerfStringConstant* create_string_constant(CounterNS ns,
duke@435 758 const char* name,
duke@435 759 const char *s, TRAPS);
duke@435 760
duke@435 761 static PerfLongConstant* create_long_constant(CounterNS ns,
duke@435 762 const char* name,
duke@435 763 PerfData::Units u,
duke@435 764 jlong val, TRAPS);
duke@435 765
duke@435 766
duke@435 767 // Variable Types
duke@435 768 static PerfStringVariable* create_string_variable(CounterNS ns,
duke@435 769 const char* name,
duke@435 770 int max_length,
duke@435 771 const char *s, TRAPS);
duke@435 772
duke@435 773 static PerfStringVariable* create_string_variable(CounterNS ns,
duke@435 774 const char* name,
duke@435 775 const char *s, TRAPS) {
duke@435 776 return create_string_variable(ns, name, 0, s, CHECK_NULL);
duke@435 777 };
duke@435 778
duke@435 779 static PerfLongVariable* create_long_variable(CounterNS ns,
duke@435 780 const char* name,
duke@435 781 PerfData::Units u,
duke@435 782 jlong ival, TRAPS);
duke@435 783
duke@435 784 static PerfLongVariable* create_long_variable(CounterNS ns,
duke@435 785 const char* name,
duke@435 786 PerfData::Units u, TRAPS) {
duke@435 787 return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL);
duke@435 788 };
duke@435 789
duke@435 790 static PerfLongVariable* create_long_variable(CounterNS, const char* name,
duke@435 791 PerfData::Units u,
duke@435 792 jlong* sp, TRAPS);
duke@435 793
duke@435 794 static PerfLongVariable* create_long_variable(CounterNS ns,
duke@435 795 const char* name,
duke@435 796 PerfData::Units u,
duke@435 797 PerfLongSampleHelper* sh,
duke@435 798 TRAPS);
duke@435 799
duke@435 800
duke@435 801 // Counter Types
duke@435 802 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
duke@435 803 PerfData::Units u,
duke@435 804 jlong ival, TRAPS);
duke@435 805
duke@435 806 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
duke@435 807 PerfData::Units u, TRAPS) {
duke@435 808 return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL);
duke@435 809 };
duke@435 810
duke@435 811 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
duke@435 812 PerfData::Units u, jlong* sp,
duke@435 813 TRAPS);
duke@435 814
duke@435 815 static PerfLongCounter* create_long_counter(CounterNS ns, const char* name,
duke@435 816 PerfData::Units u,
duke@435 817 PerfLongSampleHelper* sh,
duke@435 818 TRAPS);
duke@435 819
duke@435 820
duke@435 821 // these creation methods are provided for ease of use. These allow
duke@435 822 // Long performance data types to be created with a shorthand syntax.
duke@435 823
duke@435 824 static PerfConstant* create_constant(CounterNS ns, const char* name,
duke@435 825 PerfData::Units u, jlong val, TRAPS) {
duke@435 826 return create_long_constant(ns, name, u, val, CHECK_NULL);
duke@435 827 }
duke@435 828
duke@435 829 static PerfVariable* create_variable(CounterNS ns, const char* name,
duke@435 830 PerfData::Units u, jlong ival, TRAPS) {
duke@435 831 return create_long_variable(ns, name, u, ival, CHECK_NULL);
duke@435 832 }
duke@435 833
duke@435 834 static PerfVariable* create_variable(CounterNS ns, const char* name,
duke@435 835 PerfData::Units u, TRAPS) {
duke@435 836 return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL);
duke@435 837 }
duke@435 838
duke@435 839 static PerfVariable* create_variable(CounterNS ns, const char* name,
duke@435 840 PerfData::Units u, jlong* sp, TRAPS) {
duke@435 841 return create_long_variable(ns, name, u, sp, CHECK_NULL);
duke@435 842 }
duke@435 843
duke@435 844 static PerfVariable* create_variable(CounterNS ns, const char* name,
duke@435 845 PerfData::Units u,
duke@435 846 PerfSampleHelper* sh, TRAPS) {
duke@435 847 return create_long_variable(ns, name, u, sh, CHECK_NULL);
duke@435 848 }
duke@435 849
duke@435 850 static PerfCounter* create_counter(CounterNS ns, const char* name,
duke@435 851 PerfData::Units u, jlong ival, TRAPS) {
duke@435 852 return create_long_counter(ns, name, u, ival, CHECK_NULL);
duke@435 853 }
duke@435 854
duke@435 855 static PerfCounter* create_counter(CounterNS ns, const char* name,
duke@435 856 PerfData::Units u, TRAPS) {
duke@435 857 return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL);
duke@435 858 }
duke@435 859
duke@435 860 static PerfCounter* create_counter(CounterNS ns, const char* name,
duke@435 861 PerfData::Units u, jlong* sp, TRAPS) {
duke@435 862 return create_long_counter(ns, name, u, sp, CHECK_NULL);
duke@435 863 }
duke@435 864
duke@435 865 static PerfCounter* create_counter(CounterNS ns, const char* name,
duke@435 866 PerfData::Units u,
duke@435 867 PerfSampleHelper* sh, TRAPS) {
duke@435 868 return create_long_counter(ns, name, u, sh, CHECK_NULL);
duke@435 869 }
duke@435 870
duke@435 871 static void destroy();
duke@435 872 };
duke@435 873
duke@435 874 // Useful macros to create the performance counters
duke@435 875 #define NEWPERFTICKCOUNTER(counter, counter_ns, counter_name) \
duke@435 876 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
duke@435 877 PerfData::U_Ticks,CHECK);}
duke@435 878
duke@435 879 #define NEWPERFEVENTCOUNTER(counter, counter_ns, counter_name) \
duke@435 880 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
duke@435 881 PerfData::U_Events,CHECK);}
duke@435 882
mchung@1310 883 #define NEWPERFBYTECOUNTER(counter, counter_ns, counter_name) \
mchung@1310 884 {counter = PerfDataManager::create_counter(counter_ns, counter_name, \
mchung@1310 885 PerfData::U_Bytes,CHECK);}
mchung@1310 886
duke@435 887 // Utility Classes
duke@435 888
duke@435 889 /*
duke@435 890 * this class will administer a PerfCounter used as a time accumulator
duke@435 891 * for a basic block much like the TraceTime class.
duke@435 892 *
duke@435 893 * Example:
duke@435 894 *
duke@435 895 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, 0LL, CHECK);
duke@435 896 *
duke@435 897 * {
duke@435 898 * PerfTraceTime ptt(my_time_counter);
duke@435 899 * // perform the operation you want to measure
duke@435 900 * }
duke@435 901 *
duke@435 902 * Note: use of this class does not need to occur within a guarded
duke@435 903 * block. The UsePerfData guard is used with the implementation
duke@435 904 * of this class.
duke@435 905 */
duke@435 906 class PerfTraceTime : public StackObj {
duke@435 907
duke@435 908 protected:
duke@435 909 elapsedTimer _t;
duke@435 910 PerfLongCounter* _timerp;
duke@435 911 // pointer to thread-local or global recursion counter variable
duke@435 912 int* _recursion_counter;
duke@435 913
duke@435 914 public:
duke@435 915 inline PerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp), _recursion_counter(NULL) {
duke@435 916 if (!UsePerfData) return;
duke@435 917 _t.start();
duke@435 918 }
duke@435 919
duke@435 920 inline PerfTraceTime(PerfLongCounter* timerp, int* recursion_counter) : _timerp(timerp), _recursion_counter(recursion_counter) {
duke@435 921 if (!UsePerfData || (_recursion_counter != NULL &&
duke@435 922 (*_recursion_counter)++ > 0)) return;
duke@435 923 _t.start();
duke@435 924 }
duke@435 925
duke@435 926 inline void suspend() { if (!UsePerfData) return; _t.stop(); }
duke@435 927 inline void resume() { if (!UsePerfData) return; _t.start(); }
duke@435 928
duke@435 929 inline ~PerfTraceTime() {
duke@435 930 if (!UsePerfData || (_recursion_counter != NULL &&
duke@435 931 --(*_recursion_counter) > 0)) return;
duke@435 932 _t.stop();
duke@435 933 _timerp->inc(_t.ticks());
duke@435 934 }
duke@435 935 };
duke@435 936
duke@435 937 /* The PerfTraceTimedEvent class is responsible for counting the
duke@435 938 * occurrence of some event and measuring the the elapsed time of
duke@435 939 * the event in two separate PerfCounter instances.
duke@435 940 *
duke@435 941 * Example:
duke@435 942 *
duke@435 943 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, CHECK);
duke@435 944 * static PerfCounter* my_event_counter = PerfDataManager::create_counter("my.event.counter", PerfData::U_Events, CHECK);
duke@435 945 *
duke@435 946 * {
duke@435 947 * PerfTraceTimedEvent ptte(my_time_counter, my_event_counter);
duke@435 948 * // perform the operation you want to count and measure
duke@435 949 * }
duke@435 950 *
duke@435 951 * Note: use of this class does not need to occur within a guarded
duke@435 952 * block. The UsePerfData guard is used with the implementation
duke@435 953 * of this class.
duke@435 954 *
duke@435 955 */
duke@435 956 class PerfTraceTimedEvent : public PerfTraceTime {
duke@435 957
duke@435 958 protected:
duke@435 959 PerfLongCounter* _eventp;
duke@435 960
duke@435 961 public:
duke@435 962 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp): PerfTraceTime(timerp), _eventp(eventp) {
duke@435 963 if (!UsePerfData) return;
duke@435 964 _eventp->inc();
duke@435 965 }
duke@435 966
duke@435 967 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp, int* recursion_counter): PerfTraceTime(timerp, recursion_counter), _eventp(eventp) {
duke@435 968 if (!UsePerfData) return;
duke@435 969 _eventp->inc();
duke@435 970 }
duke@435 971 };
stefank@2314 972
stefank@2314 973 #endif // SHARE_VM_RUNTIME_PERFDATA_HPP

mercurial