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