1
|
1 |
/*
|
|
2 |
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
# include "incls/_precompiled.incl"
|
|
26 |
# include "incls/_vmSymbols.cpp.incl"
|
|
27 |
|
|
28 |
|
|
29 |
symbolOop vmSymbols::_symbols[vmSymbols::SID_LIMIT];
|
|
30 |
|
|
31 |
symbolOop vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
|
|
32 |
|
|
33 |
inline int compare_symbol(symbolOop a, symbolOop b) {
|
|
34 |
if (a == b) return 0;
|
|
35 |
// follow the natural address order:
|
|
36 |
return (address)a > (address)b ? +1 : -1;
|
|
37 |
}
|
|
38 |
|
|
39 |
static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
|
|
40 |
extern "C" {
|
|
41 |
static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
|
|
42 |
symbolOop a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
|
|
43 |
symbolOop b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
|
|
44 |
return compare_symbol(a, b);
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
#ifndef PRODUCT
|
|
49 |
#define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
|
|
50 |
static const char* vm_symbol_enum_names =
|
|
51 |
VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
|
|
52 |
"\0";
|
|
53 |
static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
|
|
54 |
const char* string = &vm_symbol_enum_names[0];
|
|
55 |
int skip = (int)sid - (int)vmSymbols::FIRST_SID;
|
|
56 |
for (; skip != 0; skip--) {
|
|
57 |
size_t skiplen = strlen(string);
|
|
58 |
if (skiplen == 0) return "<unknown>"; // overflow
|
|
59 |
string += skiplen+1;
|
|
60 |
}
|
|
61 |
return string;
|
|
62 |
}
|
|
63 |
#endif //PRODUCT
|
|
64 |
|
|
65 |
// Put all the VM symbol strings in one place.
|
|
66 |
// Makes for a more compact libjvm.
|
|
67 |
#define VM_SYMBOL_BODY(name, string) string "\0"
|
|
68 |
static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE);
|
|
69 |
|
|
70 |
void vmSymbols::initialize(TRAPS) {
|
|
71 |
assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield");
|
|
72 |
assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please");
|
|
73 |
|
|
74 |
if (!UseSharedSpaces) {
|
|
75 |
const char* string = &vm_symbol_bodies[0];
|
|
76 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
77 |
symbolOop sym = oopFactory::new_symbol(string, CHECK);
|
|
78 |
_symbols[index] = sym;
|
|
79 |
string += strlen(string); // skip string body
|
|
80 |
string += 1; // skip trailing null
|
|
81 |
}
|
|
82 |
|
|
83 |
_type_signatures[T_BYTE] = byte_signature();
|
|
84 |
_type_signatures[T_CHAR] = char_signature();
|
|
85 |
_type_signatures[T_DOUBLE] = double_signature();
|
|
86 |
_type_signatures[T_FLOAT] = float_signature();
|
|
87 |
_type_signatures[T_INT] = int_signature();
|
|
88 |
_type_signatures[T_LONG] = long_signature();
|
|
89 |
_type_signatures[T_SHORT] = short_signature();
|
|
90 |
_type_signatures[T_BOOLEAN] = bool_signature();
|
|
91 |
_type_signatures[T_VOID] = void_signature();
|
|
92 |
// no single signatures for T_OBJECT or T_ARRAY
|
|
93 |
}
|
|
94 |
|
|
95 |
#ifdef ASSERT
|
|
96 |
// Check for duplicates:
|
|
97 |
for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
|
|
98 |
symbolOop sym = symbol_at((SID)i1);
|
|
99 |
for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
|
|
100 |
if (symbol_at((SID)i2) == sym) {
|
|
101 |
tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
|
|
102 |
vm_symbol_enum_name((SID)i2), i2,
|
|
103 |
vm_symbol_enum_name((SID)i1), i1);
|
|
104 |
sym->print_symbol_on(tty);
|
|
105 |
tty->print_cr("\"");
|
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|
|
109 |
#endif //ASSERT
|
|
110 |
|
|
111 |
// Create an index for find_id:
|
|
112 |
{
|
|
113 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
114 |
vm_symbol_index[index] = (SID)index;
|
|
115 |
}
|
|
116 |
int num_sids = SID_LIMIT-FIRST_SID;
|
|
117 |
qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
|
|
118 |
compare_vmsymbol_sid);
|
|
119 |
}
|
|
120 |
|
|
121 |
#ifdef ASSERT
|
|
122 |
{
|
|
123 |
// Spot-check correspondence between strings, symbols, and enums:
|
|
124 |
assert(_symbols[NO_SID] == NULL, "must be");
|
|
125 |
const char* str = "java/lang/Object";
|
|
126 |
symbolOop sym = oopFactory::new_symbol(str, CHECK);
|
|
127 |
assert(strcmp(str, (char*)sym->base()) == 0, "");
|
|
128 |
assert(sym == java_lang_Object(), "");
|
|
129 |
SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object);
|
|
130 |
assert(find_sid(sym) == sid, "");
|
|
131 |
assert(symbol_at(sid) == sym, "");
|
|
132 |
|
|
133 |
// Make sure find_sid produces the right answer in each case.
|
|
134 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
135 |
sym = symbol_at((SID)index);
|
|
136 |
sid = find_sid(sym);
|
|
137 |
assert(sid == (SID)index, "symbol index works");
|
|
138 |
// Note: If there are duplicates, this assert will fail.
|
|
139 |
// A "Duplicate VM symbol" message will have already been printed.
|
|
140 |
}
|
|
141 |
|
|
142 |
// The string "format" happens (at the moment) not to be a vmSymbol,
|
|
143 |
// though it is a method name in java.lang.String.
|
|
144 |
str = "format";
|
|
145 |
sym = oopFactory::new_symbol(str, CHECK);
|
|
146 |
sid = find_sid(sym);
|
|
147 |
assert(sid == NO_SID, "symbol index works (negative test)");
|
|
148 |
}
|
|
149 |
#endif
|
|
150 |
}
|
|
151 |
|
|
152 |
|
|
153 |
#ifndef PRODUCT
|
|
154 |
const char* vmSymbols::name_for(vmSymbols::SID sid) {
|
|
155 |
if (sid == NO_SID)
|
|
156 |
return "NO_SID";
|
|
157 |
const char* string = &vm_symbol_bodies[0];
|
|
158 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
159 |
if (index == (int)sid)
|
|
160 |
return string;
|
|
161 |
string += strlen(string); // skip string body
|
|
162 |
string += 1; // skip trailing null
|
|
163 |
}
|
|
164 |
return "BAD_SID";
|
|
165 |
}
|
|
166 |
#endif
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
void vmSymbols::oops_do(OopClosure* f, bool do_all) {
|
|
171 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
172 |
f->do_oop((oop*) &_symbols[index]);
|
|
173 |
}
|
|
174 |
for (int i = 0; i < T_VOID+1; i++) {
|
|
175 |
if (_type_signatures[i] != NULL) {
|
|
176 |
assert(i >= T_BOOLEAN, "checking");
|
|
177 |
f->do_oop((oop*)&_type_signatures[i]);
|
|
178 |
} else if (do_all) {
|
|
179 |
f->do_oop((oop*)&_type_signatures[i]);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
|
|
185 |
BasicType vmSymbols::signature_type(symbolOop s) {
|
|
186 |
assert(s != NULL, "checking");
|
|
187 |
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
|
|
188 |
if (s == _type_signatures[i]) {
|
|
189 |
return (BasicType)i;
|
|
190 |
}
|
|
191 |
}
|
|
192 |
return T_OBJECT;
|
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
static int mid_hint = (int)vmSymbols::FIRST_SID+1;
|
|
197 |
|
|
198 |
#ifndef PRODUCT
|
|
199 |
static int find_sid_calls, find_sid_probes;
|
|
200 |
// (Typical counts are calls=7000 and probes=17000.)
|
|
201 |
#endif
|
|
202 |
|
|
203 |
vmSymbols::SID vmSymbols::find_sid(symbolOop symbol) {
|
|
204 |
// Handle the majority of misses by a bounds check.
|
|
205 |
// Then, use a binary search over the index.
|
|
206 |
// Expected trip count is less than log2_SID_LIMIT, about eight.
|
|
207 |
// This is slow but acceptable, given that calls are not
|
|
208 |
// dynamically common. (methodOop::intrinsic_id has a cache.)
|
|
209 |
NOT_PRODUCT(find_sid_calls++);
|
|
210 |
int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1;
|
|
211 |
SID sid = NO_SID, sid1;
|
|
212 |
int cmp1;
|
|
213 |
sid1 = vm_symbol_index[min];
|
|
214 |
cmp1 = compare_symbol(symbol, symbol_at(sid1));
|
|
215 |
if (cmp1 <= 0) { // before the first
|
|
216 |
if (cmp1 == 0) sid = sid1;
|
|
217 |
} else {
|
|
218 |
sid1 = vm_symbol_index[max];
|
|
219 |
cmp1 = compare_symbol(symbol, symbol_at(sid1));
|
|
220 |
if (cmp1 >= 0) { // after the last
|
|
221 |
if (cmp1 == 0) sid = sid1;
|
|
222 |
} else {
|
|
223 |
// After checking the extremes, do a binary search.
|
|
224 |
++min; --max; // endpoints are done
|
|
225 |
int mid = mid_hint; // start at previous success
|
|
226 |
while (max >= min) {
|
|
227 |
assert(mid >= min && mid <= max, "");
|
|
228 |
NOT_PRODUCT(find_sid_probes++);
|
|
229 |
sid1 = vm_symbol_index[mid];
|
|
230 |
cmp1 = compare_symbol(symbol, symbol_at(sid1));
|
|
231 |
if (cmp1 == 0) {
|
|
232 |
mid_hint = mid;
|
|
233 |
sid = sid1;
|
|
234 |
break;
|
|
235 |
}
|
|
236 |
if (cmp1 < 0)
|
|
237 |
max = mid - 1; // symbol < symbol_at(sid)
|
|
238 |
else
|
|
239 |
min = mid + 1;
|
|
240 |
|
|
241 |
// Pick a new probe point:
|
|
242 |
mid = (max + min) / 2;
|
|
243 |
}
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
#ifdef ASSERT
|
|
248 |
// Perform the exhaustive self-check the first 1000 calls,
|
|
249 |
// and every 100 calls thereafter.
|
|
250 |
static int find_sid_check_count = -2000;
|
|
251 |
if ((uint)++find_sid_check_count > (uint)100) {
|
|
252 |
if (find_sid_check_count > 0) find_sid_check_count = 0;
|
|
253 |
|
|
254 |
// Make sure this is the right answer, using linear search.
|
|
255 |
// (We have already proven that there are no duplicates in the list.)
|
|
256 |
SID sid2 = NO_SID;
|
|
257 |
for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
|
|
258 |
symbolOop sym2 = symbol_at((SID)index);
|
|
259 |
if (sym2 == symbol) {
|
|
260 |
sid2 = (SID)index;
|
|
261 |
break;
|
|
262 |
}
|
|
263 |
}
|
|
264 |
// Unless it's a duplicate, assert that the sids are the same.
|
|
265 |
if (_symbols[sid] != _symbols[sid2]) {
|
|
266 |
assert(sid == sid2, "binary same as linear search");
|
|
267 |
}
|
|
268 |
}
|
|
269 |
#endif //ASSERT
|
|
270 |
|
|
271 |
return sid;
|
|
272 |
}
|
|
273 |
|
|
274 |
|
|
275 |
#define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0"
|
|
276 |
static const char* vm_intrinsic_name_bodies =
|
|
277 |
VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE,
|
|
278 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
279 |
|
|
280 |
static const char* vm_intrinsic_name_table[vmIntrinsics::ID_LIMIT];
|
|
281 |
|
|
282 |
const char* vmIntrinsics::name_at(vmIntrinsics::ID id) {
|
|
283 |
const char** nt = &vm_intrinsic_name_table[0];
|
|
284 |
if (nt[_none] == NULL) {
|
|
285 |
char* string = (char*) &vm_intrinsic_name_bodies[0];
|
|
286 |
for (int index = FIRST_ID; index < ID_LIMIT; index++) {
|
|
287 |
nt[index] = string;
|
|
288 |
string += strlen(string); // skip string body
|
|
289 |
string += 1; // skip trailing null
|
|
290 |
}
|
|
291 |
assert(!strcmp(nt[_hashCode], "_hashCode"), "lined up");
|
|
292 |
nt[_none] = "_none";
|
|
293 |
}
|
|
294 |
if ((uint)id < (uint)ID_LIMIT)
|
|
295 |
return vm_intrinsic_name_table[(uint)id];
|
|
296 |
else
|
|
297 |
return "(unknown intrinsic)";
|
|
298 |
}
|
|
299 |
|
|
300 |
// These are flag-matching functions:
|
|
301 |
inline bool match_F_R(jshort flags) {
|
|
302 |
const int req = 0;
|
|
303 |
const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
|
|
304 |
return (flags & (req | neg)) == req;
|
|
305 |
}
|
|
306 |
inline bool match_F_RN(jshort flags) {
|
|
307 |
const int req = JVM_ACC_NATIVE;
|
|
308 |
const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
|
|
309 |
return (flags & (req | neg)) == req;
|
|
310 |
}
|
|
311 |
inline bool match_F_S(jshort flags) {
|
|
312 |
const int req = JVM_ACC_STATIC;
|
|
313 |
const int neg = JVM_ACC_SYNCHRONIZED;
|
|
314 |
return (flags & (req | neg)) == req;
|
|
315 |
}
|
|
316 |
inline bool match_F_SN(jshort flags) {
|
|
317 |
const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE;
|
|
318 |
const int neg = JVM_ACC_SYNCHRONIZED;
|
|
319 |
return (flags & (req | neg)) == req;
|
|
320 |
}
|
|
321 |
|
|
322 |
// These are for forming case labels:
|
|
323 |
#define ID3(x, y, z) (( jint)(z) + \
|
|
324 |
((jint)(y) << vmSymbols::log2_SID_LIMIT) + \
|
|
325 |
((jint)(x) << (2*vmSymbols::log2_SID_LIMIT)) )
|
|
326 |
#define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n)
|
|
327 |
|
|
328 |
vmIntrinsics::ID vmIntrinsics::find_id(vmSymbols::SID holder,
|
|
329 |
vmSymbols::SID name,
|
|
330 |
vmSymbols::SID sig,
|
|
331 |
jshort flags) {
|
|
332 |
assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit");
|
|
333 |
|
|
334 |
// Let the C compiler build the decision tree.
|
|
335 |
|
|
336 |
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
|
|
337 |
case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \
|
|
338 |
if (!match_##fcode(flags)) break; \
|
|
339 |
return id;
|
|
340 |
|
|
341 |
switch (ID3(holder, name, sig)) {
|
|
342 |
VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
|
|
343 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
344 |
}
|
|
345 |
return vmIntrinsics::_none;
|
|
346 |
|
|
347 |
#undef VM_INTRINSIC_CASE
|
|
348 |
}
|
|
349 |
|
|
350 |
|
|
351 |
const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) {
|
|
352 |
const char* str = name_at(id);
|
|
353 |
#ifndef PRODUCT
|
|
354 |
const char* kname = vmSymbols::name_for(class_for(id));
|
|
355 |
const char* mname = vmSymbols::name_for(name_for(id));
|
|
356 |
const char* sname = vmSymbols::name_for(signature_for(id));
|
|
357 |
const char* fname = "";
|
|
358 |
switch (flags_for(id)) {
|
|
359 |
case F_RN: fname = "native "; break;
|
|
360 |
case F_SN: fname = "native static "; break;
|
|
361 |
case F_S: fname = "static "; break;
|
|
362 |
}
|
|
363 |
const char* kptr = strrchr(kname, '/');
|
|
364 |
if (kptr != NULL) kname = kptr + 1;
|
|
365 |
int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s",
|
|
366 |
str, fname, kname, mname, sname);
|
|
367 |
if (len < buflen)
|
|
368 |
str = buf;
|
|
369 |
#endif //PRODUCT
|
|
370 |
return str;
|
|
371 |
}
|
|
372 |
|
|
373 |
|
|
374 |
// These are for friendly printouts of intrinsics:
|
|
375 |
|
|
376 |
vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) {
|
|
377 |
#ifndef PRODUCT
|
|
378 |
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
|
|
379 |
case id: return SID_ENUM(klass);
|
|
380 |
|
|
381 |
switch (id) {
|
|
382 |
VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
|
|
383 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
384 |
}
|
|
385 |
#undef VM_INTRINSIC_CASE
|
|
386 |
#endif //PRODUCT
|
|
387 |
return vmSymbols::NO_SID;
|
|
388 |
}
|
|
389 |
|
|
390 |
vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) {
|
|
391 |
#ifndef PRODUCT
|
|
392 |
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
|
|
393 |
case id: return SID_ENUM(name);
|
|
394 |
|
|
395 |
switch (id) {
|
|
396 |
VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
|
|
397 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
398 |
}
|
|
399 |
#undef VM_INTRINSIC_CASE
|
|
400 |
#endif //PRODUCT
|
|
401 |
return vmSymbols::NO_SID;
|
|
402 |
}
|
|
403 |
|
|
404 |
vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
|
|
405 |
#ifndef PRODUCT
|
|
406 |
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
|
|
407 |
case id: return SID_ENUM(sig);
|
|
408 |
|
|
409 |
switch (id) {
|
|
410 |
VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
|
|
411 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
412 |
}
|
|
413 |
#undef VM_INTRINSIC_CASE
|
|
414 |
#endif //PRODUCT
|
|
415 |
return vmSymbols::NO_SID;
|
|
416 |
}
|
|
417 |
|
|
418 |
vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
|
|
419 |
#ifndef PRODUCT
|
|
420 |
#define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
|
|
421 |
case id: return fcode;
|
|
422 |
|
|
423 |
switch (id) {
|
|
424 |
VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
|
|
425 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
426 |
}
|
|
427 |
#undef VM_INTRINSIC_CASE
|
|
428 |
#endif //PRODUCT
|
|
429 |
return F_none;
|
|
430 |
}
|
|
431 |
|
|
432 |
|
|
433 |
#ifndef PRODUCT
|
|
434 |
// verify_method performs an extra check on a matched intrinsic method
|
|
435 |
|
|
436 |
static bool match_method(methodOop m, symbolOop n, symbolOop s) {
|
|
437 |
return (m->name() == n &&
|
|
438 |
m->signature() == s);
|
|
439 |
}
|
|
440 |
|
|
441 |
static vmIntrinsics::ID match_method_with_klass(methodOop m, symbolOop mk) {
|
|
442 |
#define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \
|
|
443 |
{ symbolOop k = vmSymbols::klassname(); \
|
|
444 |
if (mk == k) { \
|
|
445 |
symbolOop n = vmSymbols::namepart(); \
|
|
446 |
symbolOop s = vmSymbols::sigpart(); \
|
|
447 |
if (match_method(m, n, s)) \
|
|
448 |
return vmIntrinsics::id; \
|
|
449 |
} }
|
|
450 |
VM_INTRINSICS_DO(VM_INTRINSIC_MATCH,
|
|
451 |
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
|
|
452 |
return vmIntrinsics::_none;
|
|
453 |
#undef VM_INTRINSIC_MATCH
|
|
454 |
}
|
|
455 |
|
|
456 |
void vmIntrinsics::verify_method(ID actual_id, methodOop m) {
|
|
457 |
symbolOop mk = Klass::cast(m->method_holder())->name();
|
|
458 |
ID declared_id = match_method_with_klass(m, mk);
|
|
459 |
|
|
460 |
if (declared_id == actual_id) return; // success
|
|
461 |
|
|
462 |
if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) {
|
|
463 |
// Here are a few special cases in StrictMath not declared in vmSymbols.hpp.
|
|
464 |
switch (actual_id) {
|
|
465 |
case _min:
|
|
466 |
case _max:
|
|
467 |
case _dsqrt:
|
|
468 |
declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math());
|
|
469 |
if (declared_id == actual_id) return; // acceptable alias
|
|
470 |
break;
|
|
471 |
}
|
|
472 |
}
|
|
473 |
|
|
474 |
const char* declared_name = name_at(declared_id);
|
|
475 |
const char* actual_name = name_at(actual_id);
|
|
476 |
methodHandle mh = m;
|
|
477 |
m = NULL;
|
|
478 |
ttyLocker ttyl;
|
|
479 |
if (xtty != NULL) {
|
|
480 |
xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'",
|
|
481 |
actual_name, declared_name);
|
|
482 |
xtty->method(mh);
|
|
483 |
xtty->end_elem("");
|
|
484 |
}
|
|
485 |
if (PrintMiscellaneous && (WizardMode || Verbose)) {
|
|
486 |
tty->print_cr("*** misidentified method; %s(%d) should be %s(%d):",
|
|
487 |
declared_name, declared_id, actual_name, actual_id);
|
|
488 |
m->print_short_name(tty);
|
|
489 |
tty->cr();
|
|
490 |
}
|
|
491 |
}
|
|
492 |
#endif //PRODUCT
|