annotate src/share/vm/prims/perf.cpp @ 973:ad6585fd4087

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