src/hotspot/share/runtime/perfData.cpp
author chagedorn
Wed, 02 Oct 2019 08:27:17 +0200
changeset 58438 1181f58f30e2
parent 58084 cddef3bde924
child 58679 9c3209ff7550
permissions -rw-r--r--
8231626: DeoptimizeRandom should not be a product flag Summary: The DeoptimizeRandom flag is changed to develop since it has no effect in production. Reviewed-by: neliasso, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 52190
diff changeset
     2
 * Copyright (c) 2001, 2019, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/vmSymbols.hpp"
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
    28
#include "logging/log.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 48115
diff changeset
    29
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/os.hpp"
48115
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
    36
#include "runtime/perfData.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "utilities/exceptions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "utilities/globalDefinitions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
PerfDataList*   PerfDataManager::_all = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
PerfDataList*   PerfDataManager::_sampled = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
PerfDataList*   PerfDataManager::_constants = NULL;
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    43
volatile bool   PerfDataManager::_has_PerfData = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
/*
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 18025
diff changeset
    46
 * The jvmstat global and subsystem jvmstat counter name spaces. The top
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 * level name spaces imply the interface stability level of the counter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 * which generally follows the Java package, class, and property naming
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 * conventions. The CounterNS enumeration values should be used to index
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 * into this array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
const char* PerfDataManager::_name_spaces[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // top level name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  "java",                   // stable and supported name space
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  "com.sun",                // unstable but supported name space
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  "sun",                    // unstable and unsupported name space
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // subsystem name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  "java.gc",                // Garbage Collection name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  "com.sun.gc",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  "sun.gc",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  "java.ci",                // Compiler name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  "com.sun.ci",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  "sun.ci",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  "java.cls",               // Class Loader name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  "com.sun.cls",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  "sun.cls",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  "java.rt",                // Runtime name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  "com.sun.rt",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  "sun.rt",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  "java.os",                // Operating System name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  "com.sun.os",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  "sun.os",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  "java.threads",           // Threads System name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  "com.sun.threads",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  "sun.threads",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  "java.property",          // Java Property name spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  "com.sun.property",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  "sun.property",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  "",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
PerfData::PerfData(CounterNS ns, const char* name, Units u, Variability v)
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50080
diff changeset
    83
                  : _name(NULL), _v(v), _u(u), _on_c_heap(false), _valuep(NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  const char* prefix = PerfDataManager::ns_to_string(ns);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    87
  _name = NEW_C_HEAP_ARRAY(char, strlen(name) + strlen(prefix) + 2, mtInternal);
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 52190
diff changeset
    88
  assert(strlen(name) != 0, "invalid name");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if (ns == NULL_NS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
     // No prefix is added to counters with the NULL_NS namespace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
     strcpy(_name, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
     // set the F_Supported flag based on the counter name prefix.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
     if (PerfDataManager::is_stable_supported(_name) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
         PerfDataManager::is_unstable_supported(_name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
       _flags = F_Supported;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
     else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
       _flags = F_None;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    sprintf(_name, "%s.%s", prefix, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // set the F_Supported flag based on the given namespace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (PerfDataManager::is_stable_supported(ns) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        PerfDataManager::is_unstable_supported(ns)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      _flags = F_Supported;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      _flags = F_None;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
PerfData::~PerfData() {
58084
cddef3bde924 8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents: 58083
diff changeset
   116
  FREE_C_HEAP_ARRAY(char, _name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (is_on_c_heap()) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   118
    FREE_C_HEAP_ARRAY(PerfDataEntry, _pdep);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void PerfData::create_entry(BasicType dtype, size_t dsize, size_t vlen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  size_t dlen = vlen==0 ? 1 : vlen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  size_t namelen = strlen(name()) + 1;  // include null terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  size_t size = sizeof(PerfDataEntry) + namelen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  size_t pad_length = ((size % dsize) == 0) ? 0 : dsize - (size % dsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  size += pad_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  size_t data_start = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  size += (dsize * dlen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // align size to assure allocation in units of 8 bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  int align = sizeof(jlong) - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  size = ((size + align) & ~align);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  char* psmp = PerfMemory::alloc(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  if (psmp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    // out of PerfMemory memory resources. allocate on the C heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    // to avoid vm termination.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   141
    psmp = NEW_C_HEAP_ARRAY(char, size, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    _on_c_heap = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // compute the addresses for the name and data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  char* cname = psmp + sizeof(PerfDataEntry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // data is in the last dsize*dlen bytes of the entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void* valuep = (void*) (psmp + data_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  assert(is_on_c_heap() || PerfMemory::contains(cname), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  assert(is_on_c_heap() || PerfMemory::contains((char*)valuep), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // copy the name, including null terminator, into PerfData memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  strcpy(cname, name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // set the header values in PerfData memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  PerfDataEntry* pdep = (PerfDataEntry*)psmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  pdep->entry_length = (jint)size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  pdep->name_offset = (jint) ((uintptr_t) cname - (uintptr_t) psmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  pdep->vector_length = (jint)vlen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  pdep->data_type = (jbyte) type2char(dtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  pdep->data_units = units();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  pdep->data_variability = variability();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  pdep->flags = (jbyte)flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  pdep->data_offset = (jint) data_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   169
  log_debug(perf, datacreation)("name = %s, dtype = %d, variability = %d,"
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   170
                                " units = %d, dsize = " SIZE_FORMAT ", vlen = " SIZE_FORMAT ","
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   171
                                " pad_length = " SIZE_FORMAT ", size = " SIZE_FORMAT ", on_c_heap = %s,"
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   172
                                " address = " INTPTR_FORMAT ","
50080
6fd9fbefd2b4 8202889: Remove trailing LF from perf log
ysuenaga
parents: 49360
diff changeset
   173
                                " data address = " INTPTR_FORMAT,
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   174
                                cname, dtype, variability(),
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   175
                                units(), dsize, vlen,
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   176
                                pad_length, size, is_on_c_heap() ? "TRUE":"FALSE",
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 46334
diff changeset
   177
                                p2i(psmp), p2i(valuep));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // record the start of the entry and the location of the data field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  _pdep = pdep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  _valuep = valuep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // mark the PerfData memory region as having been updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  PerfMemory::mark_updated();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
PerfLong::PerfLong(CounterNS ns, const char* namep, Units u, Variability v)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                 : PerfData(ns, namep, u, v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  create_entry(T_LONG, sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
int PerfLong::format(char* buffer, int length) {
15228
e92acc84ade3 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 13975
diff changeset
   194
  return jio_snprintf(buffer, length, JLONG_FORMAT, *(jlong*)_valuep);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
PerfLongVariant::PerfLongVariant(CounterNS ns, const char* namep, Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                 Variability v, jlong* sampled)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
                                : PerfLong(ns, namep, u, v),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
                                  _sampled(sampled), _sample_helper(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
PerfLongVariant::PerfLongVariant(CounterNS ns, const char* namep, Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                                 Variability v, PerfLongSampleHelper* helper)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                                : PerfLong(ns, namep, u, v),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                                  _sampled(NULL), _sample_helper(helper) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void PerfLongVariant::sample() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (_sample_helper != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    *(jlong*)_valuep = _sample_helper->take_sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
PerfByteArray::PerfByteArray(CounterNS ns, const char* namep, Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                             Variability v, jint length)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
                            : PerfData(ns, namep, u, v), _length(length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  create_entry(T_BYTE, sizeof(jbyte), (size_t)_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
void PerfString::set_string(const char* s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // copy n bytes of the string, assuring the null string is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // copied if s2 == NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  strncpy((char *)_valuep, s2 == NULL ? "" : s2, _length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // assure the string is null terminated when strlen(s2) >= _length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  ((char*)_valuep)[_length-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
int PerfString::format(char* buffer, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  return jio_snprintf(buffer, length, "%s", (char*)_valuep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
PerfStringConstant::PerfStringConstant(CounterNS ns, const char* namep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
                                       const char* initial_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
                     : PerfString(ns, namep, V_Constant,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
                                  initial_value == NULL ? 1 :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
                                  MIN2((jint)(strlen((char*)initial_value)+1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
                                       (jint)(PerfMaxStringConstLength+1)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                                  initial_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  if (PrintMiscellaneous && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (is_valid() && initial_value != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        ((jint)strlen(initial_value) > (jint)PerfMaxStringConstLength)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      warning("Truncating PerfStringConstant: name = %s,"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
              " length = " INT32_FORMAT ","
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
              " PerfMaxStringConstLength = " INT32_FORMAT "\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
              namep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
              (jint)strlen(initial_value),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
              (jint)PerfMaxStringConstLength);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
void PerfDataManager::destroy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (_all == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // destroy already called, or initialization never happened
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   269
  // Clear the flag before we free the PerfData counters. Thus begins
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   270
  // the race between this thread and another thread that has just
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   271
  // queried PerfDataManager::has_PerfData() and gotten back 'true'.
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   272
  // The hope is that the other thread will finish its PerfData
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   273
  // manipulation before we free the memory. The two alternatives are
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   274
  // 1) leak the PerfData memory or 2) do some form of synchronized
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   275
  // access or check before every PerfData operation.
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   276
  _has_PerfData = false;
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   277
  os::naked_short_sleep(1);  // 1ms sleep to let other thread(s) run
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   278
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  for (int index = 0; index < _all->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    PerfData* p = _all->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  delete(_all);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  delete(_sampled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  delete(_constants);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  _all = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  _sampled = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  _constants = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
void PerfDataManager::add_item(PerfData* p, bool sampled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  MutexLocker ml(PerfDataManager_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  if (_all == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    _all = new PerfDataList(100);
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
   299
    _has_PerfData = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  assert(!_all->contains(p->name()), "duplicate name added");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // add to the list of all perf data items
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  _all->append(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (p->variability() == PerfData::V_Constant) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    if (_constants == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      _constants = new PerfDataList(25);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    _constants->append(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  if (sampled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    if (_sampled == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      _sampled = new PerfDataList(25);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    _sampled->append(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15228
diff changeset
   323
PerfData* PerfDataManager::find_by_name(const char* name) {
52190
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   324
  // if add_item hasn't been called the list won't be initialized
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   325
  if (_all != NULL) {
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   326
    return _all->find_by_name(name);
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   327
  } else {
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   328
    return NULL;
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 51334
diff changeset
   329
  }
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15228
diff changeset
   330
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15228
diff changeset
   331
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
PerfDataList* PerfDataManager::all() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  MutexLocker ml(PerfDataManager_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  if (_all == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  PerfDataList* clone = _all->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  return clone;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
PerfDataList* PerfDataManager::sampled() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  MutexLocker ml(PerfDataManager_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  if (_sampled == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  PerfDataList* clone = _sampled->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  return clone;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
PerfDataList* PerfDataManager::constants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  MutexLocker ml(PerfDataManager_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  if (_constants == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  PerfDataList* clone = _constants->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  return clone;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
char* PerfDataManager::counter_name(const char* ns, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
   assert(ns != NULL, "ns string required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
   assert(name != NULL, "name string required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
   size_t len = strlen(ns) + strlen(name) + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
   char* result = NEW_RESOURCE_ARRAY(char, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
   sprintf(result, "%s.%s", ns, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
   return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
char* PerfDataManager::name_space(const char* ns, const char* sub,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                                  int instance) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
   char intbuf[40];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
   jio_snprintf(intbuf, 40, UINT32_FORMAT, instance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
   return name_space(ns, name_space(sub, intbuf));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
char *PerfDataManager::name_space(const char* ns, int instance) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
   char intbuf[40];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
   jio_snprintf(intbuf, 40, UINT32_FORMAT, instance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
   return name_space(ns, intbuf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
PerfStringConstant* PerfDataManager::create_string_constant(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
                                                            const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                                                            const char* s,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                                                            TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  PerfStringConstant* p = new PerfStringConstant(ns, name, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  add_item(p, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
PerfLongConstant* PerfDataManager::create_long_constant(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
                                                        const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
                                                        PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
                                                        jlong val, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  PerfLongConstant* p = new PerfLongConstant(ns, name, u, val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  add_item(p, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
PerfStringVariable* PerfDataManager::create_string_variable(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
                                                            const char* name,
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   426
                                                            int max_length,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                                                            const char* s,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
                                                            TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   430
  if (max_length == 0 && s != NULL) max_length = (int)strlen(s);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  assert(max_length != 0, "PerfStringVariable with length 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  PerfStringVariable* p = new PerfStringVariable(ns, name, max_length, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  add_item(p, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
                                                        const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                                                        PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                                                        jlong ival, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  PerfLongVariable* p = new PerfLongVariable(ns, name, u, ival);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  add_item(p, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
                                                        const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
                                                        PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
                                                        jlong* sp, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Sampled counters not supported if UsePerfData is false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  if (!UsePerfData) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  PerfLongVariable* p = new PerfLongVariable(ns, name, u, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  add_item(p, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
PerfLongVariable* PerfDataManager::create_long_variable(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                                                        const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
                                                        PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
                                                        PerfSampleHelper* sh,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
                                                        TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // Sampled counters not supported if UsePerfData is false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  if (!UsePerfData) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  PerfLongVariable* p = new PerfLongVariable(ns, name, u, sh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  add_item(p, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
                                                      const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
                                                      PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
                                                      jlong ival, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  PerfLongCounter* p = new PerfLongCounter(ns, name, u, ival);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  add_item(p, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
                                                      const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
                                                      PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
                                                      jlong* sp, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  // Sampled counters not supported if UsePerfData is false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  if (!UsePerfData) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  PerfLongCounter* p = new PerfLongCounter(ns, name, u, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  add_item(p, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
PerfLongCounter* PerfDataManager::create_long_counter(CounterNS ns,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
                                                      const char* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
                                                      PerfData::Units u,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
                                                      PerfSampleHelper* sh,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
                                                      TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  // Sampled counters not supported if UsePerfData is false
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  if (!UsePerfData) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  PerfLongCounter* p = new PerfLongCounter(ns, name, u, sh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  if (!p->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    // allocation of native resources failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    delete p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  add_item(p, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
PerfDataList::PerfDataList(int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   571
  _set = new(ResourceObj::C_HEAP, mtInternal) PerfDataArray(length, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
PerfDataList::PerfDataList(PerfDataList* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   576
  _set = new(ResourceObj::C_HEAP, mtInternal) PerfDataArray(p->length(), true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  _set->appendAll(p->get_impl());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
PerfDataList::~PerfDataList() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  delete _set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
bool PerfDataList::by_name(void* name, PerfData* pd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  if (pd == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  return strcmp((const char*)name, pd->name()) == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
PerfData* PerfDataList::find_by_name(const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  int i = _set->find((void*)name, PerfDataList::by_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  if (i >= 0 && i <= _set->length())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    return _set->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
PerfDataList* PerfDataList::clone() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  PerfDataList* copy = new PerfDataList(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  assert(copy != NULL, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  return copy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
}
48115
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   613
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   614
PerfTraceTime::~PerfTraceTime() {
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   615
  if (!UsePerfData || (_recursion_counter != NULL &&
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   616
      --(*_recursion_counter) > 0)) return;
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   617
  _t.stop();
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   618
  _timerp->inc(_t.ticks());
d8ec0640616c 8191860: Add perfData.inline.hpp
stefank
parents: 47765
diff changeset
   619
}