src/hotspot/share/prims/perf.cpp
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47659 a8e9aff89f7b
child 48115 d8ec0640616c
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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"
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
    26
#include "jni.h"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47659
diff changeset
    27
#include "jvm.h"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
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
/*
34928
23cee048ab91 8146736: Move sun.misc performance counters to jdk.internal.perf
chegar
parents: 31592
diff changeset
    37
 *      Implementation of class jdk.internal.perf.Perf
1
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
28618
f9d2242c1874 7076820: assert(addr != 0) failed: address sanity check in PerfMemory::detach with -XX:-UsePerfData
dsamersoff
parents: 22234
diff changeset
   103
  if (!UsePerfData) {
f9d2242c1874 7076820: assert(addr != 0) failed: address sanity check in PerfMemory::detach with -XX:-UsePerfData
dsamersoff
parents: 22234
diff changeset
   104
    // With -XX:-UsePerfData, detach is just a NOP
f9d2242c1874 7076820: assert(addr != 0) failed: address sanity check in PerfMemory::detach with -XX:-UsePerfData
dsamersoff
parents: 22234
diff changeset
   105
    return;
f9d2242c1874 7076820: assert(addr != 0) failed: address sanity check in PerfMemory::detach with -XX:-UsePerfData
dsamersoff
parents: 22234
diff changeset
   106
  }
f9d2242c1874 7076820: assert(addr != 0) failed: address sanity check in PerfMemory::detach with -XX:-UsePerfData
dsamersoff
parents: 22234
diff changeset
   107
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  void* address = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  jlong capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // get buffer address and capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
   ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
   address = env->GetDirectBufferAddress(buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
   capacity = env->GetDirectBufferCapacity(buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  PerfMemory::detach((char*)address, capacity, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
PERF_ENTRY(jobject, Perf_CreateLong(JNIEnv *env, jobject perf, jstring name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
           int variability, int units, jlong value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  PerfWrapper("Perf_CreateLong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  char* name_utf = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  if (units <= 0 || units > PerfData::U_Last) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    debug_only(warning("unexpected units argument, units = %d", units));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    name_utf = jstr_to_utf(env, name, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  PerfLong* pl = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // check that the PerfData name doesn't already exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  if (PerfDataManager::exists(name_utf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfLong name already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  switch(variability) {
17298
7e956b7a3e87 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 7397
diff changeset
   150
  case PerfData::V_Constant:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    pl = PerfDataManager::create_long_constant(NULL_NS, (char *)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
                                               (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                                               CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
17298
7e956b7a3e87 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 7397
diff changeset
   156
  case PerfData::V_Monotonic:
7e956b7a3e87 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 7397
diff changeset
   157
    pl = PerfDataManager::create_long_counter(NULL_NS, (char *)name_utf,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                                               (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                                               CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
17298
7e956b7a3e87 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 7397
diff changeset
   162
  case PerfData::V_Variable:
7e956b7a3e87 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 7397
diff changeset
   163
    pl = PerfDataManager::create_long_variable(NULL_NS, (char *)name_utf,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                                              (PerfData::Units)units, value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                                              CHECK_NULL);
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
  default: /* Illegal Argument */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    debug_only(warning("unexpected variability value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  long* lp = (long*)pl->get_address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return env->NewDirectByteBuffer(lp, sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
PERF_ENTRY(jobject, Perf_CreateByteArray(JNIEnv *env, jobject perf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                                         jstring name, jint variability,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                                         jint units, jbyteArray value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                                         jint maxlength))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  PerfWrapper("Perf_CreateByteArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // check for valid byte array objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  if (name == NULL || value == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    THROW_0(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // check for valid variability classification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (variability != PerfData::V_Constant &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      variability != PerfData::V_Variable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    debug_only(warning("unexpected variability value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // check for valid units
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  if (units != PerfData::U_String) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    // only String based ByteArray objects are currently supported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    debug_only(warning("unexpected units value: %d", variability));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  int value_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  char* name_utf = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  jbyte* value_local = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    name_utf = jstr_to_utf(env, name, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    value_length = env->GetArrayLength(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    value_local = NEW_RESOURCE_ARRAY(jbyte, value_length + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    env->GetByteArrayRegion(value, 0, value_length, value_local);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // check that the counter name doesn't already exist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  if (PerfDataManager::exists((char*)name_utf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfByteArray name already exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  PerfByteArray* pbv = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (units == PerfData::U_String) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    if (variability == PerfData::V_Constant) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      // create the string constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      pbv = PerfDataManager::create_string_constant(NULL_NS, (char*)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
                                                    (char*)value_local,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
                                                    CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      assert(maxlength == value_length, "string constant length should be == maxlength");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      maxlength = value_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      // create the string variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      pbv = PerfDataManager::create_string_variable(NULL_NS, (char*)name_utf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                                                    maxlength,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                                                    (char*)value_local,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                                                    CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
     assert(maxlength >= value_length,"string variable length should be <= maxlength");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  char* cp = (char*)pbv->get_address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    return env->NewDirectByteBuffer(cp, maxlength+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
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_HighResCounter(JNIEnv *env, jobject perf))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  PerfWrapper("Perf_HighResCounter");
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_counter();
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
PERF_ENTRY(jlong, Perf_HighResFrequency(JNIEnv *env, jobject perf))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  PerfWrapper("Perf_HighResFrequency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // this should be a method in java.lang.System. This value could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // be acquired through access to a PerfData performance counter, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // doing so would require that the PerfData monitoring overhead be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // incurred by all Java applications, which is unacceptable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  return os::elapsed_frequency();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
PERF_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
/// JVM_RegisterPerfMethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
#define CC (char*)  /*cast a literal from (const char*)*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
#define BB "Ljava/nio/ByteBuffer;"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#define JLS "Ljava/lang/String;"
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   298
#define CL_ARGS     CC "(" JLS "IIJ)" BB
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   299
#define CBA_ARGS    CC "(" JLS "II[BI)" BB
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
static JNINativeMethod perfmethods[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   303
  {CC "attach",              CC "(" JLS "II)" BB, FN_PTR(Perf_Attach)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   304
  {CC "detach",              CC "(" BB ")V",      FN_PTR(Perf_Detach)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   305
  {CC "createLong",          CL_ARGS,             FN_PTR(Perf_CreateLong)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   306
  {CC "createByteArray",     CBA_ARGS,            FN_PTR(Perf_CreateByteArray)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   307
  {CC "highResCounter",      CC "()J",            FN_PTR(Perf_HighResCounter)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 28618
diff changeset
   308
  {CC "highResFrequency",    CC "()J",            FN_PTR(Perf_HighResFrequency)}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#undef CBA_ARGS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
#undef CL_ARGS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
#undef JLS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
#undef BB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
#undef FN_PTR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
#undef CC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
// This one function is exported, used by NativeLookup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
JVM_ENTRY(void, JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  PerfWrapper("JVM_RegisterPerfMethods");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    ThreadToNativeFromVM ttnfv(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    int ok = env->RegisterNatives(perfclass, perfmethods, sizeof(perfmethods)/sizeof(JNINativeMethod));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    guarantee(ok == 0, "register perf natives");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
JVM_END