src/share/vm/classfile/vmSymbols.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
child 9041
95a08233f46c
permissions
-rw-r--r--

merge

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

mercurial