annotate src/share/vm/classfile/vmSymbols.cpp @ 1133:aa62b9388fce

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