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