src/share/vm/classfile/vmSymbols.cpp

Fri, 23 Mar 2012 11:16:05 -0400

author
coleenp
date
Fri, 23 Mar 2012 11:16:05 -0400
changeset 3682
fc9d8850ab8b
parent 2638
72dee110246f
child 3969
1d7922586cf6
permissions
-rw-r--r--

7150058: Allocate symbols from null boot loader to an arena for NMT
Summary: Move symbol allocation to an arena so NMT doesn't have to track them at startup.
Reviewed-by: never, kamg, zgu

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

mercurial