1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include <string.h> 26 27 #include "precompiled.hpp" 28 #include "classfile/vmSymbols.hpp" 29 #include "memory/allocation.hpp" 30 #include "memory/oopFactory.hpp" 31 #include "oops/oop.inline.hpp" 32 #include "runtime/handles.inline.hpp" 33 #include "utilities/xmlstream.hpp" 34 35 36 Symbol* vmSymbols::_symbols[vmSymbols::SID_LIMIT]; 37 38 Symbol* vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ }; 39 40 inline int compare_symbol(Symbol* a, Symbol* b) { 41 if (a == b) return 0; 42 // follow the natural address order: 43 return (address)a > (address)b ? +1 : -1; 44 } 45 46 static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT]; 47 extern "C" { 48 static int compare_vmsymbol_sid(const void* void_a, const void* void_b) { 49 Symbol* a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a)); 50 Symbol* b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b)); 51 return compare_symbol(a, b); 52 } 53 } 54 55 #ifdef ASSERT 56 #define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0" 57 static const char* vm_symbol_enum_names = 58 VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE) 59 "\0"; 60 static const char* vm_symbol_enum_name(vmSymbols::SID sid) { 61 const char* string = &vm_symbol_enum_names[0]; 62 int skip = (int)sid - (int)vmSymbols::FIRST_SID; 63 for (; skip != 0; skip--) { 64 size_t skiplen = strlen(string); 65 if (skiplen == 0) return "<unknown>"; // overflow 66 string += skiplen+1; 67 } 68 return string; 69 } 70 #endif //ASSERT 71 72 // Put all the VM symbol strings in one place. 73 // Makes for a more compact libjvm. 74 #define VM_SYMBOL_BODY(name, string) string "\0" 75 static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE); 76 77 void vmSymbols::initialize(TRAPS) { 78 assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield"); 79 assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please"); 80 assert(vmIntrinsics::FLAG_LIMIT <= (1 << vmIntrinsics::log2_FLAG_LIMIT), "must fit in this bitfield"); 81 82 if (!UseSharedSpaces) { 83 const char* string = &vm_symbol_bodies[0]; 84 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 85 Symbol* sym = SymbolTable::new_permanent_symbol(string, CHECK); 86 _symbols[index] = sym; 87 string += strlen(string); // skip string body 88 string += 1; // skip trailing null 89 } 90 91 _type_signatures[T_BYTE] = byte_signature(); 92 _type_signatures[T_CHAR] = char_signature(); 93 _type_signatures[T_DOUBLE] = double_signature(); 94 _type_signatures[T_FLOAT] = float_signature(); 95 _type_signatures[T_INT] = int_signature(); 96 _type_signatures[T_LONG] = long_signature(); 97 _type_signatures[T_SHORT] = short_signature(); 98 _type_signatures[T_BOOLEAN] = bool_signature(); 99 _type_signatures[T_VOID] = void_signature(); 100 // no single signatures for T_OBJECT or T_ARRAY 101 } 102 103 #ifdef ASSERT 104 // Check for duplicates: 105 for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) { 106 Symbol* sym = symbol_at((SID)i1); 107 for (int i2 = (int)FIRST_SID; i2 < i1; i2++) { 108 if (symbol_at((SID)i2) == sym) { 109 tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"", 110 vm_symbol_enum_name((SID)i2), i2, 111 vm_symbol_enum_name((SID)i1), i1); 112 sym->print_symbol_on(tty); 113 tty->print_cr("\""); 114 } 115 } 116 } 117 #endif //ASSERT 118 119 // Create an index for find_id: 120 { 121 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 122 vm_symbol_index[index] = (SID)index; 123 } 124 int num_sids = SID_LIMIT-FIRST_SID; 125 qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]), 126 compare_vmsymbol_sid); 127 } 128 129 #ifdef ASSERT 130 { 131 // Spot-check correspondence between strings, symbols, and enums: 132 assert(_symbols[NO_SID] == NULL, "must be"); 133 const char* str = "java/lang/Object"; 134 TempNewSymbol jlo = SymbolTable::new_permanent_symbol(str, CHECK); 135 assert(strncmp(str, (char*)jlo->base(), jlo->utf8_length()) == 0, ""); 136 assert(jlo == java_lang_Object(), ""); 137 SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object); 138 assert(find_sid(jlo) == sid, ""); 139 assert(symbol_at(sid) == jlo, ""); 140 141 // Make sure find_sid produces the right answer in each case. 142 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 143 Symbol* sym = symbol_at((SID)index); 144 sid = find_sid(sym); 145 assert(sid == (SID)index, "symbol index works"); 146 // Note: If there are duplicates, this assert will fail. 147 // A "Duplicate VM symbol" message will have already been printed. 148 } 149 150 // The string "format" happens (at the moment) not to be a vmSymbol, 151 // though it is a method name in java.lang.String. 152 str = "format"; 153 TempNewSymbol fmt = SymbolTable::new_permanent_symbol(str, CHECK); 154 sid = find_sid(fmt); 155 assert(sid == NO_SID, "symbol index works (negative test)"); 156 } 157 #endif 158 } 159 160 161 #ifndef PRODUCT 162 const char* vmSymbols::name_for(vmSymbols::SID sid) { 163 if (sid == NO_SID) 164 return "NO_SID"; 165 const char* string = &vm_symbol_bodies[0]; 166 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 167 if (index == (int)sid) 168 return string; 169 string += strlen(string); // skip string body 170 string += 1; // skip trailing null 171 } 172 return "BAD_SID"; 173 } 174 #endif 175 176 177 178 void vmSymbols::symbols_do(SymbolClosure* f) { 179 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 180 f->do_symbol(&_symbols[index]); 181 } 182 for (int i = 0; i < T_VOID+1; i++) { 183 f->do_symbol(&_type_signatures[i]); 184 } 185 } 186 187 void vmSymbols::serialize(SerializeClosure* soc) { 188 soc->do_region((u_char*)&_symbols[FIRST_SID], 189 (SID_LIMIT - FIRST_SID) * sizeof(_symbols[0])); 190 soc->do_region((u_char*)_type_signatures, sizeof(_type_signatures)); 191 } 192 193 194 BasicType vmSymbols::signature_type(Symbol* s) { 195 assert(s != NULL, "checking"); 196 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { 197 if (s == _type_signatures[i]) { 198 return (BasicType)i; 199 } 200 } 201 return T_OBJECT; 202 } 203 204 205 static int mid_hint = (int)vmSymbols::FIRST_SID+1; 206 207 #ifndef PRODUCT 208 static int find_sid_calls, find_sid_probes; 209 // (Typical counts are calls=7000 and probes=17000.) 210 #endif 211 212 vmSymbols::SID vmSymbols::find_sid(Symbol* symbol) { 213 // Handle the majority of misses by a bounds check. 214 // Then, use a binary search over the index. 215 // Expected trip count is less than log2_SID_LIMIT, about eight. 216 // This is slow but acceptable, given that calls are not 217 // dynamically common. (Method*::intrinsic_id has a cache.) 218 NOT_PRODUCT(find_sid_calls++); 219 int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1; 220 SID sid = NO_SID, sid1; 221 int cmp1; 222 sid1 = vm_symbol_index[min]; 223 cmp1 = compare_symbol(symbol, symbol_at(sid1)); 224 if (cmp1 <= 0) { // before the first 225 if (cmp1 == 0) sid = sid1; 226 } else { 227 sid1 = vm_symbol_index[max]; 228 cmp1 = compare_symbol(symbol, symbol_at(sid1)); 229 if (cmp1 >= 0) { // after the last 230 if (cmp1 == 0) sid = sid1; 231 } else { 232 // After checking the extremes, do a binary search. 233 ++min; --max; // endpoints are done 234 int mid = mid_hint; // start at previous success 235 while (max >= min) { 236 assert(mid >= min && mid <= max, ""); 237 NOT_PRODUCT(find_sid_probes++); 238 sid1 = vm_symbol_index[mid]; 239 cmp1 = compare_symbol(symbol, symbol_at(sid1)); 240 if (cmp1 == 0) { 241 mid_hint = mid; 242 sid = sid1; 243 break; 244 } 245 if (cmp1 < 0) 246 max = mid - 1; // symbol < symbol_at(sid) 247 else 248 min = mid + 1; 249 250 // Pick a new probe point: 251 mid = (max + min) / 2; 252 } 253 } 254 } 255 256 #ifdef ASSERT 257 // Perform the exhaustive self-check the first 1000 calls, 258 // and every 100 calls thereafter. 259 static int find_sid_check_count = -2000; 260 if ((uint)++find_sid_check_count > (uint)100) { 261 if (find_sid_check_count > 0) find_sid_check_count = 0; 262 263 // Make sure this is the right answer, using linear search. 264 // (We have already proven that there are no duplicates in the list.) 265 SID sid2 = NO_SID; 266 for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) { 267 Symbol* sym2 = symbol_at((SID)index); 268 if (sym2 == symbol) { 269 sid2 = (SID)index; 270 break; 271 } 272 } 273 // Unless it's a duplicate, assert that the sids are the same. 274 if (_symbols[sid] != _symbols[sid2]) { 275 assert(sid == sid2, "binary same as linear search"); 276 } 277 } 278 #endif //ASSERT 279 280 return sid; 281 } 282 283 vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) { 284 Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name)); 285 if (symbol == NULL) return NO_SID; 286 return find_sid(symbol); 287 } 288 289 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) { 290 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0)) 291 switch (TYPE2(type, unboxing)) { 292 #define BASIC_TYPE_CASE(type, box, unbox) \ 293 case TYPE2(type, false): return vmIntrinsics::box; \ 294 case TYPE2(type, true): return vmIntrinsics::unbox 295 BASIC_TYPE_CASE(T_BOOLEAN, _Boolean_valueOf, _booleanValue); 296 BASIC_TYPE_CASE(T_BYTE, _Byte_valueOf, _byteValue); 297 BASIC_TYPE_CASE(T_CHAR, _Character_valueOf, _charValue); 298 BASIC_TYPE_CASE(T_SHORT, _Short_valueOf, _shortValue); 299 BASIC_TYPE_CASE(T_INT, _Integer_valueOf, _intValue); 300 BASIC_TYPE_CASE(T_LONG, _Long_valueOf, _longValue); 301 BASIC_TYPE_CASE(T_FLOAT, _Float_valueOf, _floatValue); 302 BASIC_TYPE_CASE(T_DOUBLE, _Double_valueOf, _doubleValue); 303 #undef BASIC_TYPE_CASE 304 } 305 #undef TYPE2 306 return vmIntrinsics::_none; 307 } 308 309 vmIntrinsics::ID vmIntrinsics::for_boxing(BasicType type) { 310 return wrapper_intrinsic(type, false); 311 } 312 vmIntrinsics::ID vmIntrinsics::for_unboxing(BasicType type) { 313 return wrapper_intrinsic(type, true); 314 } 315 316 vmIntrinsics::ID vmIntrinsics::for_raw_conversion(BasicType src, BasicType dest) { 317 #define SRC_DEST(s,d) (((int)(s) << 4) + (int)(d)) 318 switch (SRC_DEST(src, dest)) { 319 case SRC_DEST(T_INT, T_FLOAT): return vmIntrinsics::_intBitsToFloat; 320 case SRC_DEST(T_FLOAT, T_INT): return vmIntrinsics::_floatToRawIntBits; 321 322 case SRC_DEST(T_LONG, T_DOUBLE): return vmIntrinsics::_longBitsToDouble; 323 case SRC_DEST(T_DOUBLE, T_LONG): return vmIntrinsics::_doubleToRawLongBits; 324 } 325 #undef SRC_DEST 326 327 return vmIntrinsics::_none; 328 } 329 330 bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) { 331 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 332 switch(id) { 333 #ifdef TRACE_HAVE_INTRINSICS 334 case vmIntrinsics::_classID: 335 case vmIntrinsics::_threadID: 336 case vmIntrinsics::_counterTime: 337 #endif 338 case vmIntrinsics::_currentTimeMillis: 339 case vmIntrinsics::_nanoTime: 340 case vmIntrinsics::_floatToRawIntBits: 341 case vmIntrinsics::_intBitsToFloat: 342 case vmIntrinsics::_doubleToRawLongBits: 343 case vmIntrinsics::_longBitsToDouble: 344 case vmIntrinsics::_getClass: 345 case vmIntrinsics::_isInstance: 346 case vmIntrinsics::_currentThread: 347 case vmIntrinsics::_dabs: 348 case vmIntrinsics::_dsqrt: 349 case vmIntrinsics::_dsin: 350 case vmIntrinsics::_dcos: 351 case vmIntrinsics::_dtan: 352 case vmIntrinsics::_dlog: 353 case vmIntrinsics::_dlog10: 354 case vmIntrinsics::_dexp: 355 case vmIntrinsics::_dpow: 356 case vmIntrinsics::_checkIndex: 357 case vmIntrinsics::_Reference_get: 358 case vmIntrinsics::_updateCRC32: 359 case vmIntrinsics::_updateBytesCRC32: 360 case vmIntrinsics::_updateByteBufferCRC32: 361 return true; 362 default: 363 return false; 364 } 365 } 366 367 bool vmIntrinsics::can_trap(vmIntrinsics::ID id) { 368 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 369 switch(id) { 370 #ifdef TRACE_HAVE_INTRINSICS 371 case vmIntrinsics::_counterTime: 372 #endif 373 case vmIntrinsics::_currentTimeMillis: 374 case vmIntrinsics::_nanoTime: 375 case vmIntrinsics::_floatToRawIntBits: 376 case vmIntrinsics::_intBitsToFloat: 377 case vmIntrinsics::_doubleToRawLongBits: 378 case vmIntrinsics::_longBitsToDouble: 379 case vmIntrinsics::_currentThread: 380 case vmIntrinsics::_dabs: 381 case vmIntrinsics::_dsqrt: 382 case vmIntrinsics::_dsin: 383 case vmIntrinsics::_dcos: 384 case vmIntrinsics::_dtan: 385 case vmIntrinsics::_dlog: 386 case vmIntrinsics::_dlog10: 387 case vmIntrinsics::_dexp: 388 case vmIntrinsics::_dpow: 389 case vmIntrinsics::_updateCRC32: 390 case vmIntrinsics::_updateBytesCRC32: 391 case vmIntrinsics::_updateByteBufferCRC32: 392 return false; 393 default: 394 return true; 395 } 396 } 397 398 bool vmIntrinsics::does_virtual_dispatch(vmIntrinsics::ID id) { 399 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 400 switch(id) { 401 case vmIntrinsics::_hashCode: 402 case vmIntrinsics::_clone: 403 return true; 404 break; 405 default: 406 return false; 407 } 408 } 409 410 int vmIntrinsics::predicates_needed(vmIntrinsics::ID id) { 411 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 412 switch (id) { 413 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 414 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 415 return 1; 416 case vmIntrinsics::_digestBase_implCompressMB: 417 return 3; 418 default: 419 return 0; 420 } 421 } 422 423 bool vmIntrinsics::is_disabled_by_flags(methodHandle method, methodHandle compilation_context) { 424 vmIntrinsics::ID id = method->intrinsic_id(); 425 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 426 427 // Check if the intrinsic corresponding to 'method' has been disabled on 428 // the command line by using the DisableIntrinsic flag (either globally 429 // or on a per-method level, see src/share/vm/compiler/abstractCompiler.hpp 430 // for details). 431 // Usually, the compilation context is the caller of the method 'method'. 432 // The only case when for a non-recursive method 'method' the compilation context 433 // is not the caller of the 'method' (but it is the method itself) is 434 // java.lang.ref.Referene::get. 435 // For java.lang.ref.Reference::get, the intrinsic version is used 436 // instead of the compiled version so that the value in the referent 437 // field can be registered by the G1 pre-barrier code. The intrinsified 438 // version of Reference::get also adds a memory barrier to prevent 439 // commoning reads from the referent field across safepoint since GC 440 // can change the referent field's value. See Compile::Compile() 441 // in src/share/vm/opto/compile.cpp or 442 // GraphBuilder::GraphBuilder() in src/share/vm/c1/c1_GraphBuilder.cpp 443 // for more details. 444 445 /* Check if the intrinsic was disabled globally. */ 446 if (DisableIntrinsic[0] != '\0') { 447 if (is_id_in_list(id, DisableIntrinsic)) { 448 return true; 449 } 450 } 451 452 /* Check if the intrinsic was disabled on a per-method level. */ 453 ccstr option_value; 454 if (!compilation_context.is_null() && 455 CompilerOracle::has_option_value(compilation_context, "DisableIntrinsic", option_value)) { 456 if (is_id_in_list(id, option_value)) { 457 return true; 458 } 459 } 460 461 // -XX:-InlineNatives disables nearly all intrinsics except the ones listed in 462 // the following switch statement. 463 if (!InlineNatives) { 464 switch (id) { 465 case vmIntrinsics::_indexOf: 466 case vmIntrinsics::_compareTo: 467 case vmIntrinsics::_equals: 468 case vmIntrinsics::_equalsC: 469 case vmIntrinsics::_getAndAddInt: 470 case vmIntrinsics::_getAndAddLong: 471 case vmIntrinsics::_getAndSetInt: 472 case vmIntrinsics::_getAndSetLong: 473 case vmIntrinsics::_getAndSetObject: 474 case vmIntrinsics::_loadFence: 475 case vmIntrinsics::_storeFence: 476 case vmIntrinsics::_fullFence: 477 case vmIntrinsics::_Reference_get: 478 break; 479 default: 480 return true; 481 } 482 } 483 484 switch (id) { 485 case vmIntrinsics::_isInstance: 486 case vmIntrinsics::_isAssignableFrom: 487 case vmIntrinsics::_getModifiers: 488 case vmIntrinsics::_isInterface: 489 case vmIntrinsics::_isArray: 490 case vmIntrinsics::_isPrimitive: 491 case vmIntrinsics::_getSuperclass: 492 case vmIntrinsics::_Class_cast: 493 case vmIntrinsics::_getLength: 494 case vmIntrinsics::_newArray: 495 case vmIntrinsics::_getClass: 496 if (!InlineClassNatives) return true; 497 break; 498 case vmIntrinsics::_currentThread: 499 case vmIntrinsics::_isInterrupted: 500 if (!InlineThreadNatives) return true; 501 break; 502 case vmIntrinsics::_floatToRawIntBits: 503 case vmIntrinsics::_intBitsToFloat: 504 case vmIntrinsics::_doubleToRawLongBits: 505 case vmIntrinsics::_longBitsToDouble: 506 case vmIntrinsics::_dabs: 507 case vmIntrinsics::_dsqrt: 508 case vmIntrinsics::_dsin: 509 case vmIntrinsics::_dcos: 510 case vmIntrinsics::_dtan: 511 case vmIntrinsics::_dlog: 512 case vmIntrinsics::_dexp: 513 case vmIntrinsics::_dpow: 514 case vmIntrinsics::_dlog10: 515 case vmIntrinsics::_datan2: 516 case vmIntrinsics::_min: 517 case vmIntrinsics::_max: 518 case vmIntrinsics::_floatToIntBits: 519 case vmIntrinsics::_doubleToLongBits: 520 if (!InlineMathNatives) return true; 521 break; 522 case vmIntrinsics::_arraycopy: 523 if (!InlineArrayCopy) return true; 524 break; 525 case vmIntrinsics::_updateCRC32: 526 case vmIntrinsics::_updateBytesCRC32: 527 case vmIntrinsics::_updateByteBufferCRC32: 528 if (!UseCRC32Intrinsics) return true; 529 break; 530 case vmIntrinsics::_getObject: 531 case vmIntrinsics::_getBoolean: 532 case vmIntrinsics::_getByte: 533 case vmIntrinsics::_getShort: 534 case vmIntrinsics::_getChar: 535 case vmIntrinsics::_getInt: 536 case vmIntrinsics::_getLong: 537 case vmIntrinsics::_getFloat: 538 case vmIntrinsics::_getDouble: 539 case vmIntrinsics::_putObject: 540 case vmIntrinsics::_putBoolean: 541 case vmIntrinsics::_putByte: 542 case vmIntrinsics::_putShort: 543 case vmIntrinsics::_putChar: 544 case vmIntrinsics::_putInt: 545 case vmIntrinsics::_putLong: 546 case vmIntrinsics::_putFloat: 547 case vmIntrinsics::_putDouble: 548 case vmIntrinsics::_getObjectVolatile: 549 case vmIntrinsics::_getBooleanVolatile: 550 case vmIntrinsics::_getByteVolatile: 551 case vmIntrinsics::_getShortVolatile: 552 case vmIntrinsics::_getCharVolatile: 553 case vmIntrinsics::_getIntVolatile: 554 case vmIntrinsics::_getLongVolatile: 555 case vmIntrinsics::_getFloatVolatile: 556 case vmIntrinsics::_getDoubleVolatile: 557 case vmIntrinsics::_putObjectVolatile: 558 case vmIntrinsics::_putBooleanVolatile: 559 case vmIntrinsics::_putByteVolatile: 560 case vmIntrinsics::_putShortVolatile: 561 case vmIntrinsics::_putCharVolatile: 562 case vmIntrinsics::_putIntVolatile: 563 case vmIntrinsics::_putLongVolatile: 564 case vmIntrinsics::_putFloatVolatile: 565 case vmIntrinsics::_putDoubleVolatile: 566 case vmIntrinsics::_getByte_raw: 567 case vmIntrinsics::_getShort_raw: 568 case vmIntrinsics::_getChar_raw: 569 case vmIntrinsics::_getInt_raw: 570 case vmIntrinsics::_getLong_raw: 571 case vmIntrinsics::_getFloat_raw: 572 case vmIntrinsics::_getDouble_raw: 573 case vmIntrinsics::_putByte_raw: 574 case vmIntrinsics::_putShort_raw: 575 case vmIntrinsics::_putChar_raw: 576 case vmIntrinsics::_putInt_raw: 577 case vmIntrinsics::_putLong_raw: 578 case vmIntrinsics::_putFloat_raw: 579 case vmIntrinsics::_putDouble_raw: 580 case vmIntrinsics::_putOrderedObject: 581 case vmIntrinsics::_putOrderedLong: 582 case vmIntrinsics::_putOrderedInt: 583 case vmIntrinsics::_getAndAddInt: 584 case vmIntrinsics::_getAndAddLong: 585 case vmIntrinsics::_getAndSetInt: 586 case vmIntrinsics::_getAndSetLong: 587 case vmIntrinsics::_getAndSetObject: 588 case vmIntrinsics::_loadFence: 589 case vmIntrinsics::_storeFence: 590 case vmIntrinsics::_fullFence: 591 case vmIntrinsics::_compareAndSwapObject: 592 case vmIntrinsics::_compareAndSwapLong: 593 case vmIntrinsics::_compareAndSwapInt: 594 if (!InlineUnsafeOps) return true; 595 break; 596 case vmIntrinsics::_getShortUnaligned: 597 case vmIntrinsics::_getCharUnaligned: 598 case vmIntrinsics::_getIntUnaligned: 599 case vmIntrinsics::_getLongUnaligned: 600 case vmIntrinsics::_putShortUnaligned: 601 case vmIntrinsics::_putCharUnaligned: 602 case vmIntrinsics::_putIntUnaligned: 603 case vmIntrinsics::_putLongUnaligned: 604 case vmIntrinsics::_allocateInstance: 605 case vmIntrinsics::_getAddress_raw: 606 case vmIntrinsics::_putAddress_raw: 607 if (!InlineUnsafeOps || !UseUnalignedAccesses) return true; 608 break; 609 case vmIntrinsics::_hashCode: 610 if (!InlineObjectHash) return true; 611 break; 612 case vmIntrinsics::_aescrypt_encryptBlock: 613 case vmIntrinsics::_aescrypt_decryptBlock: 614 if (!UseAESIntrinsics) return true; 615 break; 616 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 617 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 618 if (!UseAESIntrinsics) return true; 619 break; 620 case vmIntrinsics::_sha_implCompress: 621 if (!UseSHA1Intrinsics) return true; 622 break; 623 case vmIntrinsics::_sha2_implCompress: 624 if (!UseSHA256Intrinsics) return true; 625 break; 626 case vmIntrinsics::_sha5_implCompress: 627 if (!UseSHA512Intrinsics) return true; 628 break; 629 case vmIntrinsics::_digestBase_implCompressMB: 630 if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) return true; 631 break; 632 case vmIntrinsics::_ghash_processBlocks: 633 if (!UseGHASHIntrinsics) return true; 634 break; 635 case vmIntrinsics::_updateBytesCRC32C: 636 case vmIntrinsics::_updateDirectByteBufferCRC32C: 637 if (!UseCRC32CIntrinsics) return true; 638 break; 639 case vmIntrinsics::_updateBytesAdler32: 640 case vmIntrinsics::_updateByteBufferAdler32: 641 if (!UseAdler32Intrinsics) return true; 642 break; 643 case vmIntrinsics::_copyMemory: 644 if (!InlineArrayCopy || !InlineUnsafeOps) return true; 645 break; 646 #ifdef COMPILER1 647 case vmIntrinsics::_checkIndex: 648 if (!InlineNIOCheckIndex) return true; 649 break; 650 #endif // COMPILER1 651 #ifdef COMPILER2 652 case vmIntrinsics::_clone: 653 case vmIntrinsics::_copyOf: 654 case vmIntrinsics::_copyOfRange: 655 // These intrinsics use both the objectcopy and the arraycopy 656 // intrinsic mechanism. 657 if (!InlineObjectCopy || !InlineArrayCopy) return true; 658 break; 659 case vmIntrinsics::_compareTo: 660 if (!SpecialStringCompareTo) return true; 661 break; 662 case vmIntrinsics::_indexOf: 663 if (!SpecialStringIndexOf) return true; 664 break; 665 case vmIntrinsics::_equals: 666 if (!SpecialStringEquals) return true; 667 break; 668 case vmIntrinsics::_equalsC: 669 if (!SpecialArraysEquals) return true; 670 break; 671 case vmIntrinsics::_encodeISOArray: 672 if (!SpecialEncodeISOArray) return true; 673 break; 674 case vmIntrinsics::_getCallerClass: 675 if (!InlineReflectionGetCallerClass) return true; 676 break; 677 case vmIntrinsics::_multiplyToLen: 678 if (!UseMultiplyToLenIntrinsic) return true; 679 break; 680 case vmIntrinsics::_squareToLen: 681 if (!UseSquareToLenIntrinsic) return true; 682 break; 683 case vmIntrinsics::_mulAdd: 684 if (!UseMulAddIntrinsic) return true; 685 break; 686 case vmIntrinsics::_montgomeryMultiply: 687 if (!UseMontgomeryMultiplyIntrinsic) return true; 688 break; 689 case vmIntrinsics::_montgomerySquare: 690 if (!UseMontgomerySquareIntrinsic) return true; 691 break; 692 case vmIntrinsics::_addExactI: 693 case vmIntrinsics::_addExactL: 694 case vmIntrinsics::_decrementExactI: 695 case vmIntrinsics::_decrementExactL: 696 case vmIntrinsics::_incrementExactI: 697 case vmIntrinsics::_incrementExactL: 698 case vmIntrinsics::_multiplyExactI: 699 case vmIntrinsics::_multiplyExactL: 700 case vmIntrinsics::_negateExactI: 701 case vmIntrinsics::_negateExactL: 702 case vmIntrinsics::_subtractExactI: 703 case vmIntrinsics::_subtractExactL: 704 if (!UseMathExactIntrinsics || !InlineMathNatives) return true; 705 break; 706 #endif // COMPILER2 707 default: 708 return false; 709 } 710 711 return false; 712 } 713 714 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0" 715 static const char* vm_intrinsic_name_bodies = 716 VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE, 717 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 718 719 static const char* vm_intrinsic_name_table[vmIntrinsics::ID_LIMIT]; 720 721 const char* vmIntrinsics::name_at(vmIntrinsics::ID id) { 722 const char** nt = &vm_intrinsic_name_table[0]; 723 if (nt[_none] == NULL) { 724 char* string = (char*) &vm_intrinsic_name_bodies[0]; 725 for (int index = FIRST_ID; index < ID_LIMIT; index++) { 726 nt[index] = string; 727 string += strlen(string); // skip string body 728 string += 1; // skip trailing null 729 } 730 assert(!strcmp(nt[_hashCode], "_hashCode"), "lined up"); 731 nt[_none] = "_none"; 732 } 733 if ((uint)id < (uint)ID_LIMIT) 734 return vm_intrinsic_name_table[(uint)id]; 735 else 736 return "(unknown intrinsic)"; 737 } 738 739 // These are flag-matching functions: 740 inline bool match_F_R(jshort flags) { 741 const int req = 0; 742 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED; 743 return (flags & (req | neg)) == req; 744 } 745 inline bool match_F_Y(jshort flags) { 746 const int req = JVM_ACC_SYNCHRONIZED; 747 const int neg = JVM_ACC_STATIC; 748 return (flags & (req | neg)) == req; 749 } 750 inline bool match_F_RN(jshort flags) { 751 const int req = JVM_ACC_NATIVE; 752 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED; 753 return (flags & (req | neg)) == req; 754 } 755 inline bool match_F_S(jshort flags) { 756 const int req = JVM_ACC_STATIC; 757 const int neg = JVM_ACC_SYNCHRONIZED; 758 return (flags & (req | neg)) == req; 759 } 760 inline bool match_F_SN(jshort flags) { 761 const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE; 762 const int neg = JVM_ACC_SYNCHRONIZED; 763 return (flags & (req | neg)) == req; 764 } 765 inline bool match_F_RNY(jshort flags) { 766 const int req = JVM_ACC_NATIVE | JVM_ACC_SYNCHRONIZED; 767 const int neg = JVM_ACC_STATIC; 768 return (flags & (req | neg)) == req; 769 } 770 771 // These are for forming case labels: 772 #define ID3(x, y, z) (( jlong)(z) + \ 773 ((jlong)(y) << vmSymbols::log2_SID_LIMIT) + \ 774 ((jlong)(x) << (2*vmSymbols::log2_SID_LIMIT)) ) 775 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n) 776 777 vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbols::SID holder, 778 vmSymbols::SID name, 779 vmSymbols::SID sig, 780 jshort flags) { 781 assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit"); 782 783 // Let the C compiler build the decision tree. 784 785 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 786 case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \ 787 if (!match_##fcode(flags)) break; \ 788 return id; 789 790 switch (ID3(holder, name, sig)) { 791 VM_INTRINSICS_DO(VM_INTRINSIC_CASE, 792 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 793 } 794 return vmIntrinsics::_none; 795 796 #undef VM_INTRINSIC_CASE 797 } 798 799 bool vmIntrinsics::is_id_in_list(vmIntrinsics::ID id, ccstr list) { 800 ResourceMark rm; 801 size_t length = strlen(list); 802 char* local_list = NEW_RESOURCE_ARRAY(char, length + 1); 803 strncpy(local_list, list, length + 1); 804 805 char* token = strtok(local_list, ","); 806 while (token != NULL) { 807 if (strcmp(token, vmIntrinsics::name_at(id)) == 0) { 808 return true; 809 } else { 810 token = strtok(NULL, ","); 811 } 812 } 813 return false; 814 } 815 816 const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) { 817 const char* str = name_at(id); 818 #ifndef PRODUCT 819 const char* kname = vmSymbols::name_for(class_for(id)); 820 const char* mname = vmSymbols::name_for(name_for(id)); 821 const char* sname = vmSymbols::name_for(signature_for(id)); 822 const char* fname = ""; 823 switch (flags_for(id)) { 824 case F_Y: fname = "synchronized "; break; 825 case F_RN: fname = "native "; break; 826 case F_SN: fname = "native static "; break; 827 case F_S: fname = "static "; break; 828 case F_RNY:fname = "native synchronized "; break; 829 } 830 const char* kptr = strrchr(kname, '/'); 831 if (kptr != NULL) kname = kptr + 1; 832 int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s", 833 str, fname, kname, mname, sname); 834 if (len < buflen) 835 str = buf; 836 #endif //PRODUCT 837 return str; 838 } 839 840 841 // These are to get information about intrinsics. 842 843 #define ID4(x, y, z, f) ((ID3(x, y, z) << vmIntrinsics::log2_FLAG_LIMIT) | (jlong) (f)) 844 845 static const jlong intrinsic_info_array[vmIntrinsics::ID_LIMIT+1] = { 846 #define VM_INTRINSIC_INFO(ignore_id, klass, name, sig, fcode) \ 847 ID4(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig), vmIntrinsics::fcode), 848 849 0, VM_INTRINSICS_DO(VM_INTRINSIC_INFO, 850 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE) 851 0 852 #undef VM_INTRINSIC_INFO 853 }; 854 855 inline jlong intrinsic_info(vmIntrinsics::ID id) { 856 return intrinsic_info_array[vmIntrinsics::ID_from((int)id)]; 857 } 858 859 vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) { 860 jlong info = intrinsic_info(id); 861 int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 862 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1021, ""); 863 return vmSymbols::SID( (info >> shift) & mask ); 864 } 865 866 vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) { 867 jlong info = intrinsic_info(id); 868 int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 869 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1022, ""); 870 return vmSymbols::SID( (info >> shift) & mask ); 871 } 872 873 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) { 874 jlong info = intrinsic_info(id); 875 int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 876 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, ""); 877 return vmSymbols::SID( (info >> shift) & mask ); 878 } 879 880 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) { 881 jlong info = intrinsic_info(id); 882 int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT); 883 assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, ""); 884 return Flags( (info >> shift) & mask ); 885 } 886 887 888 #ifndef PRODUCT 889 // verify_method performs an extra check on a matched intrinsic method 890 891 static bool match_method(Method* m, Symbol* n, Symbol* s) { 892 return (m->name() == n && 893 m->signature() == s); 894 } 895 896 static vmIntrinsics::ID match_method_with_klass(Method* m, Symbol* mk) { 897 #define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \ 898 { Symbol* k = vmSymbols::klassname(); \ 899 if (mk == k) { \ 900 Symbol* n = vmSymbols::namepart(); \ 901 Symbol* s = vmSymbols::sigpart(); \ 902 if (match_method(m, n, s)) \ 903 return vmIntrinsics::id; \ 904 } } 905 VM_INTRINSICS_DO(VM_INTRINSIC_MATCH, 906 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 907 return vmIntrinsics::_none; 908 #undef VM_INTRINSIC_MATCH 909 } 910 911 void vmIntrinsics::verify_method(ID actual_id, Method* m) { 912 Symbol* mk = m->method_holder()->name(); 913 ID declared_id = match_method_with_klass(m, mk); 914 915 if (declared_id == actual_id) return; // success 916 917 if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) { 918 // Here are a few special cases in StrictMath not declared in vmSymbols.hpp. 919 switch (actual_id) { 920 case _min: 921 case _max: 922 case _dsqrt: 923 declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math()); 924 if (declared_id == actual_id) return; // acceptable alias 925 break; 926 } 927 } 928 929 const char* declared_name = name_at(declared_id); 930 const char* actual_name = name_at(actual_id); 931 methodHandle mh = m; 932 m = NULL; 933 ttyLocker ttyl; 934 if (xtty != NULL) { 935 xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'", 936 actual_name, declared_name); 937 xtty->method(mh); 938 xtty->end_elem("%s", ""); 939 } 940 if (PrintMiscellaneous && (WizardMode || Verbose)) { 941 tty->print_cr("*** misidentified method; %s(%d) should be %s(%d):", 942 declared_name, declared_id, actual_name, actual_id); 943 mh()->print_short_name(tty); 944 tty->cr(); 945 } 946 } 947 #endif //PRODUCT