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