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