hotspot/src/share/vm/prims/perf.cpp
author nloodin
Thu, 15 Mar 2012 13:37:13 +0100
changeset 12262 fb3b9fede660
parent 7397 5b173b4ca846
child 17298 7e956b7a3e87
permissions -rw-r--r--
7148488: Whitebox tests for the Diagnostic Framework Parser Reviewed-by: brutisso, sla, mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2001, 2010, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "prims/jni.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "prims/jvm.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/interfaceSupport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/perfData.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/perfMemory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
 *      Implementation of class sun.misc.Perf
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
#define PERF_ENTRY(result_type, header) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  JVM_ENTRY(result_type, header)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#define PERF_END JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
#define PerfWrapper(arg) /* Unimplemented at this time */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
static char* jstr_to_utf(JNIEnv *env, jstring str, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  char* utfstr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (str == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    THROW_0(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    //throw_new(env,"NullPointerException");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int len = env->GetStringUTFLength(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int unicode_len = env->GetStringLength(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  utfstr = NEW_RESOURCE_ARRAY(char, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  env->GetStringUTFRegion(str, 0, unicode_len, utfstr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  return utfstr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
PERF_ENTRY(jobject, Perf_Attach(JNIEnv *env, jobject unused, jstring user, int vmid, int mode))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  PerfWrapper("Perf_Attach");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  char* address = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  size_t capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  const char* user_utf = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    user_utf = user == NULL ? NULL : jstr_to_utf(env, user, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (mode != PerfMemory::PERF_MODE_RO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      mode != PerfMemory::PERF_MODE_RW) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // attach to the PerfData memory region for the specified VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  PerfMemory::attach(user_utf, vmid, (PerfMemory::PerfMemoryMode) mode,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                     &address, &capacity, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    return env->NewDirectByteBuffer(address, (jlong)capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
PERF_ENTRY(void, Perf_Detach(JNIEnv *env, jobject unused, jobject buffer))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  PerfWrapper("Perf_Detach");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  void* address = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  jlong capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // get buffer address and capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
   ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
   address = env->GetDirectBufferAddress(buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
   capacity = env->GetDirectBufferCapacity(buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  PerfMemory::detach((char*)address, capacity, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
PERF_ENTRY(jobject, Perf_CreateLong(JNIEnv *env, jobject perf, jstring name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
           int variability, int units, jlong value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  PerfWrapper("Perf_CreateLong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  char* name_utf = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if (units <= 0 || units > PerfData::U_Last) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    debug_only(warning("unexpected units argument, units = %d", units));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    name_utf = jstr_to_utf(env, name, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  PerfLong* pl = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // check that the PerfData name doesn't already exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  if (PerfDataManager::exists(name_utf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfLong name already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  switch(variability) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  case 1:  /* V_Constant */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    pl = PerfDataManager::create_long_constant(NULL_NS, (char *)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                                               (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
                                               CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  case 2:  /* V_Variable */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    pl = PerfDataManager::create_long_variable(NULL_NS, (char *)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                                               (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                                               CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  case 3:  /* V_Monotonic Counter */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    pl = PerfDataManager::create_long_counter(NULL_NS, (char *)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                                              (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
                                              CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  default: /* Illegal Argument */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    debug_only(warning("unexpected variability value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  long* lp = (long*)pl->get_address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    return env->NewDirectByteBuffer(lp, sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
PERF_ENTRY(jobject, Perf_CreateByteArray(JNIEnv *env, jobject perf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
                                         jstring name, jint variability,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                                         jint units, jbyteArray value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                                         jint maxlength))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  PerfWrapper("Perf_CreateByteArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // check for valid byte array objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  if (name == NULL || value == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    THROW_0(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // check for valid variability classification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  if (variability != PerfData::V_Constant &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      variability != PerfData::V_Variable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    debug_only(warning("unexpected variability value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // check for valid units
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  if (units != PerfData::U_String) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    // only String based ByteArray objects are currently supported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    debug_only(warning("unexpected units value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  int value_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  char* name_utf = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  jbyte* value_local = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    name_utf = jstr_to_utf(env, name, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    value_length = env->GetArrayLength(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    value_local = NEW_RESOURCE_ARRAY(jbyte, value_length + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    env->GetByteArrayRegion(value, 0, value_length, value_local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // check that the counter name doesn't already exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  if (PerfDataManager::exists((char*)name_utf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfByteArray name already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  PerfByteArray* pbv = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  if (units == PerfData::U_String) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    if (variability == PerfData::V_Constant) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      // create the string constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      pbv = PerfDataManager::create_string_constant(NULL_NS, (char*)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
                                                    (char*)value_local,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                                                    CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      assert(maxlength == value_length, "string constant length should be == maxlength");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      maxlength = value_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      // create the string variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      pbv = PerfDataManager::create_string_variable(NULL_NS, (char*)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
                                                    maxlength,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
                                                    (char*)value_local,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                                                    CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
     assert(maxlength >= value_length,"string variable length should be <= maxlength");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  char* cp = (char*)pbv->get_address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    return env->NewDirectByteBuffer(cp, maxlength+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
PERF_ENTRY(jlong, Perf_HighResCounter(JNIEnv *env, jobject perf))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  PerfWrapper("Perf_HighResCounter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // this should be a method in java.lang.System. This value could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // be acquired through access to a PerfData performance counter, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // doing so would require that the PerfData monitoring overhead be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // incurred by all Java applications, which is unacceptable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  return os::elapsed_counter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
PERF_ENTRY(jlong, Perf_HighResFrequency(JNIEnv *env, jobject perf))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  PerfWrapper("Perf_HighResFrequency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  // this should be a method in java.lang.System. This value could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // be acquired through access to a PerfData performance counter, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // doing so would require that the PerfData monitoring overhead be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // incurred by all Java applications, which is unacceptable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  return os::elapsed_frequency();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
/// JVM_RegisterPerfMethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
#define CC (char*)  /*cast a literal from (const char*)*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
#define BB "Ljava/nio/ByteBuffer;"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
#define JLS "Ljava/lang/String;"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#define CL_ARGS     CC"("JLS"IIJ)"BB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
#define CBA_ARGS    CC"("JLS"II[BI)"BB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
static JNINativeMethod perfmethods[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  {CC"attach",              CC"("JLS"II)"BB,  FN_PTR(Perf_Attach)},
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  {CC"detach",              CC"("BB")V",      FN_PTR(Perf_Detach)},
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  {CC"createLong",          CL_ARGS,          FN_PTR(Perf_CreateLong)},
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  {CC"createByteArray",     CBA_ARGS,         FN_PTR(Perf_CreateByteArray)},
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  {CC"highResCounter",      CC"()J",          FN_PTR(Perf_HighResCounter)},
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  {CC"highResFrequency",    CC"()J",          FN_PTR(Perf_HighResFrequency)}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
#undef CBA_ARGS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
#undef CL_ARGS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
#undef JLS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
#undef BB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
#undef FN_PTR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#undef CC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
// This one function is exported, used by NativeLookup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
JVM_ENTRY(void, JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  PerfWrapper("JVM_RegisterPerfMethods");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    int ok = env->RegisterNatives(perfclass, perfmethods, sizeof(perfmethods)/sizeof(JNINativeMethod));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    guarantee(ok == 0, "register perf natives");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
JVM_END