1 /* 2 * Copyright (c) 2020, 2025, 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 "classfile/vmIntrinsics.hpp" 26 #include "classfile/vmSymbols.hpp" 27 #include "compiler/compilerDirectives.hpp" 28 #include "jvm_constants.h" 29 #include "jvm_io.h" 30 #ifdef COMPILER2 31 #include "opto/c2_globals.hpp" 32 #endif 33 #include "runtime/vm_version.hpp" 34 #include "utilities/checkedCast.hpp" 35 #include "utilities/tribool.hpp" 36 37 // These are flag-matching functions: 38 inline bool match_F_R(u2 flags) { 39 const int req = 0; 40 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED | JVM_ACC_NATIVE; 41 return (flags & (req | neg)) == req; 42 } 43 44 inline bool match_F_Y(u2 flags) { 45 const int req = JVM_ACC_SYNCHRONIZED; 46 const int neg = JVM_ACC_STATIC | JVM_ACC_NATIVE; 47 return (flags & (req | neg)) == req; 48 } 49 50 inline bool match_F_RN(u2 flags) { 51 const int req = JVM_ACC_NATIVE; 52 const int neg = JVM_ACC_STATIC | JVM_ACC_SYNCHRONIZED; 53 return (flags & (req | neg)) == req; 54 } 55 56 inline bool match_F_S(u2 flags) { 57 const int req = JVM_ACC_STATIC; 58 const int neg = JVM_ACC_SYNCHRONIZED | JVM_ACC_NATIVE; 59 return (flags & (req | neg)) == req; 60 } 61 62 inline bool match_F_SN(u2 flags) { 63 const int req = JVM_ACC_STATIC | JVM_ACC_NATIVE; 64 const int neg = JVM_ACC_SYNCHRONIZED; 65 return (flags & (req | neg)) == req; 66 } 67 68 bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) { 69 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 70 switch(id) { 71 #ifdef JFR_HAVE_INTRINSICS 72 case vmIntrinsics::_counterTime: 73 #endif 74 case vmIntrinsics::_currentTimeMillis: 75 case vmIntrinsics::_nanoTime: 76 case vmIntrinsics::_floatToRawIntBits: 77 case vmIntrinsics::_intBitsToFloat: 78 case vmIntrinsics::_doubleToRawLongBits: 79 case vmIntrinsics::_longBitsToDouble: 80 case vmIntrinsics::_getClass: 81 case vmIntrinsics::_isInstance: 82 case vmIntrinsics::_currentCarrierThread: 83 case vmIntrinsics::_currentThread: 84 case vmIntrinsics::_scopedValueCache: 85 case vmIntrinsics::_dabs: 86 case vmIntrinsics::_fabs: 87 case vmIntrinsics::_iabs: 88 case vmIntrinsics::_labs: 89 case vmIntrinsics::_dsqrt: 90 case vmIntrinsics::_dsqrt_strict: 91 case vmIntrinsics::_dsin: 92 case vmIntrinsics::_dcos: 93 case vmIntrinsics::_dtan: 94 case vmIntrinsics::_dtanh: 95 case vmIntrinsics::_dlog: 96 case vmIntrinsics::_dlog10: 97 case vmIntrinsics::_dexp: 98 case vmIntrinsics::_dpow: 99 case vmIntrinsics::_Preconditions_checkIndex: 100 case vmIntrinsics::_Preconditions_checkLongIndex: 101 case vmIntrinsics::_Reference_get: 102 case vmIntrinsics::_Continuation_doYield: 103 case vmIntrinsics::_updateCRC32: 104 case vmIntrinsics::_updateBytesCRC32: 105 case vmIntrinsics::_updateByteBufferCRC32: 106 case vmIntrinsics::_updateBytesAdler32: 107 case vmIntrinsics::_vectorizedMismatch: 108 case vmIntrinsics::_fmaD: 109 case vmIntrinsics::_fmaF: 110 case vmIntrinsics::_isDigit: 111 case vmIntrinsics::_isLowerCase: 112 case vmIntrinsics::_isUpperCase: 113 case vmIntrinsics::_isWhitespace: 114 return true; 115 default: 116 return false; 117 } 118 } 119 120 bool vmIntrinsics::can_trap(vmIntrinsics::ID id) { 121 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 122 switch(id) { 123 #ifdef JFR_HAVE_INTRINSICS 124 case vmIntrinsics::_counterTime: 125 #endif 126 case vmIntrinsics::_currentTimeMillis: 127 case vmIntrinsics::_nanoTime: 128 case vmIntrinsics::_floatToRawIntBits: 129 case vmIntrinsics::_intBitsToFloat: 130 case vmIntrinsics::_doubleToRawLongBits: 131 case vmIntrinsics::_longBitsToDouble: 132 case vmIntrinsics::_currentCarrierThread: 133 case vmIntrinsics::_currentThread: 134 case vmIntrinsics::_setCurrentThread: 135 case vmIntrinsics::_scopedValueCache: 136 case vmIntrinsics::_setScopedValueCache: 137 case vmIntrinsics::_dabs: 138 case vmIntrinsics::_fabs: 139 case vmIntrinsics::_iabs: 140 case vmIntrinsics::_labs: 141 case vmIntrinsics::_dsqrt: 142 case vmIntrinsics::_dsqrt_strict: 143 case vmIntrinsics::_dsin: 144 case vmIntrinsics::_dcos: 145 case vmIntrinsics::_dtan: 146 case vmIntrinsics::_dtanh: 147 case vmIntrinsics::_dlog: 148 case vmIntrinsics::_dlog10: 149 case vmIntrinsics::_dexp: 150 case vmIntrinsics::_dpow: 151 case vmIntrinsics::_updateCRC32: 152 case vmIntrinsics::_updateBytesCRC32: 153 case vmIntrinsics::_updateByteBufferCRC32: 154 case vmIntrinsics::_vectorizedMismatch: 155 case vmIntrinsics::_fmaD: 156 case vmIntrinsics::_fmaF: 157 return false; 158 default: 159 return true; 160 } 161 } 162 163 // Some intrinsics produce different results if they are not pinned 164 bool vmIntrinsics::should_be_pinned(vmIntrinsics::ID id) { 165 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 166 switch(id) { 167 #ifdef JFR_HAVE_INTRINSICS 168 case vmIntrinsics::_counterTime: 169 #endif 170 case vmIntrinsics::_currentTimeMillis: 171 case vmIntrinsics::_nanoTime: 172 case vmIntrinsics::_blackhole: 173 return true; 174 default: 175 return false; 176 } 177 } 178 179 bool vmIntrinsics::does_virtual_dispatch(vmIntrinsics::ID id) { 180 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 181 switch(id) { 182 case vmIntrinsics::_hashCode: 183 case vmIntrinsics::_clone: 184 return true; 185 break; 186 default: 187 return false; 188 } 189 } 190 191 int vmIntrinsics::predicates_needed(vmIntrinsics::ID id) { 192 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 193 switch (id) { 194 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 195 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 196 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 197 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 198 case vmIntrinsics::_counterMode_AESCrypt: 199 case vmIntrinsics::_galoisCounterMode_AESCrypt: 200 return 1; 201 case vmIntrinsics::_digestBase_implCompressMB: 202 return 5; 203 default: 204 return 0; 205 } 206 } 207 208 bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) { 209 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 210 211 // -XX:-InlineNatives disables nearly all intrinsics except the ones listed in 212 // the following switch statement. 213 if (!InlineNatives) { 214 switch (id) { 215 case vmIntrinsics::_indexOfL: 216 case vmIntrinsics::_indexOfU: 217 case vmIntrinsics::_indexOfUL: 218 case vmIntrinsics::_indexOfIL: 219 case vmIntrinsics::_indexOfIU: 220 case vmIntrinsics::_indexOfIUL: 221 case vmIntrinsics::_indexOfU_char: 222 case vmIntrinsics::_indexOfL_char: 223 case vmIntrinsics::_compareToL: 224 case vmIntrinsics::_compareToU: 225 case vmIntrinsics::_compareToLU: 226 case vmIntrinsics::_compareToUL: 227 case vmIntrinsics::_equalsL: 228 case vmIntrinsics::_equalsC: 229 case vmIntrinsics::_vectorizedHashCode: 230 case vmIntrinsics::_getCharStringU: 231 case vmIntrinsics::_putCharStringU: 232 case vmIntrinsics::_compressStringC: 233 case vmIntrinsics::_compressStringB: 234 case vmIntrinsics::_inflateStringC: 235 case vmIntrinsics::_inflateStringB: 236 case vmIntrinsics::_getAndAddInt: 237 case vmIntrinsics::_getAndAddLong: 238 case vmIntrinsics::_getAndSetInt: 239 case vmIntrinsics::_getAndSetLong: 240 case vmIntrinsics::_getAndSetReference: 241 case vmIntrinsics::_loadFence: 242 case vmIntrinsics::_storeFence: 243 case vmIntrinsics::_fullFence: 244 case vmIntrinsics::_countPositives: 245 case vmIntrinsics::_Reference_get: 246 case vmIntrinsics::_Continuation_doYield: 247 case vmIntrinsics::_Continuation_enterSpecial: 248 case vmIntrinsics::_Continuation_pin: 249 case vmIntrinsics::_Continuation_unpin: 250 break; 251 default: 252 return true; 253 } 254 } 255 256 switch (id) { 257 case vmIntrinsics::_isInstance: 258 case vmIntrinsics::_isAssignableFrom: 259 case vmIntrinsics::_isHidden: 260 case vmIntrinsics::_getSuperclass: 261 case vmIntrinsics::_Class_cast: 262 case vmIntrinsics::_getLength: 263 case vmIntrinsics::_newArray: 264 case vmIntrinsics::_newNullRestrictedArray: 265 case vmIntrinsics::_newNullRestrictedAtomicArray: 266 case vmIntrinsics::_newNullableAtomicArray: 267 case vmIntrinsics::_getClass: 268 if (!InlineClassNatives) return true; 269 break; 270 case vmIntrinsics::_currentCarrierThread: 271 case vmIntrinsics::_currentThread: 272 if (!InlineThreadNatives) return true; 273 break; 274 case vmIntrinsics::_setCurrentThread: 275 case vmIntrinsics::_scopedValueCache: 276 case vmIntrinsics::_setScopedValueCache: 277 case vmIntrinsics::_floatToRawIntBits: 278 case vmIntrinsics::_intBitsToFloat: 279 case vmIntrinsics::_doubleToRawLongBits: 280 case vmIntrinsics::_longBitsToDouble: 281 case vmIntrinsics::_ceil: 282 case vmIntrinsics::_floor: 283 case vmIntrinsics::_rint: 284 case vmIntrinsics::_dabs: 285 case vmIntrinsics::_fabs: 286 case vmIntrinsics::_iabs: 287 case vmIntrinsics::_labs: 288 case vmIntrinsics::_dsqrt: 289 case vmIntrinsics::_dsqrt_strict: 290 case vmIntrinsics::_dsin: 291 case vmIntrinsics::_dcos: 292 case vmIntrinsics::_dtan: 293 case vmIntrinsics::_dtanh: 294 case vmIntrinsics::_dlog: 295 case vmIntrinsics::_dexp: 296 case vmIntrinsics::_dpow: 297 case vmIntrinsics::_dlog10: 298 case vmIntrinsics::_datan2: 299 case vmIntrinsics::_floatToIntBits: 300 case vmIntrinsics::_doubleToLongBits: 301 case vmIntrinsics::_min: 302 case vmIntrinsics::_max: 303 case vmIntrinsics::_maxF: 304 case vmIntrinsics::_minF: 305 case vmIntrinsics::_maxD: 306 case vmIntrinsics::_minD: 307 case vmIntrinsics::_min_strict: 308 case vmIntrinsics::_max_strict: 309 case vmIntrinsics::_maxF_strict: 310 case vmIntrinsics::_minF_strict: 311 case vmIntrinsics::_maxD_strict: 312 case vmIntrinsics::_minD_strict: 313 if (!InlineMathNatives) return true; 314 break; 315 case vmIntrinsics::_fmaD: 316 case vmIntrinsics::_fmaF: 317 if (!InlineMathNatives || !UseFMA) return true; 318 break; 319 case vmIntrinsics::_floatToFloat16: 320 case vmIntrinsics::_float16ToFloat: 321 if (!InlineIntrinsics) return true; 322 break; 323 case vmIntrinsics::_arraycopy: 324 if (!InlineArrayCopy) return true; 325 break; 326 case vmIntrinsics::_updateCRC32: 327 case vmIntrinsics::_updateBytesCRC32: 328 case vmIntrinsics::_updateByteBufferCRC32: 329 if (!UseCRC32Intrinsics) return true; 330 break; 331 case vmIntrinsics::_makePrivateBuffer: 332 case vmIntrinsics::_finishPrivateBuffer: 333 case vmIntrinsics::_getReference: 334 case vmIntrinsics::_getBoolean: 335 case vmIntrinsics::_getByte: 336 case vmIntrinsics::_getShort: 337 case vmIntrinsics::_getChar: 338 case vmIntrinsics::_getInt: 339 case vmIntrinsics::_getLong: 340 case vmIntrinsics::_getFloat: 341 case vmIntrinsics::_getDouble: 342 case vmIntrinsics::_getValue: 343 case vmIntrinsics::_putReference: 344 case vmIntrinsics::_putBoolean: 345 case vmIntrinsics::_putByte: 346 case vmIntrinsics::_putShort: 347 case vmIntrinsics::_putChar: 348 case vmIntrinsics::_putInt: 349 case vmIntrinsics::_putLong: 350 case vmIntrinsics::_putFloat: 351 case vmIntrinsics::_putDouble: 352 case vmIntrinsics::_putValue: 353 case vmIntrinsics::_getReferenceVolatile: 354 case vmIntrinsics::_getBooleanVolatile: 355 case vmIntrinsics::_getByteVolatile: 356 case vmIntrinsics::_getShortVolatile: 357 case vmIntrinsics::_getCharVolatile: 358 case vmIntrinsics::_getIntVolatile: 359 case vmIntrinsics::_getLongVolatile: 360 case vmIntrinsics::_getFloatVolatile: 361 case vmIntrinsics::_getDoubleVolatile: 362 case vmIntrinsics::_putReferenceVolatile: 363 case vmIntrinsics::_putBooleanVolatile: 364 case vmIntrinsics::_putByteVolatile: 365 case vmIntrinsics::_putShortVolatile: 366 case vmIntrinsics::_putCharVolatile: 367 case vmIntrinsics::_putIntVolatile: 368 case vmIntrinsics::_putLongVolatile: 369 case vmIntrinsics::_putFloatVolatile: 370 case vmIntrinsics::_putDoubleVolatile: 371 case vmIntrinsics::_getReferenceAcquire: 372 case vmIntrinsics::_getBooleanAcquire: 373 case vmIntrinsics::_getByteAcquire: 374 case vmIntrinsics::_getShortAcquire: 375 case vmIntrinsics::_getCharAcquire: 376 case vmIntrinsics::_getIntAcquire: 377 case vmIntrinsics::_getLongAcquire: 378 case vmIntrinsics::_getFloatAcquire: 379 case vmIntrinsics::_getDoubleAcquire: 380 case vmIntrinsics::_putReferenceRelease: 381 case vmIntrinsics::_putBooleanRelease: 382 case vmIntrinsics::_putByteRelease: 383 case vmIntrinsics::_putShortRelease: 384 case vmIntrinsics::_putCharRelease: 385 case vmIntrinsics::_putIntRelease: 386 case vmIntrinsics::_putLongRelease: 387 case vmIntrinsics::_putFloatRelease: 388 case vmIntrinsics::_putDoubleRelease: 389 case vmIntrinsics::_getReferenceOpaque: 390 case vmIntrinsics::_getBooleanOpaque: 391 case vmIntrinsics::_getByteOpaque: 392 case vmIntrinsics::_getShortOpaque: 393 case vmIntrinsics::_getCharOpaque: 394 case vmIntrinsics::_getIntOpaque: 395 case vmIntrinsics::_getLongOpaque: 396 case vmIntrinsics::_getFloatOpaque: 397 case vmIntrinsics::_getDoubleOpaque: 398 case vmIntrinsics::_putReferenceOpaque: 399 case vmIntrinsics::_putBooleanOpaque: 400 case vmIntrinsics::_putByteOpaque: 401 case vmIntrinsics::_putShortOpaque: 402 case vmIntrinsics::_putCharOpaque: 403 case vmIntrinsics::_putIntOpaque: 404 case vmIntrinsics::_putLongOpaque: 405 case vmIntrinsics::_putFloatOpaque: 406 case vmIntrinsics::_putDoubleOpaque: 407 case vmIntrinsics::_getAndAddInt: 408 case vmIntrinsics::_getAndAddLong: 409 case vmIntrinsics::_getAndSetInt: 410 case vmIntrinsics::_getAndSetLong: 411 case vmIntrinsics::_getAndSetReference: 412 case vmIntrinsics::_loadFence: 413 case vmIntrinsics::_storeFence: 414 case vmIntrinsics::_fullFence: 415 case vmIntrinsics::_compareAndSetLong: 416 case vmIntrinsics::_weakCompareAndSetLong: 417 case vmIntrinsics::_weakCompareAndSetLongPlain: 418 case vmIntrinsics::_weakCompareAndSetLongAcquire: 419 case vmIntrinsics::_weakCompareAndSetLongRelease: 420 case vmIntrinsics::_compareAndSetInt: 421 case vmIntrinsics::_weakCompareAndSetInt: 422 case vmIntrinsics::_weakCompareAndSetIntPlain: 423 case vmIntrinsics::_weakCompareAndSetIntAcquire: 424 case vmIntrinsics::_weakCompareAndSetIntRelease: 425 case vmIntrinsics::_compareAndSetReference: 426 case vmIntrinsics::_weakCompareAndSetReference: 427 case vmIntrinsics::_weakCompareAndSetReferencePlain: 428 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: 429 case vmIntrinsics::_weakCompareAndSetReferenceRelease: 430 case vmIntrinsics::_compareAndExchangeInt: 431 case vmIntrinsics::_compareAndExchangeIntAcquire: 432 case vmIntrinsics::_compareAndExchangeIntRelease: 433 case vmIntrinsics::_compareAndExchangeLong: 434 case vmIntrinsics::_compareAndExchangeLongAcquire: 435 case vmIntrinsics::_compareAndExchangeLongRelease: 436 case vmIntrinsics::_compareAndExchangeReference: 437 case vmIntrinsics::_compareAndExchangeReferenceAcquire: 438 case vmIntrinsics::_compareAndExchangeReferenceRelease: 439 case vmIntrinsics::_allocateInstance: 440 if (!InlineUnsafeOps) return true; 441 break; 442 case vmIntrinsics::_getShortUnaligned: 443 case vmIntrinsics::_getCharUnaligned: 444 case vmIntrinsics::_getIntUnaligned: 445 case vmIntrinsics::_getLongUnaligned: 446 case vmIntrinsics::_putShortUnaligned: 447 case vmIntrinsics::_putCharUnaligned: 448 case vmIntrinsics::_putIntUnaligned: 449 case vmIntrinsics::_putLongUnaligned: 450 if (!InlineUnsafeOps || !UseUnalignedAccesses) return true; 451 break; 452 case vmIntrinsics::_hashCode: 453 if (!InlineObjectHash) return true; 454 break; 455 case vmIntrinsics::_aescrypt_encryptBlock: 456 case vmIntrinsics::_aescrypt_decryptBlock: 457 if (!UseAESIntrinsics) return true; 458 break; 459 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 460 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 461 if (!UseAESIntrinsics) return true; 462 break; 463 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 464 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 465 if (!UseAESIntrinsics) return true; 466 break; 467 case vmIntrinsics::_counterMode_AESCrypt: 468 if (!UseAESCTRIntrinsics) return true; 469 break; 470 case vmIntrinsics::_galoisCounterMode_AESCrypt: 471 if (!UseAESIntrinsics) return true; 472 break; 473 case vmIntrinsics::_md5_implCompress: 474 if (!UseMD5Intrinsics) return true; 475 break; 476 case vmIntrinsics::_sha_implCompress: 477 if (!UseSHA1Intrinsics) return true; 478 break; 479 case vmIntrinsics::_sha2_implCompress: 480 if (!UseSHA256Intrinsics) return true; 481 break; 482 case vmIntrinsics::_sha5_implCompress: 483 if (!UseSHA512Intrinsics) return true; 484 break; 485 case vmIntrinsics::_double_keccak: 486 case vmIntrinsics::_sha3_implCompress: 487 if (!UseSHA3Intrinsics) return true; 488 break; 489 case vmIntrinsics::_digestBase_implCompressMB: 490 if (!(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics)) return true; 491 break; 492 case vmIntrinsics::_ghash_processBlocks: 493 if (!UseGHASHIntrinsics) return true; 494 break; 495 case vmIntrinsics::_chacha20Block: 496 if (!UseChaCha20Intrinsics) return true; 497 break; 498 case vmIntrinsics::_dilithiumAlmostNtt: 499 case vmIntrinsics::_dilithiumAlmostInverseNtt: 500 case vmIntrinsics::_dilithiumNttMult: 501 case vmIntrinsics::_dilithiumMontMulByConstant: 502 case vmIntrinsics::_dilithiumDecomposePoly: 503 if (!UseDilithiumIntrinsics) return true; 504 break; 505 case vmIntrinsics::_base64_encodeBlock: 506 case vmIntrinsics::_base64_decodeBlock: 507 if (!UseBASE64Intrinsics) return true; 508 break; 509 case vmIntrinsics::_poly1305_processBlocks: 510 if (!UsePoly1305Intrinsics) return true; 511 break; 512 case vmIntrinsics::_intpoly_montgomeryMult_P256: 513 case vmIntrinsics::_intpoly_assign: 514 if (!UseIntPolyIntrinsics) return true; 515 break; 516 case vmIntrinsics::_updateBytesCRC32C: 517 case vmIntrinsics::_updateDirectByteBufferCRC32C: 518 if (!UseCRC32CIntrinsics) return true; 519 break; 520 case vmIntrinsics::_vectorizedMismatch: 521 if (!UseVectorizedMismatchIntrinsic) return true; 522 break; 523 case vmIntrinsics::_updateBytesAdler32: 524 case vmIntrinsics::_updateByteBufferAdler32: 525 if (!UseAdler32Intrinsics) return true; 526 break; 527 case vmIntrinsics::_copyMemory: 528 if (!InlineArrayCopy || !InlineUnsafeOps) return true; 529 break; 530 case vmIntrinsics::_setMemory: 531 if (!InlineUnsafeOps) return true; 532 break; 533 #ifdef COMPILER2 534 case vmIntrinsics::_clone: 535 case vmIntrinsics::_copyOf: 536 case vmIntrinsics::_copyOfRange: 537 // These intrinsics use both the objectcopy and the arraycopy 538 // intrinsic mechanism. 539 if (!InlineObjectCopy || !InlineArrayCopy) return true; 540 break; 541 case vmIntrinsics::_compareToL: 542 case vmIntrinsics::_compareToU: 543 case vmIntrinsics::_compareToLU: 544 case vmIntrinsics::_compareToUL: 545 if (!SpecialStringCompareTo) return true; 546 break; 547 case vmIntrinsics::_indexOfL: 548 case vmIntrinsics::_indexOfU: 549 case vmIntrinsics::_indexOfUL: 550 case vmIntrinsics::_indexOfIL: 551 case vmIntrinsics::_indexOfIU: 552 case vmIntrinsics::_indexOfIUL: 553 case vmIntrinsics::_indexOfU_char: 554 case vmIntrinsics::_indexOfL_char: 555 if (!SpecialStringIndexOf) return true; 556 break; 557 case vmIntrinsics::_equalsL: 558 if (!SpecialStringEquals) return true; 559 break; 560 case vmIntrinsics::_vectorizedHashCode: 561 if (!UseVectorizedHashCodeIntrinsic) return true; 562 break; 563 case vmIntrinsics::_equalsB: 564 case vmIntrinsics::_equalsC: 565 if (!SpecialArraysEquals) return true; 566 break; 567 case vmIntrinsics::_encodeISOArray: 568 case vmIntrinsics::_encodeAsciiArray: 569 case vmIntrinsics::_encodeByteISOArray: 570 if (!SpecialEncodeISOArray) return true; 571 break; 572 case vmIntrinsics::_getCallerClass: 573 if (!InlineReflectionGetCallerClass) return true; 574 break; 575 case vmIntrinsics::_multiplyToLen: 576 if (!UseMultiplyToLenIntrinsic) return true; 577 break; 578 case vmIntrinsics::_squareToLen: 579 if (!UseSquareToLenIntrinsic) return true; 580 break; 581 case vmIntrinsics::_mulAdd: 582 if (!UseMulAddIntrinsic) return true; 583 break; 584 case vmIntrinsics::_montgomeryMultiply: 585 if (!UseMontgomeryMultiplyIntrinsic) return true; 586 break; 587 case vmIntrinsics::_montgomerySquare: 588 if (!UseMontgomerySquareIntrinsic) return true; 589 break; 590 case vmIntrinsics::_bigIntegerRightShiftWorker: 591 case vmIntrinsics::_bigIntegerLeftShiftWorker: 592 break; 593 case vmIntrinsics::_addExactI: 594 case vmIntrinsics::_addExactL: 595 case vmIntrinsics::_decrementExactI: 596 case vmIntrinsics::_decrementExactL: 597 case vmIntrinsics::_incrementExactI: 598 case vmIntrinsics::_incrementExactL: 599 case vmIntrinsics::_multiplyExactI: 600 case vmIntrinsics::_multiplyExactL: 601 case vmIntrinsics::_negateExactI: 602 case vmIntrinsics::_negateExactL: 603 case vmIntrinsics::_subtractExactI: 604 case vmIntrinsics::_subtractExactL: 605 if (!UseMathExactIntrinsics || !InlineMathNatives) return true; 606 break; 607 case vmIntrinsics::_isDigit: 608 case vmIntrinsics::_isLowerCase: 609 case vmIntrinsics::_isUpperCase: 610 case vmIntrinsics::_isWhitespace: 611 if (!UseCharacterCompareIntrinsics) return true; 612 break; 613 case vmIntrinsics::_dcopySign: 614 case vmIntrinsics::_fcopySign: 615 if (!InlineMathNatives || !UseCopySignIntrinsic) return true; 616 break; 617 case vmIntrinsics::_dsignum: 618 case vmIntrinsics::_fsignum: 619 if (!InlineMathNatives || !UseSignumIntrinsic) return true; 620 break; 621 #endif // COMPILER2 622 default: 623 return false; 624 } 625 626 return false; 627 } 628 629 #define VM_INTRINSIC_INITIALIZE(id, klass, name, sig, flags) #id "\0" 630 static const char* vm_intrinsic_name_bodies = 631 VM_INTRINSICS_DO(VM_INTRINSIC_INITIALIZE, 632 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 633 634 static const char* vm_intrinsic_name_table[vmIntrinsics::number_of_intrinsics()]; 635 static TriBoolArray<(size_t)vmIntrinsics::number_of_intrinsics(), int> vm_intrinsic_control_words; 636 637 void vmIntrinsics::init_vm_intrinsic_name_table() { 638 const char** nt = &vm_intrinsic_name_table[0]; 639 char* string = (char*) &vm_intrinsic_name_bodies[0]; 640 641 for (auto index : EnumRange<vmIntrinsicID>{}) { 642 nt[as_int(index)] = string; 643 string += strlen(string); // skip string body 644 string += 1; // skip trailing null 645 } 646 assert(!strcmp(nt[as_int(vmIntrinsics::_hashCode)], "_hashCode"), "lined up"); 647 nt[as_int(vmIntrinsics::_none)] = "_none"; 648 } 649 650 const char* vmIntrinsics::name_at(vmIntrinsics::ID id) { 651 const char** nt = &vm_intrinsic_name_table[0]; 652 if (nt[as_int(_none)] == nullptr) { 653 init_vm_intrinsic_name_table(); 654 } 655 656 if (id < ID_LIMIT) 657 return vm_intrinsic_name_table[as_int(id)]; 658 else 659 return "(unknown intrinsic)"; 660 } 661 662 vmIntrinsics::ID vmIntrinsics::find_id(const char* name) { 663 const char** nt = &vm_intrinsic_name_table[0]; 664 if (nt[as_int(_none)] == nullptr) { 665 init_vm_intrinsic_name_table(); 666 } 667 668 for (auto index : EnumRange<vmIntrinsicID>{}) { 669 if (0 == strcmp(name, nt[as_int(index)])) { 670 return index; 671 } 672 } 673 674 return _none; 675 } 676 677 bool vmIntrinsics::is_intrinsic_available(vmIntrinsics::ID id) { 678 return VM_Version::is_intrinsic_supported(id) && !is_disabled_by_flags(id); 679 } 680 681 bool vmIntrinsics::is_disabled_by_flags(vmIntrinsics::ID id) { 682 assert(id > _none && id < ID_LIMIT, "must be a VM intrinsic"); 683 684 // not initialized yet, process Control/DisableIntrinsic 685 if (vm_intrinsic_control_words[as_int(_none)].is_default()) { 686 for (ControlIntrinsicIter iter(ControlIntrinsic); *iter != nullptr; ++iter) { 687 vmIntrinsics::ID id = vmIntrinsics::find_id(*iter); 688 689 if (id != vmIntrinsics::_none) { 690 vm_intrinsic_control_words[as_int(id)] = iter.is_enabled() && !disabled_by_jvm_flags(id); 691 } 692 } 693 694 // Order matters, DisableIntrinsic can overwrite ControlIntrinsic 695 for (ControlIntrinsicIter iter(DisableIntrinsic, true/*disable_all*/); *iter != nullptr; ++iter) { 696 vmIntrinsics::ID id = vmIntrinsics::find_id(*iter); 697 698 if (id != vmIntrinsics::_none) { 699 vm_intrinsic_control_words[as_int(id)] = false; 700 } 701 } 702 703 vm_intrinsic_control_words[as_int(_none)] = true; 704 } 705 706 TriBool b = vm_intrinsic_control_words[as_int(id)]; 707 if (b.is_default()) { 708 // unknown yet, query and cache it 709 b = vm_intrinsic_control_words[as_int(id)] = !disabled_by_jvm_flags(id); 710 } 711 712 return !b; 713 } 714 715 // These are for forming case labels: 716 #define ID3(x, y, z) (( jlong)(z) + \ 717 ((jlong)(y) << vmSymbols::log2_SID_LIMIT) + \ 718 ((jlong)(x) << (2*vmSymbols::log2_SID_LIMIT)) ) 719 #define SID_ENUM(n) VM_SYMBOL_ENUM_NAME(n) 720 721 vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbolID holder, 722 vmSymbolID name, 723 vmSymbolID sig, 724 u2 flags) { 725 assert((int)vmSymbolID::SID_LIMIT <= (1<<vmSymbols::log2_SID_LIMIT), "must fit"); 726 727 // Let the C compiler build the decision tree. 728 729 #define VM_INTRINSIC_CASE(id, klass, name, sig, fcode) \ 730 case ID3(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig)): \ 731 if (!match_##fcode(flags)) break; \ 732 return id; 733 734 switch (ID3(holder, name, sig)) { 735 VM_INTRINSICS_DO(VM_INTRINSIC_CASE, 736 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 737 } 738 return vmIntrinsics::_none; 739 740 #undef VM_INTRINSIC_CASE 741 } 742 743 class vmIntrinsicsLookup { 744 bool _class_map[vmSymbols::number_of_symbols()]; 745 746 constexpr int as_index(vmSymbolID id) const { 747 int index = vmSymbols::as_int(id); 748 assert(0 <= index && index < int(sizeof(_class_map)), "must be"); 749 return index; 750 } 751 752 constexpr void set_class_map(vmSymbolID id) { 753 _class_map[as_index(id)] = true; 754 } 755 756 public: 757 constexpr vmIntrinsicsLookup() : _class_map() { 758 759 #define VM_INTRINSIC_CLASS_MAP(id, klass, name, sig, fcode) \ 760 set_class_map(SID_ENUM(klass)); 761 762 VM_INTRINSICS_DO(VM_INTRINSIC_CLASS_MAP, 763 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE); 764 #undef VM_INTRINSIC_CLASS_MAP 765 766 767 // A few slightly irregular cases. See Method::init_intrinsic_id 768 set_class_map(SID_ENUM(java_lang_StrictMath)); 769 set_class_map(SID_ENUM(java_lang_invoke_MethodHandle)); 770 set_class_map(SID_ENUM(java_lang_invoke_VarHandle)); 771 } 772 773 bool class_has_intrinsics(vmSymbolID holder) const { 774 return _class_map[as_index(holder)]; 775 } 776 }; 777 778 constexpr vmIntrinsicsLookup _intrinsics_lookup; 779 780 bool vmIntrinsics::class_has_intrinsics(vmSymbolID holder) { 781 return _intrinsics_lookup.class_has_intrinsics(holder); 782 } 783 784 const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) { 785 const char* str = name_at(id); 786 #ifndef PRODUCT 787 const char* kname = vmSymbols::name_for(class_for(id)); 788 const char* mname = vmSymbols::name_for(name_for(id)); 789 const char* sname = vmSymbols::name_for(signature_for(id)); 790 const char* fname = ""; 791 switch (flags_for(id)) { 792 case F_Y: fname = "synchronized "; break; 793 case F_RN: fname = "native "; break; 794 case F_SN: fname = "native static "; break; 795 case F_S: fname = "static "; break; 796 default: break; 797 } 798 const char* kptr = strrchr(kname, JVM_SIGNATURE_SLASH); 799 if (kptr != nullptr) kname = kptr + 1; 800 int len = jio_snprintf(buf, buflen, "%s: %s%s.%s%s", 801 str, fname, kname, mname, sname); 802 if (len < buflen) 803 str = buf; 804 #endif //PRODUCT 805 return str; 806 } 807 808 809 // These are to get information about intrinsics. 810 811 #define ID4(x, y, z, f) ((ID3(x, y, z) << vmIntrinsics::log2_FLAG_LIMIT) | (jlong) (f)) 812 813 #ifndef PRODUCT 814 static const jlong intrinsic_info_array[vmIntrinsics::number_of_intrinsics()+1] = { 815 #define VM_INTRINSIC_INFO(ignore_id, klass, name, sig, fcode) \ 816 ID4(SID_ENUM(klass), SID_ENUM(name), SID_ENUM(sig), vmIntrinsics::fcode), 817 818 0, VM_INTRINSICS_DO(VM_INTRINSIC_INFO, 819 VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE) 820 0 821 #undef VM_INTRINSIC_INFO 822 }; 823 824 inline jlong intrinsic_info(vmIntrinsics::ID id) { 825 return intrinsic_info_array[vmIntrinsics::as_int(id)]; 826 } 827 828 vmSymbolID vmIntrinsics::class_for(vmIntrinsics::ID id) { 829 jlong info = intrinsic_info(id); 830 int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 831 assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1021, ""); 832 return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask)); 833 } 834 835 vmSymbolID vmIntrinsics::name_for(vmIntrinsics::ID id) { 836 jlong info = intrinsic_info(id); 837 int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 838 assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1022, ""); 839 return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask)); 840 } 841 842 vmSymbolID vmIntrinsics::signature_for(vmIntrinsics::ID id) { 843 jlong info = intrinsic_info(id); 844 int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT); 845 assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1023, ""); 846 return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask)); 847 } 848 849 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) { 850 jlong info = intrinsic_info(id); 851 int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT); 852 assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 7, ""); 853 return Flags( (info >> shift) & mask ); 854 } 855 #endif // !PRODUCT