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