1 /*
   2  * Copyright (c) 1997, 2019, 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 "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "compiler/compilerDirectives.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 #include "memory/oopFactory.hpp"
  32 #include "memory/metaspaceClosure.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/handles.inline.hpp"
  35 #include "utilities/xmlstream.hpp"
  36 
  37 
  38 Symbol* vmSymbols::_symbols[vmSymbols::SID_LIMIT];
  39 
  40 Symbol* vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
  41 
  42 inline int compare_symbol(const Symbol* a, const Symbol* b) {
  43   if (a == b)  return 0;
  44   // follow the natural address order:
  45   return (address)a > (address)b ? +1 : -1;
  46 }
  47 
  48 static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
  49 extern "C" {
  50   static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
  51     const Symbol* a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
  52     const Symbol* b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
  53     return compare_symbol(a, b);
  54   }
  55 }
  56 
  57 #ifdef ASSERT
  58 #define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
  59 static const char* vm_symbol_enum_names =
  60   VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
  61   "\0";
  62 static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
  63   const char* string = &vm_symbol_enum_names[0];
  64   int skip = (int)sid - (int)vmSymbols::FIRST_SID;
  65   for (; skip != 0; skip--) {
  66     size_t skiplen = strlen(string);
  67     if (skiplen == 0)  return "<unknown>";  // overflow
  68     string += skiplen+1;
  69   }
  70   return string;
  71 }
  72 #endif //ASSERT
  73 
  74 // Put all the VM symbol strings in one place.
  75 // Makes for a more compact libjvm.
  76 #define VM_SYMBOL_BODY(name, string) string "\0"
  77 static const char* vm_symbol_bodies = VM_SYMBOLS_DO(VM_SYMBOL_BODY, VM_ALIAS_IGNORE);
  78 
  79 void vmSymbols::initialize(TRAPS) {
  80   assert((int)SID_LIMIT <= (1<<log2_SID_LIMIT), "must fit in this bitfield");
  81   assert((int)SID_LIMIT*5 > (1<<log2_SID_LIMIT), "make the bitfield smaller, please");
  82   assert(vmIntrinsics::FLAG_LIMIT <= (1 << vmIntrinsics::log2_FLAG_LIMIT), "must fit in this bitfield");
  83 
  84   if (!UseSharedSpaces) {
  85     const char* string = &vm_symbol_bodies[0];
  86     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
  87       Symbol* sym = SymbolTable::new_permanent_symbol(string);
  88       _symbols[index] = sym;
  89       string += strlen(string); // skip string body
  90       string += 1;              // skip trailing null
  91     }
  92 
  93     _type_signatures[T_BYTE]    = byte_signature();
  94     _type_signatures[T_CHAR]    = char_signature();
  95     _type_signatures[T_DOUBLE]  = double_signature();
  96     _type_signatures[T_FLOAT]   = float_signature();
  97     _type_signatures[T_INT]     = int_signature();
  98     _type_signatures[T_LONG]    = long_signature();
  99     _type_signatures[T_SHORT]   = short_signature();
 100     _type_signatures[T_BOOLEAN] = bool_signature();
 101     _type_signatures[T_VOID]    = void_signature();
 102     // no single signatures for T_OBJECT or T_ARRAY
 103 #ifdef ASSERT
 104     for (int i = (int)T_BOOLEAN; i < (int)T_VOID+1; i++) {
 105       Symbol* s = _type_signatures[i];
 106       if (s == NULL)  continue;
 107       BasicType st = signature_type(s);
 108       assert(st == i, "");
 109     }
 110 #endif
 111   }
 112 
 113 #ifdef ASSERT
 114   // Check for duplicates:
 115   for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
 116     Symbol* sym = symbol_at((SID)i1);
 117     for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
 118       if (symbol_at((SID)i2) == sym) {
 119         tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
 120                    vm_symbol_enum_name((SID)i2), i2,
 121                    vm_symbol_enum_name((SID)i1), i1);
 122         sym->print_symbol_on(tty);
 123         tty->print_cr("\"");
 124       }
 125     }
 126   }
 127 #endif //ASSERT
 128 
 129   // Create an index for find_id:
 130   {
 131     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 132       vm_symbol_index[index] = (SID)index;
 133     }
 134     int num_sids = SID_LIMIT-FIRST_SID;
 135     qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
 136           compare_vmsymbol_sid);
 137   }
 138 
 139 #ifdef ASSERT
 140   {
 141     // Spot-check correspondence between strings, symbols, and enums:
 142     assert(_symbols[NO_SID] == NULL, "must be");
 143     const char* str = "java/lang/Object";
 144     TempNewSymbol jlo = SymbolTable::new_permanent_symbol(str);
 145     assert(strncmp(str, (char*)jlo->base(), jlo->utf8_length()) == 0, "");
 146     assert(jlo == java_lang_Object(), "");
 147     SID sid = VM_SYMBOL_ENUM_NAME(java_lang_Object);
 148     assert(find_sid(jlo) == sid, "");
 149     assert(symbol_at(sid) == jlo, "");
 150 
 151     // Make sure find_sid produces the right answer in each case.
 152     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 153       Symbol* sym = symbol_at((SID)index);
 154       sid = find_sid(sym);
 155       assert(sid == (SID)index, "symbol index works");
 156       // Note:  If there are duplicates, this assert will fail.
 157       // A "Duplicate VM symbol" message will have already been printed.
 158     }
 159 
 160     // The string "format" happens (at the moment) not to be a vmSymbol,
 161     // though it is a method name in java.lang.String.
 162     str = "format";
 163     TempNewSymbol fmt = SymbolTable::new_permanent_symbol(str);
 164     sid = find_sid(fmt);
 165     assert(sid == NO_SID, "symbol index works (negative test)");
 166   }
 167 #endif
 168 }
 169 
 170 
 171 #ifndef PRODUCT
 172 const char* vmSymbols::name_for(vmSymbols::SID sid) {
 173   if (sid == NO_SID)
 174     return "NO_SID";
 175   const char* string = &vm_symbol_bodies[0];
 176   for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 177     if (index == (int)sid)
 178       return string;
 179     string += strlen(string); // skip string body
 180     string += 1;              // skip trailing null
 181   }
 182   return "BAD_SID";
 183 }
 184 #endif
 185 
 186 
 187 
 188 void vmSymbols::symbols_do(SymbolClosure* f) {
 189   for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 190     f->do_symbol(&_symbols[index]);
 191   }
 192   for (int i = 0; i < T_VOID+1; i++) {
 193     f->do_symbol(&_type_signatures[i]);
 194   }
 195 }
 196 
 197 void vmSymbols::metaspace_pointers_do(MetaspaceClosure *it) {
 198   for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 199     it->push(&_symbols[index]);
 200   }
 201   for (int i = 0; i < T_VOID+1; i++) {
 202     it->push(&_type_signatures[i]);
 203   }
 204 }
 205 
 206 void vmSymbols::serialize(SerializeClosure* soc) {
 207   soc->do_region((u_char*)&_symbols[FIRST_SID],
 208                  (SID_LIMIT - FIRST_SID) * sizeof(_symbols[0]));
 209   soc->do_region((u_char*)_type_signatures, sizeof(_type_signatures));
 210 }
 211 
 212 
 213 BasicType vmSymbols::signature_type(const Symbol* s) {
 214   assert(s != NULL, "checking");
 215   if (s->utf8_length() == 1) {
 216     BasicType result = char2type(s->char_at(0));
 217     if (is_java_primitive(result) || result == T_VOID) {
 218       assert(s == _type_signatures[result], "");
 219       return result;
 220     }
 221   }
 222   return T_OBJECT;
 223 }
 224 
 225 
 226 static int mid_hint = (int)vmSymbols::FIRST_SID+1;
 227 
 228 #ifndef PRODUCT
 229 static int find_sid_calls, find_sid_probes;
 230 // (Typical counts are calls=7000 and probes=17000.)
 231 #endif
 232 
 233 vmSymbols::SID vmSymbols::find_sid(const Symbol* symbol) {
 234   // Handle the majority of misses by a bounds check.
 235   // Then, use a binary search over the index.
 236   // Expected trip count is less than log2_SID_LIMIT, about eight.
 237   // This is slow but acceptable, given that calls are not
 238   // dynamically common.  (Method*::intrinsic_id has a cache.)
 239   NOT_PRODUCT(find_sid_calls++);
 240   int min = (int)FIRST_SID, max = (int)SID_LIMIT - 1;
 241   SID sid = NO_SID, sid1;
 242   int cmp1;
 243   sid1 = vm_symbol_index[min];
 244   cmp1 = compare_symbol(symbol, symbol_at(sid1));
 245   if (cmp1 <= 0) {              // before the first
 246     if (cmp1 == 0)  sid = sid1;
 247   } else {
 248     sid1 = vm_symbol_index[max];
 249     cmp1 = compare_symbol(symbol, symbol_at(sid1));
 250     if (cmp1 >= 0) {            // after the last
 251       if (cmp1 == 0)  sid = sid1;
 252     } else {
 253       // After checking the extremes, do a binary search.
 254       ++min; --max;             // endpoints are done
 255       int mid = mid_hint;       // start at previous success
 256       while (max >= min) {
 257         assert(mid >= min && mid <= max, "");
 258         NOT_PRODUCT(find_sid_probes++);
 259         sid1 = vm_symbol_index[mid];
 260         cmp1 = compare_symbol(symbol, symbol_at(sid1));
 261         if (cmp1 == 0) {
 262           mid_hint = mid;
 263           sid = sid1;
 264           break;
 265         }
 266         if (cmp1 < 0)
 267           max = mid - 1;        // symbol < symbol_at(sid)
 268         else
 269           min = mid + 1;
 270 
 271         // Pick a new probe point:
 272         mid = (max + min) / 2;
 273       }
 274     }
 275   }
 276 
 277 #ifdef ASSERT
 278   // Perform the exhaustive self-check the first 1000 calls,
 279   // and every 100 calls thereafter.
 280   static int find_sid_check_count = -2000;
 281   if ((uint)++find_sid_check_count > (uint)100) {
 282     if (find_sid_check_count > 0)  find_sid_check_count = 0;
 283 
 284     // Make sure this is the right answer, using linear search.
 285     // (We have already proven that there are no duplicates in the list.)
 286     SID sid2 = NO_SID;
 287     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 288       Symbol* sym2 = symbol_at((SID)index);
 289       if (sym2 == symbol) {
 290         sid2 = (SID)index;
 291         break;
 292       }
 293     }
 294     // Unless it's a duplicate, assert that the sids are the same.
 295     if (_symbols[sid] != _symbols[sid2]) {
 296       assert(sid == sid2, "binary same as linear search");
 297     }
 298   }
 299 #endif //ASSERT
 300 
 301   return sid;
 302 }
 303 
 304 vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) {
 305   Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name));
 306   if (symbol == NULL)  return NO_SID;
 307   return find_sid(symbol);
 308 }
 309 
 310 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) {
 311 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0))
 312   switch (TYPE2(type, unboxing)) {
 313 #define BASIC_TYPE_CASE(type, box, unbox) \
 314     case TYPE2(type, false):  return vmIntrinsics::box; \
 315     case TYPE2(type, true):   return vmIntrinsics::unbox
 316     BASIC_TYPE_CASE(T_BOOLEAN, _Boolean_valueOf,   _booleanValue);
 317     BASIC_TYPE_CASE(T_BYTE,    _Byte_valueOf,      _byteValue);
 318     BASIC_TYPE_CASE(T_CHAR,    _Character_valueOf, _charValue);
 319     BASIC_TYPE_CASE(T_SHORT,   _Short_valueOf,     _shortValue);
 320     BASIC_TYPE_CASE(T_INT,     _Integer_valueOf,   _intValue);
 321     BASIC_TYPE_CASE(T_LONG,    _Long_valueOf,      _longValue);
 322     BASIC_TYPE_CASE(T_FLOAT,   _Float_valueOf,     _floatValue);
 323     BASIC_TYPE_CASE(T_DOUBLE,  _Double_valueOf,    _doubleValue);
 324 #undef BASIC_TYPE_CASE
 325   }
 326 #undef TYPE2
 327   return vmIntrinsics::_none;
 328 }
 329 
 330 vmIntrinsics::ID vmIntrinsics::for_boxing(BasicType type) {
 331   return wrapper_intrinsic(type, false);
 332 }
 333 vmIntrinsics::ID vmIntrinsics::for_unboxing(BasicType type) {
 334   return wrapper_intrinsic(type, true);
 335 }
 336 
 337 vmIntrinsics::ID vmIntrinsics::for_raw_conversion(BasicType src, BasicType dest) {
 338 #define SRC_DEST(s,d) (((int)(s) << 4) + (int)(d))
 339   switch (SRC_DEST(src, dest)) {
 340   case SRC_DEST(T_INT, T_FLOAT):   return vmIntrinsics::_intBitsToFloat;
 341   case SRC_DEST(T_FLOAT, T_INT):   return vmIntrinsics::_floatToRawIntBits;
 342 
 343   case SRC_DEST(T_LONG, T_DOUBLE): return vmIntrinsics::_longBitsToDouble;
 344   case SRC_DEST(T_DOUBLE, T_LONG): return vmIntrinsics::_doubleToRawLongBits;
 345   }
 346 #undef SRC_DEST
 347 
 348   return vmIntrinsics::_none;
 349 }
 350 
 351 bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) {
 352   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 353   switch(id) {
 354 #ifdef JFR_HAVE_INTRINSICS
 355   case vmIntrinsics::_counterTime:
 356 #endif
 357   case vmIntrinsics::_currentTimeMillis:
 358   case vmIntrinsics::_nanoTime:
 359   case vmIntrinsics::_floatToRawIntBits:
 360   case vmIntrinsics::_intBitsToFloat:
 361   case vmIntrinsics::_doubleToRawLongBits:
 362   case vmIntrinsics::_longBitsToDouble:
 363   case vmIntrinsics::_getClass:
 364   case vmIntrinsics::_isInstance:
 365   case vmIntrinsics::_currentThread:
 366   case vmIntrinsics::_dabs:
 367   case vmIntrinsics::_fabs:
 368   case vmIntrinsics::_iabs:
 369   case vmIntrinsics::_labs:
 370   case vmIntrinsics::_dsqrt:
 371   case vmIntrinsics::_dsin:
 372   case vmIntrinsics::_dcos:
 373   case vmIntrinsics::_dtan:
 374   case vmIntrinsics::_dlog:
 375   case vmIntrinsics::_dlog10:
 376   case vmIntrinsics::_dexp:
 377   case vmIntrinsics::_dpow:
 378   case vmIntrinsics::_checkIndex:
 379   case vmIntrinsics::_Reference_get:
 380   case vmIntrinsics::_Continuation_doContinue:
 381   case vmIntrinsics::_Continuation_doYield:
 382   case vmIntrinsics::_Continuation_jump:
 383   case vmIntrinsics::_Continuation_getSP:
 384   case vmIntrinsics::_updateCRC32:
 385   case vmIntrinsics::_updateBytesCRC32:
 386   case vmIntrinsics::_updateByteBufferCRC32:
 387   case vmIntrinsics::_vectorizedMismatch:
 388   case vmIntrinsics::_fmaD:
 389   case vmIntrinsics::_fmaF:
 390   case vmIntrinsics::_isDigit:
 391   case vmIntrinsics::_isLowerCase:
 392   case vmIntrinsics::_isUpperCase:
 393   case vmIntrinsics::_isWhitespace:
 394     return true;
 395   default:
 396     return false;
 397   }
 398 }
 399 
 400 bool vmIntrinsics::can_trap(vmIntrinsics::ID id) {
 401   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 402   switch(id) {
 403 #ifdef JFR_HAVE_INTRINSICS
 404   case vmIntrinsics::_counterTime:
 405   case vmIntrinsics::_getClassId:
 406 #endif
 407   case vmIntrinsics::_currentTimeMillis:
 408   case vmIntrinsics::_nanoTime:
 409   case vmIntrinsics::_floatToRawIntBits:
 410   case vmIntrinsics::_intBitsToFloat:
 411   case vmIntrinsics::_doubleToRawLongBits:
 412   case vmIntrinsics::_longBitsToDouble:
 413   case vmIntrinsics::_currentThread:
 414   case vmIntrinsics::_dabs:
 415   case vmIntrinsics::_fabs:
 416   case vmIntrinsics::_iabs:
 417   case vmIntrinsics::_labs:
 418   case vmIntrinsics::_dsqrt:
 419   case vmIntrinsics::_dsin:
 420   case vmIntrinsics::_dcos:
 421   case vmIntrinsics::_dtan:
 422   case vmIntrinsics::_dlog:
 423   case vmIntrinsics::_dlog10:
 424   case vmIntrinsics::_dexp:
 425   case vmIntrinsics::_dpow:
 426   case vmIntrinsics::_updateCRC32:
 427   case vmIntrinsics::_updateBytesCRC32:
 428   case vmIntrinsics::_updateByteBufferCRC32:
 429   case vmIntrinsics::_vectorizedMismatch:
 430   case vmIntrinsics::_fmaD:
 431   case vmIntrinsics::_fmaF:
 432     return false;
 433   default:
 434     return true;
 435   }
 436 }
 437 
 438 // Some intrinsics produce different results if they are not pinned
 439 bool vmIntrinsics::should_be_pinned(vmIntrinsics::ID id) {
 440   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 441   switch(id) {
 442 #ifdef JFR_HAVE_INTRINSICS
 443   case vmIntrinsics::_counterTime:
 444 #endif
 445   case vmIntrinsics::_currentTimeMillis:
 446   case vmIntrinsics::_nanoTime:
 447     return true;
 448   default:
 449     return false;
 450   }
 451 }
 452 
 453 bool vmIntrinsics::does_virtual_dispatch(vmIntrinsics::ID id) {
 454   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 455   switch(id) {
 456   case vmIntrinsics::_hashCode:
 457   case vmIntrinsics::_clone:
 458     return true;
 459     break;
 460   default:
 461     return false;
 462   }
 463 }
 464 
 465 int vmIntrinsics::predicates_needed(vmIntrinsics::ID id) {
 466   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 467   switch (id) {
 468   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 469   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 470   case vmIntrinsics::_counterMode_AESCrypt:
 471     return 1;
 472   case vmIntrinsics::_digestBase_implCompressMB:
 473     return 3;
 474   default:
 475     return 0;
 476   }
 477 }
 478 
 479 bool vmIntrinsics::is_intrinsic_available(vmIntrinsics::ID id) {
 480   return !vmIntrinsics::is_intrinsic_disabled(id) &&
 481     !vmIntrinsics::is_disabled_by_flags(id);
 482 }
 483 
 484 bool vmIntrinsics::is_intrinsic_disabled(vmIntrinsics::ID id) {
 485   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 486 
 487   // Canonicalize DisableIntrinsic to contain only ',' as a separator.
 488   // Note, DirectiveSet may not be created at this point yet since this code
 489   // is called from initial stub geenration code.
 490   char* local_list = (char*)DirectiveSet::canonicalize_disableintrinsic(DisableIntrinsic);
 491   char* save_ptr;
 492   bool found = false;
 493 
 494   char* token = strtok_r(local_list, ",", &save_ptr);
 495   while (token != NULL) {
 496     if (strcmp(token, vmIntrinsics::name_at(id)) == 0) {
 497       found = true;
 498       break;
 499     } else {
 500       token = strtok_r(NULL, ",", &save_ptr);
 501     }
 502   }
 503 
 504   FREE_C_HEAP_ARRAY(char, local_list);
 505   return found;
 506 }
 507 
 508 
 509 bool vmIntrinsics::is_disabled_by_flags(const methodHandle& method) {
 510   vmIntrinsics::ID id = method->intrinsic_id();
 511   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 512   return is_disabled_by_flags(id);
 513 }
 514 
 515 bool vmIntrinsics::is_disabled_by_flags(vmIntrinsics::ID id) {
 516   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 517 
 518   // -XX:-InlineNatives disables nearly all intrinsics except the ones listed in
 519   // the following switch statement.
 520   if (!InlineNatives) {
 521     switch (id) {
 522     case vmIntrinsics::_indexOfL:
 523     case vmIntrinsics::_indexOfU:
 524     case vmIntrinsics::_indexOfUL:
 525     case vmIntrinsics::_indexOfIL:
 526     case vmIntrinsics::_indexOfIU:
 527     case vmIntrinsics::_indexOfIUL:
 528     case vmIntrinsics::_indexOfU_char:
 529     case vmIntrinsics::_compareToL:
 530     case vmIntrinsics::_compareToU:
 531     case vmIntrinsics::_compareToLU:
 532     case vmIntrinsics::_compareToUL:
 533     case vmIntrinsics::_equalsL:
 534     case vmIntrinsics::_equalsU:
 535     case vmIntrinsics::_equalsC:
 536     case vmIntrinsics::_getCharStringU:
 537     case vmIntrinsics::_putCharStringU:
 538     case vmIntrinsics::_compressStringC:
 539     case vmIntrinsics::_compressStringB:
 540     case vmIntrinsics::_inflateStringC:
 541     case vmIntrinsics::_inflateStringB:
 542     case vmIntrinsics::_getAndAddInt:
 543     case vmIntrinsics::_getAndAddLong:
 544     case vmIntrinsics::_getAndSetInt:
 545     case vmIntrinsics::_getAndSetLong:
 546     case vmIntrinsics::_getAndSetReference:
 547     case vmIntrinsics::_loadFence:
 548     case vmIntrinsics::_storeFence:
 549     case vmIntrinsics::_fullFence:
 550     case vmIntrinsics::_hasNegatives:
 551     case vmIntrinsics::_Reference_get:
 552     case vmIntrinsics::_Continuation_doContinue:
 553     case vmIntrinsics::_Continuation_doYield:
 554     case vmIntrinsics::_Continuation_jump:
 555     case vmIntrinsics::_Continuation_getSP:
 556       break;
 557     default:
 558       return true;
 559     }
 560   }
 561 
 562   switch (id) {
 563   case vmIntrinsics::_isInstance:
 564   case vmIntrinsics::_isAssignableFrom:
 565   case vmIntrinsics::_getModifiers:
 566   case vmIntrinsics::_isInterface:
 567   case vmIntrinsics::_isArray:
 568   case vmIntrinsics::_isPrimitive:
 569   case vmIntrinsics::_getSuperclass:
 570   case vmIntrinsics::_Class_cast:
 571   case vmIntrinsics::_getLength:
 572   case vmIntrinsics::_newArray:
 573   case vmIntrinsics::_getClass:
 574     if (!InlineClassNatives) return true;
 575     break;
 576   case vmIntrinsics::_currentThread:
 577   case vmIntrinsics::_isInterrupted:
 578     if (!InlineThreadNatives) return true;
 579     break;
 580   case vmIntrinsics::_floatToRawIntBits:
 581   case vmIntrinsics::_intBitsToFloat:
 582   case vmIntrinsics::_doubleToRawLongBits:
 583   case vmIntrinsics::_longBitsToDouble:
 584   case vmIntrinsics::_dabs:
 585   case vmIntrinsics::_fabs:
 586   case vmIntrinsics::_iabs:
 587   case vmIntrinsics::_labs:
 588   case vmIntrinsics::_dsqrt:
 589   case vmIntrinsics::_dsin:
 590   case vmIntrinsics::_dcos:
 591   case vmIntrinsics::_dtan:
 592   case vmIntrinsics::_dlog:
 593   case vmIntrinsics::_dexp:
 594   case vmIntrinsics::_dpow:
 595   case vmIntrinsics::_dlog10:
 596   case vmIntrinsics::_datan2:
 597   case vmIntrinsics::_min:
 598   case vmIntrinsics::_max:
 599   case vmIntrinsics::_floatToIntBits:
 600   case vmIntrinsics::_doubleToLongBits:
 601   case vmIntrinsics::_maxF:
 602   case vmIntrinsics::_minF:
 603   case vmIntrinsics::_maxD:
 604   case vmIntrinsics::_minD:
 605     if (!InlineMathNatives) return true;
 606     break;
 607   case vmIntrinsics::_fmaD:
 608   case vmIntrinsics::_fmaF:
 609     if (!InlineMathNatives || !UseFMA) return true;
 610     break;
 611   case vmIntrinsics::_arraycopy:
 612     if (!InlineArrayCopy) return true;
 613     break;
 614   case vmIntrinsics::_updateCRC32:
 615   case vmIntrinsics::_updateBytesCRC32:
 616   case vmIntrinsics::_updateByteBufferCRC32:
 617     if (!UseCRC32Intrinsics) return true;
 618     break;
 619   case vmIntrinsics::_getReference:
 620   case vmIntrinsics::_getBoolean:
 621   case vmIntrinsics::_getByte:
 622   case vmIntrinsics::_getShort:
 623   case vmIntrinsics::_getChar:
 624   case vmIntrinsics::_getInt:
 625   case vmIntrinsics::_getLong:
 626   case vmIntrinsics::_getFloat:
 627   case vmIntrinsics::_getDouble:
 628   case vmIntrinsics::_putReference:
 629   case vmIntrinsics::_putBoolean:
 630   case vmIntrinsics::_putByte:
 631   case vmIntrinsics::_putShort:
 632   case vmIntrinsics::_putChar:
 633   case vmIntrinsics::_putInt:
 634   case vmIntrinsics::_putLong:
 635   case vmIntrinsics::_putFloat:
 636   case vmIntrinsics::_putDouble:
 637   case vmIntrinsics::_getReferenceVolatile:
 638   case vmIntrinsics::_getBooleanVolatile:
 639   case vmIntrinsics::_getByteVolatile:
 640   case vmIntrinsics::_getShortVolatile:
 641   case vmIntrinsics::_getCharVolatile:
 642   case vmIntrinsics::_getIntVolatile:
 643   case vmIntrinsics::_getLongVolatile:
 644   case vmIntrinsics::_getFloatVolatile:
 645   case vmIntrinsics::_getDoubleVolatile:
 646   case vmIntrinsics::_putReferenceVolatile:
 647   case vmIntrinsics::_putBooleanVolatile:
 648   case vmIntrinsics::_putByteVolatile:
 649   case vmIntrinsics::_putShortVolatile:
 650   case vmIntrinsics::_putCharVolatile:
 651   case vmIntrinsics::_putIntVolatile:
 652   case vmIntrinsics::_putLongVolatile:
 653   case vmIntrinsics::_putFloatVolatile:
 654   case vmIntrinsics::_putDoubleVolatile:
 655   case vmIntrinsics::_getReferenceAcquire:
 656   case vmIntrinsics::_getBooleanAcquire:
 657   case vmIntrinsics::_getByteAcquire:
 658   case vmIntrinsics::_getShortAcquire:
 659   case vmIntrinsics::_getCharAcquire:
 660   case vmIntrinsics::_getIntAcquire:
 661   case vmIntrinsics::_getLongAcquire:
 662   case vmIntrinsics::_getFloatAcquire:
 663   case vmIntrinsics::_getDoubleAcquire:
 664   case vmIntrinsics::_putReferenceRelease:
 665   case vmIntrinsics::_putBooleanRelease:
 666   case vmIntrinsics::_putByteRelease:
 667   case vmIntrinsics::_putShortRelease:
 668   case vmIntrinsics::_putCharRelease:
 669   case vmIntrinsics::_putIntRelease:
 670   case vmIntrinsics::_putLongRelease:
 671   case vmIntrinsics::_putFloatRelease:
 672   case vmIntrinsics::_putDoubleRelease:
 673   case vmIntrinsics::_getReferenceOpaque:
 674   case vmIntrinsics::_getBooleanOpaque:
 675   case vmIntrinsics::_getByteOpaque:
 676   case vmIntrinsics::_getShortOpaque:
 677   case vmIntrinsics::_getCharOpaque:
 678   case vmIntrinsics::_getIntOpaque:
 679   case vmIntrinsics::_getLongOpaque:
 680   case vmIntrinsics::_getFloatOpaque:
 681   case vmIntrinsics::_getDoubleOpaque:
 682   case vmIntrinsics::_putReferenceOpaque:
 683   case vmIntrinsics::_putBooleanOpaque:
 684   case vmIntrinsics::_putByteOpaque:
 685   case vmIntrinsics::_putShortOpaque:
 686   case vmIntrinsics::_putCharOpaque:
 687   case vmIntrinsics::_putIntOpaque:
 688   case vmIntrinsics::_putLongOpaque:
 689   case vmIntrinsics::_putFloatOpaque:
 690   case vmIntrinsics::_putDoubleOpaque:
 691   case vmIntrinsics::_getAndAddInt:
 692   case vmIntrinsics::_getAndAddLong:
 693   case vmIntrinsics::_getAndSetInt:
 694   case vmIntrinsics::_getAndSetLong:
 695   case vmIntrinsics::_getAndSetReference:
 696   case vmIntrinsics::_loadFence:
 697   case vmIntrinsics::_storeFence:
 698   case vmIntrinsics::_fullFence:
 699   case vmIntrinsics::_compareAndSetLong:
 700   case vmIntrinsics::_weakCompareAndSetLong:
 701   case vmIntrinsics::_weakCompareAndSetLongPlain:
 702   case vmIntrinsics::_weakCompareAndSetLongAcquire:
 703   case vmIntrinsics::_weakCompareAndSetLongRelease:
 704   case vmIntrinsics::_compareAndSetInt:
 705   case vmIntrinsics::_weakCompareAndSetInt:
 706   case vmIntrinsics::_weakCompareAndSetIntPlain:
 707   case vmIntrinsics::_weakCompareAndSetIntAcquire:
 708   case vmIntrinsics::_weakCompareAndSetIntRelease:
 709   case vmIntrinsics::_compareAndSetReference:
 710   case vmIntrinsics::_weakCompareAndSetReference:
 711   case vmIntrinsics::_weakCompareAndSetReferencePlain:
 712   case vmIntrinsics::_weakCompareAndSetReferenceAcquire:
 713   case vmIntrinsics::_weakCompareAndSetReferenceRelease:
 714   case vmIntrinsics::_compareAndExchangeInt:
 715   case vmIntrinsics::_compareAndExchangeIntAcquire:
 716   case vmIntrinsics::_compareAndExchangeIntRelease:
 717   case vmIntrinsics::_compareAndExchangeLong:
 718   case vmIntrinsics::_compareAndExchangeLongAcquire:
 719   case vmIntrinsics::_compareAndExchangeLongRelease:
 720   case vmIntrinsics::_compareAndExchangeReference:
 721   case vmIntrinsics::_compareAndExchangeReferenceAcquire:
 722   case vmIntrinsics::_compareAndExchangeReferenceRelease:
 723     if (!InlineUnsafeOps) return true;
 724     break;
 725   case vmIntrinsics::_getShortUnaligned:
 726   case vmIntrinsics::_getCharUnaligned:
 727   case vmIntrinsics::_getIntUnaligned:
 728   case vmIntrinsics::_getLongUnaligned:
 729   case vmIntrinsics::_putShortUnaligned:
 730   case vmIntrinsics::_putCharUnaligned:
 731   case vmIntrinsics::_putIntUnaligned:
 732   case vmIntrinsics::_putLongUnaligned:
 733   case vmIntrinsics::_allocateInstance:
 734     if (!InlineUnsafeOps || !UseUnalignedAccesses) return true;
 735     break;
 736   case vmIntrinsics::_hashCode:
 737     if (!InlineObjectHash) return true;
 738     break;
 739   case vmIntrinsics::_aescrypt_encryptBlock:
 740   case vmIntrinsics::_aescrypt_decryptBlock:
 741     if (!UseAESIntrinsics) return true;
 742     break;
 743   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 744   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 745     if (!UseAESIntrinsics) return true;
 746     break;
 747   case vmIntrinsics::_counterMode_AESCrypt:
 748     if (!UseAESCTRIntrinsics) return true;
 749     break;
 750   case vmIntrinsics::_sha_implCompress:
 751     if (!UseSHA1Intrinsics) return true;
 752     break;
 753   case vmIntrinsics::_sha2_implCompress:
 754     if (!UseSHA256Intrinsics) return true;
 755     break;
 756   case vmIntrinsics::_sha5_implCompress:
 757     if (!UseSHA512Intrinsics) return true;
 758     break;
 759   case vmIntrinsics::_digestBase_implCompressMB:
 760     if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) return true;
 761     break;
 762   case vmIntrinsics::_ghash_processBlocks:
 763     if (!UseGHASHIntrinsics) return true;
 764     break;
 765   case vmIntrinsics::_base64_encodeBlock:
 766     if (!UseBASE64Intrinsics) return true;
 767     break;
 768   case vmIntrinsics::_updateBytesCRC32C:
 769   case vmIntrinsics::_updateDirectByteBufferCRC32C:
 770     if (!UseCRC32CIntrinsics) return true;
 771     break;
 772   case vmIntrinsics::_vectorizedMismatch:
 773     if (!UseVectorizedMismatchIntrinsic) return true;
 774     break;
 775   case vmIntrinsics::_updateBytesAdler32:
 776   case vmIntrinsics::_updateByteBufferAdler32:
 777     if (!UseAdler32Intrinsics) return true;
 778     break;
 779   case vmIntrinsics::_copyMemory:
 780     if (!InlineArrayCopy || !InlineUnsafeOps) return true;
 781     break;
 782 #ifdef COMPILER1
 783   case vmIntrinsics::_checkIndex:
 784     if (!InlineNIOCheckIndex) return true;
 785     break;
 786 #endif // COMPILER1
 787 #ifdef COMPILER2
 788   case vmIntrinsics::_clone:
 789 #if INCLUDE_ZGC
 790     if (UseZGC) return true;
 791 #endif
 792   case vmIntrinsics::_copyOf:
 793   case vmIntrinsics::_copyOfRange:
 794     // These intrinsics use both the objectcopy and the arraycopy
 795     // intrinsic mechanism.
 796     if (!InlineObjectCopy || !InlineArrayCopy) return true;
 797     break;
 798   case vmIntrinsics::_compareToL:
 799   case vmIntrinsics::_compareToU:
 800   case vmIntrinsics::_compareToLU:
 801   case vmIntrinsics::_compareToUL:
 802     if (!SpecialStringCompareTo) return true;
 803     break;
 804   case vmIntrinsics::_indexOfL:
 805   case vmIntrinsics::_indexOfU:
 806   case vmIntrinsics::_indexOfUL:
 807   case vmIntrinsics::_indexOfIL:
 808   case vmIntrinsics::_indexOfIU:
 809   case vmIntrinsics::_indexOfIUL:
 810   case vmIntrinsics::_indexOfU_char:
 811     if (!SpecialStringIndexOf) return true;
 812     break;
 813   case vmIntrinsics::_equalsL:
 814   case vmIntrinsics::_equalsU:
 815     if (!SpecialStringEquals) return true;
 816     break;
 817   case vmIntrinsics::_equalsB:
 818   case vmIntrinsics::_equalsC:
 819     if (!SpecialArraysEquals) return true;
 820     break;
 821   case vmIntrinsics::_encodeISOArray:
 822   case vmIntrinsics::_encodeByteISOArray:
 823     if (!SpecialEncodeISOArray) return true;
 824     break;
 825   case vmIntrinsics::_getCallerClass:
 826     if (!InlineReflectionGetCallerClass) return true;
 827     break;
 828   case vmIntrinsics::_multiplyToLen:
 829     if (!UseMultiplyToLenIntrinsic) return true;
 830     break;
 831   case vmIntrinsics::_squareToLen:
 832     if (!UseSquareToLenIntrinsic) return true;
 833     break;
 834   case vmIntrinsics::_mulAdd:
 835     if (!UseMulAddIntrinsic) return true;
 836     break;
 837   case vmIntrinsics::_montgomeryMultiply:
 838     if (!UseMontgomeryMultiplyIntrinsic) return true;
 839     break;
 840   case vmIntrinsics::_montgomerySquare:
 841     if (!UseMontgomerySquareIntrinsic) return true;
 842     break;
 843   case vmIntrinsics::_addExactI:
 844   case vmIntrinsics::_addExactL:
 845   case vmIntrinsics::_decrementExactI:
 846   case vmIntrinsics::_decrementExactL:
 847   case vmIntrinsics::_incrementExactI:
 848   case vmIntrinsics::_incrementExactL:
 849   case vmIntrinsics::_multiplyExactI:
 850   case vmIntrinsics::_multiplyExactL:
 851   case vmIntrinsics::_negateExactI:
 852   case vmIntrinsics::_negateExactL:
 853   case vmIntrinsics::_subtractExactI:
 854   case vmIntrinsics::_subtractExactL:
 855     if (!UseMathExactIntrinsics || !InlineMathNatives) return true;
 856     break;
 857   case vmIntrinsics::_isDigit:
 858   case vmIntrinsics::_isLowerCase:
 859   case vmIntrinsics::_isUpperCase:
 860   case vmIntrinsics::_isWhitespace:
 861     if (!UseCharacterCompareIntrinsics) return true;
 862     break;
 863 #endif // COMPILER2
 864   default:
 865     return false;
 866   }
 867 
 868   return false;
 869 }
 870 
 871 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0"
 872 static const char* vm_intrinsic_name_bodies =
 873   VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE,
 874                    VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
 875 
 876 static const char* vm_intrinsic_name_table[vmIntrinsics::ID_LIMIT];
 877 
 878 const char* vmIntrinsics::name_at(vmIntrinsics::ID id) {
 879   const char** nt = &vm_intrinsic_name_table[0];
 880   if (nt[_none] == NULL) {
 881     char* string = (char*) &vm_intrinsic_name_bodies[0];
 882     for (int index = FIRST_ID; index < ID_LIMIT; index++) {
 883       nt[index] = string;
 884       string += strlen(string); // skip string body
 885       string += 1;              // skip trailing null
 886     }
 887     assert(!strcmp(nt[_hashCode], "_hashCode"), "lined up");
 888     nt[_none] = "_none";
 889   }
 890   if ((uint)id < (uint)ID_LIMIT)
 891     return vm_intrinsic_name_table[(uint)id];
 892   else
 893     return "(unknown intrinsic)";
 894 }
 895 
 896 // These are flag-matching functions:
 897 inline bool match_F_R(jshort flags) {
 898   const int req = 0;
 899   const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
 900   return (flags & (req | neg)) == req;
 901 }
 902 inline bool match_F_Y(jshort flags) {
 903   const int req = JVM_ACC_SYNCHRONIZED;
 904   const int neg = JVM_ACC_STATIC;
 905   return (flags & (req | neg)) == req;
 906 }
 907 inline bool match_F_RN(jshort flags) {
 908   const int req = JVM_ACC_NATIVE;
 909   const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED;
 910   return (flags & (req | neg)) == req;
 911 }
 912 inline bool match_F_S(jshort flags) {
 913   const int req = JVM_ACC_STATIC;
 914   const int neg = JVM_ACC_SYNCHRONIZED;
 915   return (flags & (req | neg)) == req;
 916 }
 917 inline bool match_F_SN(jshort flags) {
 918   const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE;
 919   const int neg = JVM_ACC_SYNCHRONIZED;
 920   return (flags & (req | neg)) == req;
 921 }
 922 inline bool match_F_RNY(jshort flags) {
 923   const int req = JVM_ACC_NATIVE | JVM_ACC_SYNCHRONIZED;
 924   const int neg = JVM_ACC_STATIC;
 925   return (flags & (req | neg)) == req;
 926 }
 927 
 928 // These are for forming case labels:
 929 #define ID3(x, y, z) (( jlong)(z) +                                  \
 930                       ((jlong)(y) <<    vmSymbols::log2_SID_LIMIT) + \
 931                       ((jlong)(x) << (2*vmSymbols::log2_SID_LIMIT))  )
 932 #define SID_ENUM(n) vmSymbols::VM_SYMBOL_ENUM_NAME(n)
 933 
 934 vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbols::SID holder,
 935                                             vmSymbols::SID name,
 936                                             vmSymbols::SID sig,
 937                                             jshort flags) {
 938   assert((int)vmSymbols::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit");
 939 
 940   // Let the C compiler build the decision tree.
 941 
 942 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \
 943   case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \
 944     if (!match_##fcode(flags))  break; \
 945     return id;
 946 
 947   switch (ID3(holder, name, sig)) {
 948     VM_INTRINSICS_DO(VM_INTRINSIC_CASE,
 949                      VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
 950   }
 951   return vmIntrinsics::_none;
 952 
 953 #undef VM_INTRINSIC_CASE
 954 }
 955 
 956 
 957 const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) {
 958   const char* str = name_at(id);
 959 #ifndef PRODUCT
 960   const char* kname = vmSymbols::name_for(class_for(id));
 961   const char* mname = vmSymbols::name_for(name_for(id));
 962   const char* sname = vmSymbols::name_for(signature_for(id));
 963   const char* fname = "";
 964   switch (flags_for(id)) {
 965   case F_Y:  fname = "synchronized ";  break;
 966   case F_RN: fname = "native ";        break;
 967   case F_SN: fname = "native static "; break;
 968   case F_S:  fname = "static ";        break;
 969   case F_RNY:fname = "native synchronized "; break;
 970   default:   break;
 971   }
 972   const char* kptr = strrchr(kname, '/');
 973   if (kptr != NULL)  kname = kptr + 1;
 974   int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s",
 975                          str, fname, kname, mname, sname);
 976   if (len < buflen)
 977     str = buf;
 978 #endif //PRODUCT
 979   return str;
 980 }
 981 
 982 
 983 // These are to get information about intrinsics.
 984 
 985 #define ID4(x, y, z, f) ((ID3(x, y, z) << vmIntrinsics::log2_FLAG_LIMIT) | (jlong) (f))
 986 
 987 static const jlong intrinsic_info_array[vmIntrinsics::ID_LIMIT+1] = {
 988 #define VM_INTRINSIC_INFO(ignore_id, klass, name, sig, fcode) \
 989   ID4(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig), vmIntrinsics::fcode),
 990 
 991   0, VM_INTRINSICS_DO(VM_INTRINSIC_INFO,
 992                      VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE)
 993     0
 994 #undef VM_INTRINSIC_INFO
 995 };
 996 
 997 inline jlong intrinsic_info(vmIntrinsics::ID id) {
 998   return intrinsic_info_array[vmIntrinsics::ID_from((int)id)];
 999 }
1000 
1001 vmSymbols::SID vmIntrinsics::class_for(vmIntrinsics::ID id) {
1002   jlong info = intrinsic_info(id);
1003   int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
1004   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1021, "");
1005   return vmSymbols::SID( (info >> shift) & mask );
1006 }
1007 
1008 vmSymbols::SID vmIntrinsics::name_for(vmIntrinsics::ID id) {
1009   jlong info = intrinsic_info(id);
1010   int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
1011   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1022, "");
1012   return vmSymbols::SID( (info >> shift) & mask );
1013 }
1014 
1015 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
1016   jlong info = intrinsic_info(id);
1017   int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
1018   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, "");
1019   return vmSymbols::SID( (info >> shift) & mask );
1020 }
1021 
1022 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
1023   jlong info = intrinsic_info(id);
1024   int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT);
1025   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, "");
1026   return Flags( (info >> shift) & mask );
1027 }
1028 
1029 
1030 #ifndef PRODUCT
1031 // verify_method performs an extra check on a matched intrinsic method
1032 
1033 static bool match_method(Method* m, Symbol* n, Symbol* s) {
1034   return (m->name() == n &&
1035           m->signature() == s);
1036 }
1037 
1038 static vmIntrinsics::ID match_method_with_klass(Method* m, Symbol* mk) {
1039 #define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \
1040   { Symbol* k = vmSymbols::klassname(); \
1041     if (mk == k) { \
1042       Symbol* n = vmSymbols::namepart(); \
1043       Symbol* s = vmSymbols::sigpart(); \
1044       if (match_method(m, n, s)) \
1045         return vmIntrinsics::id; \
1046     } }
1047   VM_INTRINSICS_DO(VM_INTRINSIC_MATCH,
1048                    VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
1049   return vmIntrinsics::_none;
1050 #undef VM_INTRINSIC_MATCH
1051 }
1052 
1053 void vmIntrinsics::verify_method(ID actual_id, Method* m) {
1054   Symbol* mk = m->method_holder()->name();
1055   ID declared_id = match_method_with_klass(m, mk);
1056 
1057   if (declared_id == actual_id)  return; // success
1058 
1059   if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) {
1060     // Here are a few special cases in StrictMath not declared in vmSymbols.hpp.
1061     switch (actual_id) {
1062     case _min:
1063     case _max:
1064     case _dsqrt:
1065       declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math());
1066       if (declared_id == actual_id)  return; // acceptable alias
1067       break;
1068     default:
1069         break;
1070     }
1071   }
1072 
1073   const char* declared_name = name_at(declared_id);
1074   const char* actual_name   = name_at(actual_id);
1075   methodHandle mh = m;
1076   m = NULL;
1077   ttyLocker ttyl;
1078   if (xtty != NULL) {
1079     xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'",
1080                      actual_name, declared_name);
1081     xtty->method(mh);
1082     xtty->end_elem("%s", "");
1083   }
1084   if (PrintMiscellaneous && (WizardMode || Verbose)) {
1085     tty->print_cr("*** misidentified method; %s(%d) should be %s(%d):",
1086                   declared_name, declared_id, actual_name, actual_id);
1087     mh()->print_short_name(tty);
1088     tty->cr();
1089   }
1090 }
1091 #endif //PRODUCT