annotate src/share/vm/prims/perf.cpp @ 10217:bf089b838c9e

8012641: Perf_CreateLong creates perf counter of incorrect type Reviewed-by: mchung, hseigel, coleenp
author ccheung
date Thu, 02 May 2013 16:55:00 -0700
parents f95d63e2154a
children de6a9e811145
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/vmSymbols.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "prims/jni.h"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "prims/jvm.h"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/interfaceSupport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/perfData.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "runtime/perfMemory.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * Implementation of class sun.misc.Perf
a61af66fc99e Initial load
duke
parents:
diff changeset
38 */
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #define PERF_ENTRY(result_type, header) \
a61af66fc99e Initial load
duke
parents:
diff changeset
42 JVM_ENTRY(result_type, header)
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #define PERF_END JVM_END
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #define PerfWrapper(arg) /* Unimplemented at this time */
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 static char* jstr_to_utf(JNIEnv *env, jstring str, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 char* utfstr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (str == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 THROW_0(vmSymbols::java_lang_NullPointerException());
a61af66fc99e Initial load
duke
parents:
diff changeset
54 //throw_new(env,"NullPointerException");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int len = env->GetStringUTFLength(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 int unicode_len = env->GetStringLength(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 utfstr = NEW_RESOURCE_ARRAY(char, len + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 env->GetStringUTFRegion(str, 0, unicode_len, utfstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return utfstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 PERF_ENTRY(jobject, Perf_Attach(JNIEnv *env, jobject unused, jstring user, int vmid, int mode))
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 PerfWrapper("Perf_Attach");
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 char* address = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 size_t capacity = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 const char* user_utf = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 user_utf = user == NULL ? NULL : jstr_to_utf(env, user, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (mode != PerfMemory::PERF_MODE_RO &&
a61af66fc99e Initial load
duke
parents:
diff changeset
84 mode != PerfMemory::PERF_MODE_RW) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 THROW_0(vmSymbols::java_lang_IllegalArgumentException());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // attach to the PerfData memory region for the specified VM
a61af66fc99e Initial load
duke
parents:
diff changeset
89 PerfMemory::attach(user_utf, vmid, (PerfMemory::PerfMemoryMode) mode,
a61af66fc99e Initial load
duke
parents:
diff changeset
90 &address, &capacity, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return env->NewDirectByteBuffer(address, (jlong)capacity);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 PERF_ENTRY(void, Perf_Detach(JNIEnv *env, jobject unused, jobject buffer))
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 PerfWrapper("Perf_Detach");
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void* address = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 jlong capacity = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // get buffer address and capacity
a61af66fc99e Initial load
duke
parents:
diff changeset
107 {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 address = env->GetDirectBufferAddress(buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 capacity = env->GetDirectBufferCapacity(buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 PerfMemory::detach((char*)address, capacity, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 PERF_ENTRY(jobject, Perf_CreateLong(JNIEnv *env, jobject perf, jstring name,
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int variability, int units, jlong value))
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 PerfWrapper("Perf_CreateLong");
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 char* name_utf = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (units <= 0 || units > PerfData::U_Last) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 debug_only(warning("unexpected units argument, units = %d", units));
a61af66fc99e Initial load
duke
parents:
diff changeset
126 THROW_0(vmSymbols::java_lang_IllegalArgumentException());
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 name_utf = jstr_to_utf(env, name, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 PerfLong* pl = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // check that the PerfData name doesn't already exist
a61af66fc99e Initial load
duke
parents:
diff changeset
140 if (PerfDataManager::exists(name_utf)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfLong name already exists");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 switch(variability) {
10217
bf089b838c9e 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 1972
diff changeset
145 case PerfData::V_Constant:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 pl = PerfDataManager::create_long_constant(NULL_NS, (char *)name_utf,
a61af66fc99e Initial load
duke
parents:
diff changeset
147 (PerfData::Units)units, value,
a61af66fc99e Initial load
duke
parents:
diff changeset
148 CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
150
10217
bf089b838c9e 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 1972
diff changeset
151 case PerfData::V_Monotonic:
bf089b838c9e 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 1972
diff changeset
152 pl = PerfDataManager::create_long_counter(NULL_NS, (char *)name_utf,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
153 (PerfData::Units)units, value,
a61af66fc99e Initial load
duke
parents:
diff changeset
154 CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
156
10217
bf089b838c9e 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 1972
diff changeset
157 case PerfData::V_Variable:
bf089b838c9e 8012641: Perf_CreateLong creates perf counter of incorrect type
ccheung
parents: 1972
diff changeset
158 pl = PerfDataManager::create_long_variable(NULL_NS, (char *)name_utf,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
159 (PerfData::Units)units, value,
a61af66fc99e Initial load
duke
parents:
diff changeset
160 CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 default: /* Illegal Argument */
a61af66fc99e Initial load
duke
parents:
diff changeset
164 debug_only(warning("unexpected variability value: %d", variability));
a61af66fc99e Initial load
duke
parents:
diff changeset
165 THROW_0(vmSymbols::java_lang_IllegalArgumentException());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 long* lp = (long*)pl->get_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 return env->NewDirectByteBuffer(lp, sizeof(jlong));
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 PERF_ENTRY(jobject, Perf_CreateByteArray(JNIEnv *env, jobject perf,
a61af66fc99e Initial load
duke
parents:
diff changeset
179 jstring name, jint variability,
a61af66fc99e Initial load
duke
parents:
diff changeset
180 jint units, jbyteArray value,
a61af66fc99e Initial load
duke
parents:
diff changeset
181 jint maxlength))
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 PerfWrapper("Perf_CreateByteArray");
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // check for valid byte array objects
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (name == NULL || value == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 THROW_0(vmSymbols::java_lang_NullPointerException());
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // check for valid variability classification
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (variability != PerfData::V_Constant &&
a61af66fc99e Initial load
duke
parents:
diff changeset
192 variability != PerfData::V_Variable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 debug_only(warning("unexpected variability value: %d", variability));
a61af66fc99e Initial load
duke
parents:
diff changeset
194 THROW_0(vmSymbols::java_lang_IllegalArgumentException());
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // check for valid units
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (units != PerfData::U_String) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // only String based ByteArray objects are currently supported
a61af66fc99e Initial load
duke
parents:
diff changeset
200 debug_only(warning("unexpected units value: %d", variability));
a61af66fc99e Initial load
duke
parents:
diff changeset
201 THROW_0(vmSymbols::java_lang_IllegalArgumentException());
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 int value_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 char* name_utf = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 jbyte* value_local = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 name_utf = jstr_to_utf(env, name, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 value_length = env->GetArrayLength(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 value_local = NEW_RESOURCE_ARRAY(jbyte, value_length + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 env->GetByteArrayRegion(value, 0, value_length, value_local);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // check that the counter name doesn't already exist
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (PerfDataManager::exists((char*)name_utf)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "PerfByteArray name already exists");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 PerfByteArray* pbv = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (units == PerfData::U_String) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 if (variability == PerfData::V_Constant) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // create the string constant
a61af66fc99e Initial load
duke
parents:
diff changeset
233 pbv = PerfDataManager::create_string_constant(NULL_NS, (char*)name_utf,
a61af66fc99e Initial load
duke
parents:
diff changeset
234 (char*)value_local,
a61af66fc99e Initial load
duke
parents:
diff changeset
235 CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 assert(maxlength == value_length, "string constant length should be == maxlength");
a61af66fc99e Initial load
duke
parents:
diff changeset
238 maxlength = value_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // create the string variable
a61af66fc99e Initial load
duke
parents:
diff changeset
243 pbv = PerfDataManager::create_string_variable(NULL_NS, (char*)name_utf,
a61af66fc99e Initial load
duke
parents:
diff changeset
244 maxlength,
a61af66fc99e Initial load
duke
parents:
diff changeset
245 (char*)value_local,
a61af66fc99e Initial load
duke
parents:
diff changeset
246 CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 assert(maxlength >= value_length,"string variable length should be <= maxlength");
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 char* cp = (char*)pbv->get_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return env->NewDirectByteBuffer(cp, maxlength+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 PERF_ENTRY(jlong, Perf_HighResCounter(JNIEnv *env, jobject perf))
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 PerfWrapper("Perf_HighResCounter");
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // this should be a method in java.lang.System. This value could
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // be acquired through access to a PerfData performance counter, but
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // doing so would require that the PerfData monitoring overhead be
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // incurred by all Java applications, which is unacceptable.
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return os::elapsed_counter();
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 PERF_ENTRY(jlong, Perf_HighResFrequency(JNIEnv *env, jobject perf))
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 PerfWrapper("Perf_HighResFrequency");
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // this should be a method in java.lang.System. This value could
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // be acquired through access to a PerfData performance counter, but
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // doing so would require that the PerfData monitoring overhead be
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // incurred by all Java applications, which is unacceptable.
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return os::elapsed_frequency();
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 PERF_END
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 /// JVM_RegisterPerfMethods
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 #define CC (char*) /*cast a literal from (const char*)*/
a61af66fc99e Initial load
duke
parents:
diff changeset
290 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
a61af66fc99e Initial load
duke
parents:
diff changeset
291 #define BB "Ljava/nio/ByteBuffer;"
a61af66fc99e Initial load
duke
parents:
diff changeset
292 #define JLS "Ljava/lang/String;"
a61af66fc99e Initial load
duke
parents:
diff changeset
293 #define CL_ARGS CC"("JLS"IIJ)"BB
a61af66fc99e Initial load
duke
parents:
diff changeset
294 #define CBA_ARGS CC"("JLS"II[BI)"BB
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 static JNINativeMethod perfmethods[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 {CC"attach", CC"("JLS"II)"BB, FN_PTR(Perf_Attach)},
a61af66fc99e Initial load
duke
parents:
diff changeset
299 {CC"detach", CC"("BB")V", FN_PTR(Perf_Detach)},
a61af66fc99e Initial load
duke
parents:
diff changeset
300 {CC"createLong", CL_ARGS, FN_PTR(Perf_CreateLong)},
a61af66fc99e Initial load
duke
parents:
diff changeset
301 {CC"createByteArray", CBA_ARGS, FN_PTR(Perf_CreateByteArray)},
a61af66fc99e Initial load
duke
parents:
diff changeset
302 {CC"highResCounter", CC"()J", FN_PTR(Perf_HighResCounter)},
a61af66fc99e Initial load
duke
parents:
diff changeset
303 {CC"highResFrequency", CC"()J", FN_PTR(Perf_HighResFrequency)}
a61af66fc99e Initial load
duke
parents:
diff changeset
304 };
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 #undef CBA_ARGS
a61af66fc99e Initial load
duke
parents:
diff changeset
307 #undef CL_ARGS
a61af66fc99e Initial load
duke
parents:
diff changeset
308 #undef JLS
a61af66fc99e Initial load
duke
parents:
diff changeset
309 #undef BB
a61af66fc99e Initial load
duke
parents:
diff changeset
310 #undef FN_PTR
a61af66fc99e Initial load
duke
parents:
diff changeset
311 #undef CC
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // This one function is exported, used by NativeLookup.
a61af66fc99e Initial load
duke
parents:
diff changeset
314 JVM_ENTRY(void, JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass))
a61af66fc99e Initial load
duke
parents:
diff changeset
315 PerfWrapper("JVM_RegisterPerfMethods");
a61af66fc99e Initial load
duke
parents:
diff changeset
316 {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 ThreadToNativeFromVM ttnfv(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 int ok = env->RegisterNatives(perfclass, perfmethods, sizeof(perfmethods)/sizeof(JNINativeMethod));
a61af66fc99e Initial load
duke
parents:
diff changeset
319 guarantee(ok == 0, "register perf natives");
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 JVM_END