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