duke@435: /* mikael@6198: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_RUNTIME_PERFDATA_HPP stefank@2314: #define SHARE_VM_RUNTIME_PERFDATA_HPP stefank@2314: stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "runtime/perfMemory.hpp" stefank@2314: #include "runtime/timer.hpp" stefank@2314: #include "utilities/growableArray.hpp" stefank@2314: duke@435: /* jvmstat global and subsystem counter name space - enumeration value duke@435: * serve as an index into the PerfDataManager::_name_space[] array duke@435: * containing the corresponding name space string. Only the top level duke@435: * subsystem name spaces are represented here. duke@435: */ duke@435: enum CounterNS { duke@435: // top level name spaces duke@435: JAVA_NS, duke@435: COM_NS, duke@435: SUN_NS, duke@435: // subsystem name spaces duke@435: JAVA_GC, // Garbage Collection name spaces duke@435: COM_GC, duke@435: SUN_GC, duke@435: JAVA_CI, // Compiler name spaces duke@435: COM_CI, duke@435: SUN_CI, duke@435: JAVA_CLS, // Class Loader name spaces duke@435: COM_CLS, duke@435: SUN_CLS, duke@435: JAVA_RT, // Runtime name spaces duke@435: COM_RT, duke@435: SUN_RT, duke@435: JAVA_OS, // Operating System name spaces duke@435: COM_OS, duke@435: SUN_OS, duke@435: JAVA_THREADS, // Threads System name spaces duke@435: COM_THREADS, duke@435: SUN_THREADS, duke@435: JAVA_PROPERTY, // Java Property name spaces duke@435: COM_PROPERTY, duke@435: SUN_PROPERTY, duke@435: NULL_NS, duke@435: COUNTERNS_LAST = NULL_NS duke@435: }; duke@435: duke@435: /* duke@435: * Classes to support access to production performance data duke@435: * duke@435: * The PerfData class structure is provided for creation, access, and update duke@435: * of performance data (a.k.a. instrumentation) in a specific memory region duke@435: * which is possibly accessible as shared memory. Although not explicitly duke@435: * prevented from doing so, developers should not use the values returned duke@435: * by accessor methods to make algorithmic decisions as they are potentially duke@435: * extracted from a shared memory region. Although any shared memory region duke@435: * created is with appropriate access restrictions, allowing read-write access duke@435: * only to the principal that created the JVM, it is believed that a the duke@435: * shared memory region facilitates an easier attack path than attacks duke@435: * launched through mechanisms such as /proc. For this reason, it is duke@435: * recommended that data returned by PerfData accessor methods be used duke@435: * cautiously. duke@435: * duke@435: * There are three variability classifications of performance data duke@435: * Constants - value is written to the PerfData memory once, on creation duke@435: * Variables - value is modifiable, with no particular restrictions duke@435: * Counters - value is monotonically changing (increasing or decreasing) duke@435: * duke@435: * The performance data items can also have various types. The class duke@435: * hierarchy and the structure of the memory region are designed to duke@435: * accommodate new types as they are needed. Types are specified in duke@435: * terms of Java basic types, which accommodates client applications duke@435: * written in the Java programming language. The class hierarchy is: duke@435: * duke@435: * - PerfData (Abstract) duke@435: * - PerfLong (Abstract) duke@435: * - PerfLongConstant (alias: PerfConstant) duke@435: * - PerfLongVariant (Abstract) duke@435: * - PerfLongVariable (alias: PerfVariable) duke@435: * - PerfLongCounter (alias: PerfCounter) duke@435: * duke@435: * - PerfByteArray (Abstract) duke@435: * - PerfString (Abstract) duke@435: * - PerfStringVariable duke@435: * - PerfStringConstant duke@435: * duke@435: * duke@435: * As seen in the class hierarchy, the initially supported types are: duke@435: * duke@435: * Long - performance data holds a Java long type duke@435: * ByteArray - performance data holds an array of Java bytes duke@435: * used for holding C++ char arrays. duke@435: * duke@435: * The String type is derived from the ByteArray type. duke@435: * duke@435: * A PerfData subtype is not required to provide an implementation for duke@435: * each variability classification. For example, the String type provides duke@435: * Variable and Constant variablility classifications in the PerfStringVariable duke@435: * and PerfStringConstant classes, but does not provide a counter type. duke@435: * duke@435: * Performance data are also described by a unit of measure. Units allow duke@435: * client applications to make reasonable decisions on how to treat duke@435: * performance data generically, preventing the need to hard-code the duke@435: * specifics of a particular data item in client applications. The current duke@435: * set of units are: duke@435: * duke@435: * None - the data has no units of measure duke@435: * Bytes - data is measured in bytes duke@435: * Ticks - data is measured in clock ticks duke@435: * Events - data is measured in events. For example, duke@435: * the number of garbage collection events or the duke@435: * number of methods compiled. duke@435: * String - data is not numerical. For example, duke@435: * the java command line options duke@435: * Hertz - data is a frequency duke@435: * duke@435: * The performance counters also provide a support attribute, indicating duke@435: * the stability of the counter as a programmatic interface. The support duke@435: * level is also implied by the name space in which the counter is created. duke@435: * The counter name space support conventions follow the Java package, class, duke@435: * and property support conventions: duke@435: * duke@435: * java.* - stable, supported interface duke@435: * com.sun.* - unstable, supported interface duke@435: * sun.* - unstable, unsupported interface duke@435: * duke@435: * In the above context, unstable is a measure of the interface support duke@435: * level, not the implementation stability level. duke@435: * duke@435: * Currently, instances of PerfData subtypes are considered to have duke@435: * a life time equal to that of the VM and are managed by the duke@435: * PerfDataManager class. All constructors for the PerfData class and duke@435: * its subtypes have protected constructors. Creation of PerfData duke@435: * instances is performed by invoking various create methods on the duke@435: * PerfDataManager class. Users should not attempt to delete these duke@435: * instances as the PerfDataManager class expects to perform deletion duke@435: * operations on exit of the VM. duke@435: * duke@435: * Examples: duke@435: * duke@435: * Creating performance counter that holds a monotonically increasing duke@435: * long data value with units specified in U_Bytes in the "java.gc.*" duke@435: * name space. duke@435: * duke@435: * PerfLongCounter* foo_counter; duke@435: * duke@435: * foo_counter = PerfDataManager::create_long_counter(JAVA_GC, "foo", duke@435: * PerfData::U_Bytes, duke@435: * optionalInitialValue, duke@435: * CHECK); duke@435: * foo_counter->inc(); duke@435: * duke@435: * Creating a performance counter that holds a variably change long duke@435: * data value with untis specified in U_Bytes in the "com.sun.ci duke@435: * name space. duke@435: * duke@435: * PerfLongVariable* bar_varible; duke@435: * bar_variable = PerfDataManager::create_long_variable(COM_CI, "bar", duke@435: .* PerfData::U_Bytes, duke@435: * optionalInitialValue, duke@435: * CHECK); duke@435: * duke@435: * bar_variable->inc(); duke@435: * bar_variable->set_value(0); duke@435: * duke@435: * Creating a performance counter that holds a constant string value in duke@435: * the "sun.cls.*" name space. duke@435: * duke@435: * PerfDataManager::create_string_constant(SUN_CLS, "foo", string, CHECK); duke@435: * duke@435: * Although the create_string_constant() factory method returns a pointer duke@435: * to the PerfStringConstant object, it can safely be ignored. Developers duke@435: * are not encouraged to access the string constant's value via this duke@435: * pointer at this time due to security concerns. duke@435: * duke@435: * Creating a performance counter in an arbitrary name space that holds a duke@435: * value that is sampled by the StatSampler periodic task. duke@435: * duke@435: * PerfDataManager::create_counter("foo.sampled", PerfData::U_Events, duke@435: * &my_jlong, CHECK); duke@435: * duke@435: * In this example, the PerfData pointer can be ignored as the caller duke@435: * is relying on the StatSampler PeriodicTask to sample the given duke@435: * address at a regular interval. The interval is defined by the duke@435: * PerfDataSamplingInterval global variable, and is applyied on duke@435: * a system wide basis, not on an per-counter basis. duke@435: * duke@435: * Creating a performance counter in an arbitrary name space that utilizes duke@435: * a helper object to return a value to the StatSampler via the take_sample() duke@435: * method. duke@435: * duke@435: * class MyTimeSampler : public PerfLongSampleHelper { duke@435: * public: duke@435: * jlong take_sample() { return os::elapsed_counter(); } duke@435: * }; duke@435: * duke@435: * PerfDataManager::create_counter(SUN_RT, "helped", duke@435: * PerfData::U_Ticks, duke@435: * new MyTimeSampler(), CHECK); duke@435: * duke@435: * In this example, a subtype of PerfLongSampleHelper is instantiated duke@435: * and its take_sample() method is overridden to perform whatever duke@435: * operation is necessary to generate the data sample. This method duke@435: * will be called by the StatSampler at a regular interval, defined duke@435: * by the PerfDataSamplingInterval global variable. duke@435: * duke@435: * As before, PerfSampleHelper is an alias for PerfLongSampleHelper. duke@435: * duke@435: * For additional uses of PerfData subtypes, see the utility classes duke@435: * PerfTraceTime and PerfTraceTimedEvent below. duke@435: * duke@435: * Always-on non-sampled counters can be created independent of duke@435: * the UsePerfData flag. Counters will be created on the c-heap duke@435: * if UsePerfData is false. duke@435: * duke@435: * Until further noice, all PerfData objects should be created and duke@435: * manipulated within a guarded block. The guard variable is duke@435: * UsePerfData, a product flag set to true by default. This flag may duke@435: * be removed from the product in the future. duke@435: * duke@435: */ zgu@3900: class PerfData : public CHeapObj { duke@435: duke@435: friend class StatSampler; // for access to protected void sample() duke@435: friend class PerfDataManager; // for access to protected destructor duke@435: duke@435: public: duke@435: duke@435: // the Variability enum must be kept in synchronization with the duke@435: // the com.sun.hotspot.perfdata.Variability class duke@435: enum Variability { duke@435: V_Constant = 1, duke@435: V_Monotonic = 2, duke@435: V_Variable = 3, duke@435: V_last = V_Variable duke@435: }; duke@435: duke@435: // the Units enum must be kept in synchronization with the duke@435: // the com.sun.hotspot.perfdata.Units class duke@435: enum Units { duke@435: U_None = 1, duke@435: U_Bytes = 2, duke@435: U_Ticks = 3, duke@435: U_Events = 4, duke@435: U_String = 5, duke@435: U_Hertz = 6, duke@435: U_Last = U_Hertz duke@435: }; duke@435: duke@435: // Miscellaneous flags duke@435: enum Flags { duke@435: F_None = 0x0, duke@435: F_Supported = 0x1 // interface is supported - java.* and com.sun.* duke@435: }; duke@435: duke@435: private: duke@435: char* _name; duke@435: Variability _v; duke@435: Units _u; duke@435: bool _on_c_heap; duke@435: Flags _flags; duke@435: duke@435: PerfDataEntry* _pdep; duke@435: duke@435: protected: duke@435: duke@435: void *_valuep; duke@435: duke@435: PerfData(CounterNS ns, const char* name, Units u, Variability v); duke@435: ~PerfData(); duke@435: duke@435: // create the entry for the PerfData item in the PerfData memory region. duke@435: // this region is maintained separately from the PerfData objects to duke@435: // facilitate its use by external processes. duke@435: void create_entry(BasicType dtype, size_t dsize, size_t dlen = 0); duke@435: duke@435: // sample the data item given at creation time and write its value duke@435: // into the its corresponding PerfMemory location. duke@435: virtual void sample() = 0; duke@435: duke@435: public: duke@435: duke@435: // returns a boolean indicating the validity of this object. duke@435: // the object is valid if and only if memory in PerfMemory duke@435: // region was successfully allocated. duke@435: inline bool is_valid() { return _valuep != NULL; } duke@435: duke@435: // returns a boolean indicating whether the underlying object duke@435: // was allocated in the PerfMemory region or on the C heap. duke@435: inline bool is_on_c_heap() { return _on_c_heap; } duke@435: duke@435: // returns a pointer to a char* containing the name of the item. duke@435: // The pointer returned is the pointer to a copy of the name duke@435: // passed to the constructor, not the pointer to the name in the duke@435: // PerfData memory region. This redundancy is maintained for duke@435: // security reasons as the PerfMemory region may be in shared duke@435: // memory. duke@435: const char* name() { return _name; } duke@435: duke@435: // returns the variability classification associated with this item duke@435: Variability variability() { return _v; } duke@435: duke@435: // returns the units associated with this item. duke@435: Units units() { return _u; } duke@435: duke@435: // returns the flags associated with this item. duke@435: Flags flags() { return _flags; } duke@435: duke@435: // returns the address of the data portion of the item in the duke@435: // PerfData memory region. duke@435: inline void* get_address() { return _valuep; } duke@435: duke@435: // returns the value of the data portion of the item in the duke@435: // PerfData memory region formatted as a string. duke@435: virtual int format(char* cp, int length) = 0; duke@435: }; duke@435: duke@435: /* duke@435: * PerfLongSampleHelper, and its alias PerfSamplerHelper, is a base class duke@435: * for helper classes that rely upon the StatSampler periodic task to duke@435: * invoke the take_sample() method and write the value returned to its duke@435: * appropriate location in the PerfData memory region. duke@435: */ zgu@3900: class PerfLongSampleHelper : public CHeapObj { duke@435: public: duke@435: virtual jlong take_sample() = 0; duke@435: }; duke@435: duke@435: typedef PerfLongSampleHelper PerfSampleHelper; duke@435: duke@435: duke@435: /* duke@435: * PerfLong is the base class for the various Long PerfData subtypes. duke@435: * it contains implementation details that are common among its derived duke@435: * types. duke@435: */ duke@435: class PerfLong : public PerfData { duke@435: duke@435: protected: duke@435: duke@435: PerfLong(CounterNS ns, const char* namep, Units u, Variability v); duke@435: duke@435: public: duke@435: int format(char* buffer, int length); duke@435: duke@435: // returns the value of the data portion of the item in the duke@435: // PerfData memory region. duke@435: inline jlong get_value() { return *(jlong*)_valuep; } duke@435: }; duke@435: duke@435: /* duke@435: * The PerfLongConstant class, and its alias PerfConstant, implement duke@435: * a PerfData subtype that holds a jlong data value that is set upon duke@435: * creation of an instance of this class. This class provides no duke@435: * methods for changing the data value stored in PerfData memory region. duke@435: */ duke@435: class PerfLongConstant : public PerfLong { duke@435: duke@435: friend class PerfDataManager; // for access to protected constructor duke@435: duke@435: private: duke@435: // hide sample() - no need to sample constants duke@435: void sample() { } duke@435: duke@435: protected: duke@435: duke@435: PerfLongConstant(CounterNS ns, const char* namep, Units u, duke@435: jlong initial_value=0) duke@435: : PerfLong(ns, namep, u, V_Constant) { duke@435: duke@435: if (is_valid()) *(jlong*)_valuep = initial_value; duke@435: } duke@435: }; duke@435: duke@435: typedef PerfLongConstant PerfConstant; duke@435: duke@435: /* duke@435: * The PerfLongVariant class, and its alias PerfVariant, implement duke@435: * a PerfData subtype that holds a jlong data value that can be modified duke@435: * in an unrestricted manner. This class provides the implementation details duke@435: * for common functionality among its derived types. duke@435: */ duke@435: class PerfLongVariant : public PerfLong { duke@435: duke@435: protected: duke@435: jlong* _sampled; duke@435: PerfLongSampleHelper* _sample_helper; duke@435: duke@435: PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v, duke@435: jlong initial_value=0) duke@435: : PerfLong(ns, namep, u, v) { duke@435: if (is_valid()) *(jlong*)_valuep = initial_value; duke@435: } duke@435: duke@435: PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v, duke@435: jlong* sampled); duke@435: duke@435: PerfLongVariant(CounterNS ns, const char* namep, Units u, Variability v, duke@435: PerfLongSampleHelper* sample_helper); duke@435: duke@435: void sample(); duke@435: duke@435: public: duke@435: inline void inc() { (*(jlong*)_valuep)++; } duke@435: inline void inc(jlong val) { (*(jlong*)_valuep) += val; } duke@435: inline void add(jlong val) { (*(jlong*)_valuep) += val; } coleenp@4037: void clear_sample_helper() { _sample_helper = NULL; } duke@435: }; duke@435: duke@435: /* duke@435: * The PerfLongCounter class, and its alias PerfCounter, implement duke@435: * a PerfData subtype that holds a jlong data value that can (should) duke@435: * be modified in a monotonic manner. The inc(jlong) and add(jlong) duke@435: * methods can be passed negative values to implement a monotonically duke@435: * decreasing value. However, we rely upon the programmer to honor duke@435: * the notion that this counter always moves in the same direction - duke@435: * either increasing or decreasing. duke@435: */ duke@435: class PerfLongCounter : public PerfLongVariant { duke@435: duke@435: friend class PerfDataManager; // for access to protected constructor duke@435: duke@435: protected: duke@435: duke@435: PerfLongCounter(CounterNS ns, const char* namep, Units u, duke@435: jlong initial_value=0) duke@435: : PerfLongVariant(ns, namep, u, V_Monotonic, duke@435: initial_value) { } duke@435: duke@435: PerfLongCounter(CounterNS ns, const char* namep, Units u, jlong* sampled) duke@435: : PerfLongVariant(ns, namep, u, V_Monotonic, sampled) { } duke@435: duke@435: PerfLongCounter(CounterNS ns, const char* namep, Units u, duke@435: PerfLongSampleHelper* sample_helper) duke@435: : PerfLongVariant(ns, namep, u, V_Monotonic, duke@435: sample_helper) { } duke@435: }; duke@435: duke@435: typedef PerfLongCounter PerfCounter; duke@435: duke@435: /* duke@435: * The PerfLongVariable class, and its alias PerfVariable, implement duke@435: * a PerfData subtype that holds a jlong data value that can duke@435: * be modified in an unrestricted manner. duke@435: */ duke@435: class PerfLongVariable : public PerfLongVariant { duke@435: duke@435: friend class PerfDataManager; // for access to protected constructor duke@435: duke@435: protected: duke@435: duke@435: PerfLongVariable(CounterNS ns, const char* namep, Units u, duke@435: jlong initial_value=0) duke@435: : PerfLongVariant(ns, namep, u, V_Variable, duke@435: initial_value) { } duke@435: duke@435: PerfLongVariable(CounterNS ns, const char* namep, Units u, jlong* sampled) duke@435: : PerfLongVariant(ns, namep, u, V_Variable, sampled) { } duke@435: duke@435: PerfLongVariable(CounterNS ns, const char* namep, Units u, duke@435: PerfLongSampleHelper* sample_helper) duke@435: : PerfLongVariant(ns, namep, u, V_Variable, duke@435: sample_helper) { } duke@435: duke@435: public: duke@435: inline void set_value(jlong val) { (*(jlong*)_valuep) = val; } duke@435: }; duke@435: duke@435: typedef PerfLongVariable PerfVariable; duke@435: duke@435: /* duke@435: * The PerfByteArray provides a PerfData subtype that allows the creation duke@435: * of a contiguous region of the PerfData memory region for storing a vector duke@435: * of bytes. This class is currently intended to be a base class for duke@435: * the PerfString class, and cannot be instantiated directly. duke@435: */ duke@435: class PerfByteArray : public PerfData { duke@435: duke@435: protected: duke@435: jint _length; duke@435: duke@435: PerfByteArray(CounterNS ns, const char* namep, Units u, Variability v, duke@435: jint length); duke@435: }; duke@435: duke@435: class PerfString : public PerfByteArray { duke@435: duke@435: protected: duke@435: duke@435: void set_string(const char* s2); duke@435: duke@435: PerfString(CounterNS ns, const char* namep, Variability v, jint length, duke@435: const char* initial_value) duke@435: : PerfByteArray(ns, namep, U_String, v, length) { duke@435: if (is_valid()) set_string(initial_value); duke@435: } duke@435: duke@435: public: duke@435: duke@435: int format(char* buffer, int length); duke@435: }; duke@435: duke@435: /* duke@435: * The PerfStringConstant class provides a PerfData sub class that duke@435: * allows a null terminated string of single byte characters to be duke@435: * stored in the PerfData memory region. duke@435: */ duke@435: class PerfStringConstant : public PerfString { duke@435: duke@435: friend class PerfDataManager; // for access to protected constructor duke@435: duke@435: private: duke@435: duke@435: // hide sample() - no need to sample constants duke@435: void sample() { } duke@435: duke@435: protected: duke@435: duke@435: // Restrict string constant lengths to be <= PerfMaxStringConstLength. duke@435: // This prevents long string constants, as can occur with very duke@435: // long classpaths or java command lines, from consuming too much duke@435: // PerfData memory. duke@435: PerfStringConstant(CounterNS ns, const char* namep, duke@435: const char* initial_value); duke@435: }; duke@435: duke@435: /* duke@435: * The PerfStringVariable class provides a PerfData sub class that duke@435: * allows a null terminated string of single byte character data duke@435: * to be stored in PerfData memory region. The string value can be reset duke@435: * after initialization. If the string value is >= max_length, then duke@435: * it will be truncated to max_length characters. The copied string duke@435: * is always null terminated. duke@435: */ duke@435: class PerfStringVariable : public PerfString { duke@435: duke@435: friend class PerfDataManager; // for access to protected constructor duke@435: duke@435: protected: duke@435: duke@435: // sampling of string variables are not yet supported duke@435: void sample() { } duke@435: duke@435: PerfStringVariable(CounterNS ns, const char* namep, jint max_length, duke@435: const char* initial_value) duke@435: : PerfString(ns, namep, V_Variable, max_length+1, duke@435: initial_value) { } duke@435: duke@435: public: duke@435: inline void set_value(const char* val) { set_string(val); } duke@435: }; duke@435: duke@435: duke@435: /* duke@435: * The PerfDataList class is a container class for managing lists duke@435: * of PerfData items. The intention of this class is to allow for duke@435: * alternative implementations for management of list of PerfData duke@435: * items without impacting the code that uses the lists. duke@435: * duke@435: * The initial implementation is based upon GrowableArray. Searches duke@435: * on GrowableArray types is linear in nature and this may become duke@435: * a performance issue for creation of PerfData items, particularly duke@435: * from Java code where a test for existence is implemented as a duke@435: * search over all existing PerfData items. duke@435: * duke@435: * The abstraction is not complete. A more general container class duke@435: * would provide an Iterator abstraction that could be used to duke@435: * traverse the lists. This implementation still relys upon integer duke@435: * iterators and the at(int index) method. However, the GrowableArray duke@435: * is not directly visible outside this class and can be replaced by duke@435: * some other implementation, as long as that implementation provides duke@435: * a mechanism to iterate over the container by index. duke@435: */ zgu@3900: class PerfDataList : public CHeapObj { duke@435: duke@435: private: duke@435: duke@435: // GrowableArray implementation duke@435: typedef GrowableArray PerfDataArray; duke@435: duke@435: PerfDataArray* _set; duke@435: duke@435: // method to search for a instrumentation object by name duke@435: static bool by_name(void* name, PerfData* pd); duke@435: duke@435: protected: duke@435: // we expose the implementation here to facilitate the clone duke@435: // method. duke@435: PerfDataArray* get_impl() { return _set; } duke@435: duke@435: public: duke@435: duke@435: // create a PerfDataList with the given initial length duke@435: PerfDataList(int length); duke@435: duke@435: // create a PerfDataList as a shallow copy of the given PerfDataList duke@435: PerfDataList(PerfDataList* p); duke@435: duke@435: ~PerfDataList(); duke@435: duke@435: // return the PerfData item indicated by name, duke@435: // or NULL if it doesn't exist. duke@435: PerfData* find_by_name(const char* name); duke@435: duke@435: // return true if a PerfData item with the name specified in the duke@435: // argument exists, otherwise return false. duke@435: bool contains(const char* name) { return find_by_name(name) != NULL; } duke@435: duke@435: // return the number of PerfData items in this list duke@435: int length() { return _set->length(); } duke@435: duke@435: // add a PerfData item to this list duke@435: void append(PerfData *p) { _set->append(p); } duke@435: duke@435: // remove the given PerfData item from this list. When called duke@435: // while iterating over the list, this method will result in a duke@435: // change in the length of the container. The at(int index) duke@435: // method is also impacted by this method as elements with an duke@435: // index greater than the index of the element removed by this duke@435: // method will be shifted down by one. duke@435: void remove(PerfData *p) { _set->remove(p); } duke@435: duke@435: // create a new PerfDataList from this list. The new list is duke@435: // a shallow copy of the original list and care should be taken duke@435: // with respect to delete operations on the elements of the list duke@435: // as the are likely in use by another copy of the list. duke@435: PerfDataList* clone(); duke@435: duke@435: // for backward compatibility with GrowableArray - need to implement duke@435: // some form of iterator to provide a cleaner abstraction for duke@435: // iteration over the container. duke@435: PerfData* at(int index) { return _set->at(index); } duke@435: }; duke@435: duke@435: duke@435: /* duke@435: * The PerfDataManager class is responsible for creating PerfData duke@435: * subtypes via a set a factory methods and for managing lists duke@435: * of the various PerfData types. duke@435: */ duke@435: class PerfDataManager : AllStatic { duke@435: duke@435: friend class StatSampler; // for access to protected PerfDataList methods duke@435: duke@435: private: duke@435: static PerfDataList* _all; duke@435: static PerfDataList* _sampled; duke@435: static PerfDataList* _constants; duke@435: static const char* _name_spaces[]; duke@435: duke@435: // add a PerfData item to the list(s) of know PerfData objects duke@435: static void add_item(PerfData* p, bool sampled); duke@435: duke@435: protected: duke@435: // return the list of all known PerfData items duke@435: static PerfDataList* all(); duke@435: static int count() { return _all->length(); } duke@435: duke@435: // return the list of all known PerfData items that are to be duke@435: // sampled by the StatSampler. duke@435: static PerfDataList* sampled(); duke@435: static int sampled_count() { return _sampled->length(); } duke@435: duke@435: // return the list of all known PerfData items that have a duke@435: // variability classification of type Constant duke@435: static PerfDataList* constants(); duke@435: static int constants_count() { return _constants->length(); } duke@435: duke@435: public: duke@435: duke@435: // method to check for the existence of a PerfData item with duke@435: // the given name. duke@435: static bool exists(const char* name) { return _all->contains(name); } duke@435: sla@5237: // method to search for a instrumentation object by name sla@5237: static PerfData* find_by_name(const char* name); sla@5237: duke@435: // method to map a CounterNS enumeration to a namespace string duke@435: static const char* ns_to_string(CounterNS ns) { duke@435: return _name_spaces[ns]; duke@435: } duke@435: duke@435: // methods to test the interface stability of a given counter namespace duke@435: // duke@435: static bool is_stable_supported(CounterNS ns) { duke@435: return (ns != NULL_NS) && ((ns % 3) == JAVA_NS); duke@435: } duke@435: static bool is_unstable_supported(CounterNS ns) { duke@435: return (ns != NULL_NS) && ((ns % 3) == COM_NS); duke@435: } duke@435: static bool is_unstable_unsupported(CounterNS ns) { duke@435: return (ns == NULL_NS) || ((ns % 3) == SUN_NS); duke@435: } duke@435: duke@435: // methods to test the interface stability of a given counter name duke@435: // duke@435: static bool is_stable_supported(const char* name) { duke@435: const char* javadot = "java."; duke@435: return strncmp(name, javadot, strlen(javadot)) == 0; duke@435: } duke@435: static bool is_unstable_supported(const char* name) { duke@435: const char* comdot = "com.sun."; duke@435: return strncmp(name, comdot, strlen(comdot)) == 0; duke@435: } duke@435: static bool is_unstable_unsupported(const char* name) { duke@435: return !(is_stable_supported(name) && is_unstable_supported(name)); duke@435: } duke@435: duke@435: // method to construct counter name strings in a given name space. duke@435: // The string object is allocated from the Resource Area and calls duke@435: // to this method must be made within a ResourceMark. duke@435: // duke@435: static char* counter_name(const char* name_space, const char* name); duke@435: duke@435: // method to construct name space strings in a given name space. duke@435: // The string object is allocated from the Resource Area and calls duke@435: // to this method must be made within a ResourceMark. duke@435: // duke@435: static char* name_space(const char* name_space, const char* sub_space) { duke@435: return counter_name(name_space, sub_space); duke@435: } duke@435: duke@435: // same as above, but appends the instance number to the name space duke@435: // duke@435: static char* name_space(const char* name_space, const char* sub_space, duke@435: int instance); duke@435: static char* name_space(const char* name_space, int instance); duke@435: duke@435: duke@435: // these methods provide the general interface for creating duke@435: // performance data resources. The types of performance data duke@435: // resources can be extended by adding additional create duke@435: // methods. duke@435: duke@435: // Constant Types duke@435: static PerfStringConstant* create_string_constant(CounterNS ns, duke@435: const char* name, duke@435: const char *s, TRAPS); duke@435: duke@435: static PerfLongConstant* create_long_constant(CounterNS ns, duke@435: const char* name, duke@435: PerfData::Units u, duke@435: jlong val, TRAPS); duke@435: duke@435: duke@435: // Variable Types duke@435: static PerfStringVariable* create_string_variable(CounterNS ns, duke@435: const char* name, duke@435: int max_length, duke@435: const char *s, TRAPS); duke@435: duke@435: static PerfStringVariable* create_string_variable(CounterNS ns, duke@435: const char* name, duke@435: const char *s, TRAPS) { duke@435: return create_string_variable(ns, name, 0, s, CHECK_NULL); duke@435: }; duke@435: duke@435: static PerfLongVariable* create_long_variable(CounterNS ns, duke@435: const char* name, duke@435: PerfData::Units u, duke@435: jlong ival, TRAPS); duke@435: duke@435: static PerfLongVariable* create_long_variable(CounterNS ns, duke@435: const char* name, duke@435: PerfData::Units u, TRAPS) { duke@435: return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL); duke@435: }; duke@435: duke@435: static PerfLongVariable* create_long_variable(CounterNS, const char* name, duke@435: PerfData::Units u, duke@435: jlong* sp, TRAPS); duke@435: duke@435: static PerfLongVariable* create_long_variable(CounterNS ns, duke@435: const char* name, duke@435: PerfData::Units u, duke@435: PerfLongSampleHelper* sh, duke@435: TRAPS); duke@435: duke@435: duke@435: // Counter Types duke@435: static PerfLongCounter* create_long_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, duke@435: jlong ival, TRAPS); duke@435: duke@435: static PerfLongCounter* create_long_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, TRAPS) { duke@435: return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL); duke@435: }; duke@435: duke@435: static PerfLongCounter* create_long_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong* sp, duke@435: TRAPS); duke@435: duke@435: static PerfLongCounter* create_long_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, duke@435: PerfLongSampleHelper* sh, duke@435: TRAPS); duke@435: duke@435: duke@435: // these creation methods are provided for ease of use. These allow duke@435: // Long performance data types to be created with a shorthand syntax. duke@435: duke@435: static PerfConstant* create_constant(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong val, TRAPS) { duke@435: return create_long_constant(ns, name, u, val, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfVariable* create_variable(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong ival, TRAPS) { duke@435: return create_long_variable(ns, name, u, ival, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfVariable* create_variable(CounterNS ns, const char* name, duke@435: PerfData::Units u, TRAPS) { duke@435: return create_long_variable(ns, name, u, (jlong)0, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfVariable* create_variable(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong* sp, TRAPS) { duke@435: return create_long_variable(ns, name, u, sp, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfVariable* create_variable(CounterNS ns, const char* name, duke@435: PerfData::Units u, duke@435: PerfSampleHelper* sh, TRAPS) { duke@435: return create_long_variable(ns, name, u, sh, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfCounter* create_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong ival, TRAPS) { duke@435: return create_long_counter(ns, name, u, ival, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfCounter* create_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, TRAPS) { duke@435: return create_long_counter(ns, name, u, (jlong)0, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfCounter* create_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, jlong* sp, TRAPS) { duke@435: return create_long_counter(ns, name, u, sp, CHECK_NULL); duke@435: } duke@435: duke@435: static PerfCounter* create_counter(CounterNS ns, const char* name, duke@435: PerfData::Units u, duke@435: PerfSampleHelper* sh, TRAPS) { duke@435: return create_long_counter(ns, name, u, sh, CHECK_NULL); duke@435: } duke@435: duke@435: static void destroy(); duke@435: }; duke@435: duke@435: // Useful macros to create the performance counters duke@435: #define NEWPERFTICKCOUNTER(counter, counter_ns, counter_name) \ duke@435: {counter = PerfDataManager::create_counter(counter_ns, counter_name, \ duke@435: PerfData::U_Ticks,CHECK);} duke@435: duke@435: #define NEWPERFEVENTCOUNTER(counter, counter_ns, counter_name) \ duke@435: {counter = PerfDataManager::create_counter(counter_ns, counter_name, \ duke@435: PerfData::U_Events,CHECK);} duke@435: mchung@1310: #define NEWPERFBYTECOUNTER(counter, counter_ns, counter_name) \ mchung@1310: {counter = PerfDataManager::create_counter(counter_ns, counter_name, \ mchung@1310: PerfData::U_Bytes,CHECK);} mchung@1310: duke@435: // Utility Classes duke@435: duke@435: /* duke@435: * this class will administer a PerfCounter used as a time accumulator duke@435: * for a basic block much like the TraceTime class. duke@435: * duke@435: * Example: duke@435: * duke@435: * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, 0LL, CHECK); duke@435: * duke@435: * { duke@435: * PerfTraceTime ptt(my_time_counter); duke@435: * // perform the operation you want to measure duke@435: * } duke@435: * duke@435: * Note: use of this class does not need to occur within a guarded duke@435: * block. The UsePerfData guard is used with the implementation duke@435: * of this class. duke@435: */ duke@435: class PerfTraceTime : public StackObj { duke@435: duke@435: protected: duke@435: elapsedTimer _t; duke@435: PerfLongCounter* _timerp; duke@435: // pointer to thread-local or global recursion counter variable duke@435: int* _recursion_counter; duke@435: duke@435: public: duke@435: inline PerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp), _recursion_counter(NULL) { duke@435: if (!UsePerfData) return; duke@435: _t.start(); duke@435: } duke@435: duke@435: inline PerfTraceTime(PerfLongCounter* timerp, int* recursion_counter) : _timerp(timerp), _recursion_counter(recursion_counter) { duke@435: if (!UsePerfData || (_recursion_counter != NULL && duke@435: (*_recursion_counter)++ > 0)) return; duke@435: _t.start(); duke@435: } duke@435: duke@435: inline void suspend() { if (!UsePerfData) return; _t.stop(); } duke@435: inline void resume() { if (!UsePerfData) return; _t.start(); } duke@435: duke@435: inline ~PerfTraceTime() { duke@435: if (!UsePerfData || (_recursion_counter != NULL && duke@435: --(*_recursion_counter) > 0)) return; duke@435: _t.stop(); duke@435: _timerp->inc(_t.ticks()); duke@435: } duke@435: }; duke@435: duke@435: /* The PerfTraceTimedEvent class is responsible for counting the duke@435: * occurrence of some event and measuring the the elapsed time of duke@435: * the event in two separate PerfCounter instances. duke@435: * duke@435: * Example: duke@435: * duke@435: * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, CHECK); duke@435: * static PerfCounter* my_event_counter = PerfDataManager::create_counter("my.event.counter", PerfData::U_Events, CHECK); duke@435: * duke@435: * { duke@435: * PerfTraceTimedEvent ptte(my_time_counter, my_event_counter); duke@435: * // perform the operation you want to count and measure duke@435: * } duke@435: * duke@435: * Note: use of this class does not need to occur within a guarded duke@435: * block. The UsePerfData guard is used with the implementation duke@435: * of this class. duke@435: * duke@435: */ duke@435: class PerfTraceTimedEvent : public PerfTraceTime { duke@435: duke@435: protected: duke@435: PerfLongCounter* _eventp; duke@435: duke@435: public: duke@435: inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp): PerfTraceTime(timerp), _eventp(eventp) { duke@435: if (!UsePerfData) return; duke@435: _eventp->inc(); duke@435: } duke@435: duke@435: inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp, int* recursion_counter): PerfTraceTime(timerp, recursion_counter), _eventp(eventp) { duke@435: if (!UsePerfData) return; duke@435: _eventp->inc(); duke@435: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_PERFDATA_HPP