1 /* 2 * Copyright (c) 1998, 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/vmClasses.hpp" 26 #include "classfile/vmSymbols.hpp" 27 #include "code/codeCache.hpp" 28 #include "code/compiledIC.hpp" 29 #include "code/nmethod.hpp" 30 #include "code/pcDesc.hpp" 31 #include "code/scopeDesc.hpp" 32 #include "code/vtableStubs.hpp" 33 #include "compiler/compilationMemoryStatistic.hpp" 34 #include "compiler/compileBroker.hpp" 35 #include "compiler/oopMap.hpp" 36 #include "gc/g1/g1HeapRegion.hpp" 37 #include "gc/shared/barrierSet.hpp" 38 #include "gc/shared/collectedHeap.hpp" 39 #include "gc/shared/gcLocker.hpp" 40 #include "interpreter/bytecode.hpp" 41 #include "interpreter/interpreter.hpp" 42 #include "interpreter/linkResolver.hpp" 43 #include "logging/log.hpp" 44 #include "logging/logStream.hpp" 45 #include "memory/oopFactory.hpp" 46 #include "memory/resourceArea.hpp" 47 #include "oops/objArrayKlass.hpp" 48 #include "oops/klass.inline.hpp" 49 #include "oops/oop.inline.hpp" 50 #include "oops/typeArrayOop.inline.hpp" 51 #include "opto/ad.hpp" 52 #include "opto/addnode.hpp" 53 #include "opto/callnode.hpp" 54 #include "opto/cfgnode.hpp" 55 #include "opto/graphKit.hpp" 56 #include "opto/machnode.hpp" 57 #include "opto/matcher.hpp" 58 #include "opto/memnode.hpp" 59 #include "opto/mulnode.hpp" 60 #include "opto/output.hpp" 61 #include "opto/runtime.hpp" 62 #include "opto/subnode.hpp" 63 #include "prims/jvmtiExport.hpp" 64 #include "runtime/atomic.hpp" 65 #include "runtime/frame.inline.hpp" 66 #include "runtime/handles.inline.hpp" 67 #include "runtime/interfaceSupport.inline.hpp" 68 #include "runtime/javaCalls.hpp" 69 #include "runtime/sharedRuntime.hpp" 70 #include "runtime/signature.hpp" 71 #include "runtime/stackWatermarkSet.hpp" 72 #include "runtime/synchronizer.hpp" 73 #include "runtime/threadCritical.hpp" 74 #include "runtime/threadWXSetters.inline.hpp" 75 #include "runtime/vframe.hpp" 76 #include "runtime/vframeArray.hpp" 77 #include "runtime/vframe_hp.hpp" 78 #include "utilities/copy.hpp" 79 #include "utilities/preserveException.hpp" 80 81 82 // For debugging purposes: 83 // To force FullGCALot inside a runtime function, add the following two lines 84 // 85 // Universe::release_fullgc_alot_dummy(); 86 // Universe::heap()->collect(); 87 // 88 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000 89 90 91 #define C2_BLOB_FIELD_DEFINE(name, type) \ 92 type OptoRuntime:: BLOB_FIELD_NAME(name) = nullptr; 93 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java 94 #define C2_STUB_FIELD_DEFINE(name, f, t, r) \ 95 address OptoRuntime:: C2_STUB_FIELD_NAME(name) = nullptr; 96 #define C2_JVMTI_STUB_FIELD_DEFINE(name) \ 97 address OptoRuntime:: STUB_FIELD_NAME(name) = nullptr; 98 C2_STUBS_DO(C2_BLOB_FIELD_DEFINE, C2_STUB_FIELD_DEFINE, C2_JVMTI_STUB_FIELD_DEFINE) 99 #undef C2_BLOB_FIELD_DEFINE 100 #undef C2_STUB_FIELD_DEFINE 101 #undef C2_JVMTI_STUB_FIELD_DEFINE 102 103 #define C2_BLOB_NAME_DEFINE(name, type) "C2 Runtime " # name "_blob", 104 #define C2_STUB_NAME_DEFINE(name, f, t, r) "C2 Runtime " # name, 105 #define C2_JVMTI_STUB_NAME_DEFINE(name) "C2 Runtime " # name, 106 const char* OptoRuntime::_stub_names[] = { 107 C2_STUBS_DO(C2_BLOB_NAME_DEFINE, C2_STUB_NAME_DEFINE, C2_JVMTI_STUB_NAME_DEFINE) 108 }; 109 #undef C2_BLOB_NAME_DEFINE 110 #undef C2_STUB_NAME_DEFINE 111 #undef C2_JVMTI_STUB_NAME_DEFINE 112 113 // This should be called in an assertion at the start of OptoRuntime routines 114 // which are entered from compiled code (all of them) 115 #ifdef ASSERT 116 static bool check_compiled_frame(JavaThread* thread) { 117 assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code"); 118 RegisterMap map(thread, 119 RegisterMap::UpdateMap::skip, 120 RegisterMap::ProcessFrames::include, 121 RegisterMap::WalkContinuation::skip); 122 frame caller = thread->last_frame().sender(&map); 123 assert(caller.is_compiled_frame(), "not being called from compiled like code"); 124 return true; 125 } 126 #endif // ASSERT 127 128 /* 129 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \ 130 var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \ 131 if (var == nullptr) { return false; } 132 */ 133 134 #define GEN_C2_BLOB(name, type) \ 135 BLOB_FIELD_NAME(name) = \ 136 generate_ ## name ## _blob(); \ 137 if (BLOB_FIELD_NAME(name) == nullptr) { return false; } 138 139 // a few helper macros to conjure up generate_stub call arguments 140 #define C2_STUB_FIELD_NAME(name) _ ## name ## _Java 141 #define C2_STUB_TYPEFUNC(name) name ## _Type 142 #define C2_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, name ## _C) 143 #define C2_STUB_NAME(name) stub_name(OptoStubId::name ## _id) 144 145 // Almost all the C functions targeted from the generated stubs are 146 // implemented locally to OptoRuntime with names that can be generated 147 // from the stub name by appending suffix '_C'. However, in two cases 148 // a common target method also needs to be called from shared runtime 149 // stubs. In these two cases the opto stubs rely on method 150 // imlementations defined in class SharedRuntime. The following 151 // defines temporarily rebind the generated names to reference the 152 // relevant implementations. 153 154 #define GEN_C2_STUB(name, fancy_jump, pass_tls, pass_retpc ) \ 155 C2_STUB_FIELD_NAME(name) = \ 156 generate_stub(env, \ 157 C2_STUB_TYPEFUNC(name), \ 158 C2_STUB_C_FUNC(name), \ 159 C2_STUB_NAME(name), \ 160 fancy_jump, \ 161 pass_tls, \ 162 pass_retpc); \ 163 if (C2_STUB_FIELD_NAME(name) == nullptr) { return false; } \ 164 165 #define C2_JVMTI_STUB_C_FUNC(name) CAST_FROM_FN_PTR(address, SharedRuntime::name) 166 167 #define GEN_C2_JVMTI_STUB(name) \ 168 STUB_FIELD_NAME(name) = \ 169 generate_stub(env, \ 170 notify_jvmti_vthread_Type, \ 171 C2_JVMTI_STUB_C_FUNC(name), \ 172 C2_STUB_NAME(name), \ 173 0, \ 174 true, \ 175 false); \ 176 if (STUB_FIELD_NAME(name) == nullptr) { return false; } \ 177 178 bool OptoRuntime::generate(ciEnv* env) { 179 180 C2_STUBS_DO(GEN_C2_BLOB, GEN_C2_STUB, GEN_C2_JVMTI_STUB) 181 182 return true; 183 } 184 185 #undef GEN_C2_BLOB 186 187 #undef C2_STUB_FIELD_NAME 188 #undef C2_STUB_TYPEFUNC 189 #undef C2_STUB_C_FUNC 190 #undef C2_STUB_NAME 191 #undef GEN_C2_STUB 192 193 #undef C2_JVMTI_STUB_C_FUNC 194 #undef GEN_C2_JVMTI_STUB 195 // #undef gen 196 197 const TypeFunc* OptoRuntime::_new_instance_Type = nullptr; 198 const TypeFunc* OptoRuntime::_new_array_Type = nullptr; 199 const TypeFunc* OptoRuntime::_multianewarray2_Type = nullptr; 200 const TypeFunc* OptoRuntime::_multianewarray3_Type = nullptr; 201 const TypeFunc* OptoRuntime::_multianewarray4_Type = nullptr; 202 const TypeFunc* OptoRuntime::_multianewarray5_Type = nullptr; 203 const TypeFunc* OptoRuntime::_multianewarrayN_Type = nullptr; 204 const TypeFunc* OptoRuntime::_complete_monitor_enter_Type = nullptr; 205 const TypeFunc* OptoRuntime::_complete_monitor_exit_Type = nullptr; 206 const TypeFunc* OptoRuntime::_monitor_notify_Type = nullptr; 207 const TypeFunc* OptoRuntime::_uncommon_trap_Type = nullptr; 208 const TypeFunc* OptoRuntime::_athrow_Type = nullptr; 209 const TypeFunc* OptoRuntime::_rethrow_Type = nullptr; 210 const TypeFunc* OptoRuntime::_Math_D_D_Type = nullptr; 211 const TypeFunc* OptoRuntime::_Math_DD_D_Type = nullptr; 212 const TypeFunc* OptoRuntime::_modf_Type = nullptr; 213 const TypeFunc* OptoRuntime::_l2f_Type = nullptr; 214 const TypeFunc* OptoRuntime::_void_long_Type = nullptr; 215 const TypeFunc* OptoRuntime::_void_void_Type = nullptr; 216 const TypeFunc* OptoRuntime::_jfr_write_checkpoint_Type = nullptr; 217 const TypeFunc* OptoRuntime::_flush_windows_Type = nullptr; 218 const TypeFunc* OptoRuntime::_fast_arraycopy_Type = nullptr; 219 const TypeFunc* OptoRuntime::_checkcast_arraycopy_Type = nullptr; 220 const TypeFunc* OptoRuntime::_generic_arraycopy_Type = nullptr; 221 const TypeFunc* OptoRuntime::_slow_arraycopy_Type = nullptr; 222 const TypeFunc* OptoRuntime::_unsafe_setmemory_Type = nullptr; 223 const TypeFunc* OptoRuntime::_array_fill_Type = nullptr; 224 const TypeFunc* OptoRuntime::_array_sort_Type = nullptr; 225 const TypeFunc* OptoRuntime::_array_partition_Type = nullptr; 226 const TypeFunc* OptoRuntime::_aescrypt_block_Type = nullptr; 227 const TypeFunc* OptoRuntime::_cipherBlockChaining_aescrypt_Type = nullptr; 228 const TypeFunc* OptoRuntime::_electronicCodeBook_aescrypt_Type = nullptr; 229 const TypeFunc* OptoRuntime::_counterMode_aescrypt_Type = nullptr; 230 const TypeFunc* OptoRuntime::_galoisCounterMode_aescrypt_Type = nullptr; 231 const TypeFunc* OptoRuntime::_digestBase_implCompress_with_sha3_Type = nullptr; 232 const TypeFunc* OptoRuntime::_digestBase_implCompress_without_sha3_Type = nullptr; 233 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_with_sha3_Type = nullptr; 234 const TypeFunc* OptoRuntime::_digestBase_implCompressMB_without_sha3_Type = nullptr; 235 const TypeFunc* OptoRuntime::_double_keccak_Type = nullptr; 236 const TypeFunc* OptoRuntime::_multiplyToLen_Type = nullptr; 237 const TypeFunc* OptoRuntime::_montgomeryMultiply_Type = nullptr; 238 const TypeFunc* OptoRuntime::_montgomerySquare_Type = nullptr; 239 const TypeFunc* OptoRuntime::_squareToLen_Type = nullptr; 240 const TypeFunc* OptoRuntime::_mulAdd_Type = nullptr; 241 const TypeFunc* OptoRuntime::_bigIntegerShift_Type = nullptr; 242 const TypeFunc* OptoRuntime::_vectorizedMismatch_Type = nullptr; 243 const TypeFunc* OptoRuntime::_ghash_processBlocks_Type = nullptr; 244 const TypeFunc* OptoRuntime::_chacha20Block_Type = nullptr; 245 246 const TypeFunc* OptoRuntime::_dilithiumAlmostNtt_Type = nullptr; 247 const TypeFunc* OptoRuntime::_dilithiumAlmostInverseNtt_Type = nullptr; 248 const TypeFunc* OptoRuntime::_dilithiumNttMult_Type = nullptr; 249 const TypeFunc* OptoRuntime::_dilithiumMontMulByConstant_Type = nullptr; 250 const TypeFunc* OptoRuntime::_dilithiumDecomposePoly_Type = nullptr; 251 252 const TypeFunc* OptoRuntime::_base64_encodeBlock_Type = nullptr; 253 const TypeFunc* OptoRuntime::_base64_decodeBlock_Type = nullptr; 254 const TypeFunc* OptoRuntime::_string_IndexOf_Type = nullptr; 255 const TypeFunc* OptoRuntime::_poly1305_processBlocks_Type = nullptr; 256 const TypeFunc* OptoRuntime::_intpoly_montgomeryMult_P256_Type = nullptr; 257 const TypeFunc* OptoRuntime::_intpoly_assign_Type = nullptr; 258 const TypeFunc* OptoRuntime::_updateBytesCRC32_Type = nullptr; 259 const TypeFunc* OptoRuntime::_updateBytesCRC32C_Type = nullptr; 260 const TypeFunc* OptoRuntime::_updateBytesAdler32_Type = nullptr; 261 const TypeFunc* OptoRuntime::_osr_end_Type = nullptr; 262 const TypeFunc* OptoRuntime::_register_finalizer_Type = nullptr; 263 #if INCLUDE_JFR 264 const TypeFunc* OptoRuntime::_class_id_load_barrier_Type = nullptr; 265 #endif // INCLUDE_JFR 266 #if INCLUDE_JVMTI 267 const TypeFunc* OptoRuntime::_notify_jvmti_vthread_Type = nullptr; 268 #endif // INCLUDE_JVMTI 269 const TypeFunc* OptoRuntime::_dtrace_method_entry_exit_Type = nullptr; 270 const TypeFunc* OptoRuntime::_dtrace_object_alloc_Type = nullptr; 271 272 // Helper method to do generation of RunTimeStub's 273 address OptoRuntime::generate_stub(ciEnv* env, 274 TypeFunc_generator gen, address C_function, 275 const char *name, int is_fancy_jump, 276 bool pass_tls, 277 bool return_pc) { 278 279 // Matching the default directive, we currently have no method to match. 280 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization)); 281 CompilationMemoryStatisticMark cmsm(directive); 282 ResourceMark rm; 283 Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive); 284 DirectivesStack::release(directive); 285 return C.stub_entry_point(); 286 } 287 288 const char* OptoRuntime::stub_name(address entry) { 289 #ifndef PRODUCT 290 CodeBlob* cb = CodeCache::find_blob(entry); 291 RuntimeStub* rs =(RuntimeStub *)cb; 292 assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub"); 293 return rs->name(); 294 #else 295 // Fast implementation for product mode (maybe it should be inlined too) 296 return "runtime stub"; 297 #endif 298 } 299 300 // local methods passed as arguments to stub generator that forward 301 // control to corresponding JRT methods of SharedRuntime 302 303 void OptoRuntime::slow_arraycopy_C(oopDesc* src, jint src_pos, 304 oopDesc* dest, jint dest_pos, 305 jint length, JavaThread* thread) { 306 SharedRuntime::slow_arraycopy_C(src, src_pos, dest, dest_pos, length, thread); 307 } 308 309 void OptoRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current) { 310 SharedRuntime::complete_monitor_locking_C(obj, lock, current); 311 } 312 313 314 //============================================================================= 315 // Opto compiler runtime routines 316 //============================================================================= 317 318 319 //=============================allocation====================================== 320 // We failed the fast-path allocation. Now we need to do a scavenge or GC 321 // and try allocation again. 322 323 // object allocation 324 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* current)) 325 JRT_BLOCK; 326 #ifndef PRODUCT 327 SharedRuntime::_new_instance_ctr++; // new instance requires GC 328 #endif 329 assert(check_compiled_frame(current), "incorrect caller"); 330 331 // These checks are cheap to make and support reflective allocation. 332 int lh = klass->layout_helper(); 333 if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) { 334 Handle holder(current, klass->klass_holder()); // keep the klass alive 335 klass->check_valid_for_instantiation(false, THREAD); 336 if (!HAS_PENDING_EXCEPTION) { 337 InstanceKlass::cast(klass)->initialize(THREAD); 338 } 339 } 340 341 if (!HAS_PENDING_EXCEPTION) { 342 // Scavenge and allocate an instance. 343 Handle holder(current, klass->klass_holder()); // keep the klass alive 344 oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD); 345 current->set_vm_result(result); 346 347 // Pass oops back through thread local storage. Our apparent type to Java 348 // is that we return an oop, but we can block on exit from this routine and 349 // a GC can trash the oop in C's return register. The generated stub will 350 // fetch the oop from TLS after any possible GC. 351 } 352 353 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 354 JRT_BLOCK_END; 355 356 // inform GC that we won't do card marks for initializing writes. 357 SharedRuntime::on_slowpath_allocation_exit(current); 358 JRT_END 359 360 361 // array allocation 362 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current)) 363 JRT_BLOCK; 364 #ifndef PRODUCT 365 SharedRuntime::_new_array_ctr++; // new array requires GC 366 #endif 367 assert(check_compiled_frame(current), "incorrect caller"); 368 369 // Scavenge and allocate an instance. 370 oop result; 371 372 if (array_type->is_typeArray_klass()) { 373 // The oopFactory likes to work with the element type. 374 // (We could bypass the oopFactory, since it doesn't add much value.) 375 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 376 result = oopFactory::new_typeArray(elem_type, len, THREAD); 377 } else { 378 // Although the oopFactory likes to work with the elem_type, 379 // the compiler prefers the array_type, since it must already have 380 // that latter value in hand for the fast path. 381 Handle holder(current, array_type->klass_holder()); // keep the array klass alive 382 Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass(); 383 result = oopFactory::new_objArray(elem_type, len, THREAD); 384 } 385 386 // Pass oops back through thread local storage. Our apparent type to Java 387 // is that we return an oop, but we can block on exit from this routine and 388 // a GC can trash the oop in C's return register. The generated stub will 389 // fetch the oop from TLS after any possible GC. 390 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 391 current->set_vm_result(result); 392 JRT_BLOCK_END; 393 394 // inform GC that we won't do card marks for initializing writes. 395 SharedRuntime::on_slowpath_allocation_exit(current); 396 JRT_END 397 398 // array allocation without zeroing 399 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current)) 400 JRT_BLOCK; 401 #ifndef PRODUCT 402 SharedRuntime::_new_array_ctr++; // new array requires GC 403 #endif 404 assert(check_compiled_frame(current), "incorrect caller"); 405 406 // Scavenge and allocate an instance. 407 oop result; 408 409 assert(array_type->is_typeArray_klass(), "should be called only for type array"); 410 // The oopFactory likes to work with the element type. 411 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 412 result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD); 413 414 // Pass oops back through thread local storage. Our apparent type to Java 415 // is that we return an oop, but we can block on exit from this routine and 416 // a GC can trash the oop in C's return register. The generated stub will 417 // fetch the oop from TLS after any possible GC. 418 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 419 current->set_vm_result(result); 420 JRT_BLOCK_END; 421 422 423 // inform GC that we won't do card marks for initializing writes. 424 SharedRuntime::on_slowpath_allocation_exit(current); 425 426 oop result = current->vm_result(); 427 if ((len > 0) && (result != nullptr) && 428 is_deoptimized_caller_frame(current)) { 429 // Zero array here if the caller is deoptimized. 430 const size_t size = TypeArrayKlass::cast(array_type)->oop_size(result); 431 BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type(); 432 size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type); 433 assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned"); 434 HeapWord* obj = cast_from_oop<HeapWord*>(result); 435 if (!is_aligned(hs_bytes, BytesPerLong)) { 436 *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0; 437 hs_bytes += BytesPerInt; 438 } 439 440 // Optimized zeroing. 441 assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned"); 442 const size_t aligned_hs = hs_bytes / BytesPerLong; 443 Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs); 444 } 445 446 JRT_END 447 448 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array. 449 450 // multianewarray for 2 dimensions 451 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current)) 452 #ifndef PRODUCT 453 SharedRuntime::_multi2_ctr++; // multianewarray for 1 dimension 454 #endif 455 assert(check_compiled_frame(current), "incorrect caller"); 456 assert(elem_type->is_klass(), "not a class"); 457 jint dims[2]; 458 dims[0] = len1; 459 dims[1] = len2; 460 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 461 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD); 462 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 463 current->set_vm_result(obj); 464 JRT_END 465 466 // multianewarray for 3 dimensions 467 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current)) 468 #ifndef PRODUCT 469 SharedRuntime::_multi3_ctr++; // multianewarray for 1 dimension 470 #endif 471 assert(check_compiled_frame(current), "incorrect caller"); 472 assert(elem_type->is_klass(), "not a class"); 473 jint dims[3]; 474 dims[0] = len1; 475 dims[1] = len2; 476 dims[2] = len3; 477 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 478 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD); 479 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 480 current->set_vm_result(obj); 481 JRT_END 482 483 // multianewarray for 4 dimensions 484 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current)) 485 #ifndef PRODUCT 486 SharedRuntime::_multi4_ctr++; // multianewarray for 1 dimension 487 #endif 488 assert(check_compiled_frame(current), "incorrect caller"); 489 assert(elem_type->is_klass(), "not a class"); 490 jint dims[4]; 491 dims[0] = len1; 492 dims[1] = len2; 493 dims[2] = len3; 494 dims[3] = len4; 495 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 496 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD); 497 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 498 current->set_vm_result(obj); 499 JRT_END 500 501 // multianewarray for 5 dimensions 502 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current)) 503 #ifndef PRODUCT 504 SharedRuntime::_multi5_ctr++; // multianewarray for 1 dimension 505 #endif 506 assert(check_compiled_frame(current), "incorrect caller"); 507 assert(elem_type->is_klass(), "not a class"); 508 jint dims[5]; 509 dims[0] = len1; 510 dims[1] = len2; 511 dims[2] = len3; 512 dims[3] = len4; 513 dims[4] = len5; 514 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 515 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD); 516 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 517 current->set_vm_result(obj); 518 JRT_END 519 520 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current)) 521 assert(check_compiled_frame(current), "incorrect caller"); 522 assert(elem_type->is_klass(), "not a class"); 523 assert(oop(dims)->is_typeArray(), "not an array"); 524 525 ResourceMark rm; 526 jint len = dims->length(); 527 assert(len > 0, "Dimensions array should contain data"); 528 jint *c_dims = NEW_RESOURCE_ARRAY(jint, len); 529 ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0), 530 c_dims, len); 531 532 Handle holder(current, elem_type->klass_holder()); // keep the klass alive 533 oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD); 534 deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION); 535 current->set_vm_result(obj); 536 JRT_END 537 538 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current)) 539 540 // Very few notify/notifyAll operations find any threads on the waitset, so 541 // the dominant fast-path is to simply return. 542 // Relatedly, it's critical that notify/notifyAll be fast in order to 543 // reduce lock hold times. 544 if (!SafepointSynchronize::is_synchronizing()) { 545 if (ObjectSynchronizer::quick_notify(obj, current, false)) { 546 return; 547 } 548 } 549 550 // This is the case the fast-path above isn't provisioned to handle. 551 // The fast-path is designed to handle frequently arising cases in an efficient manner. 552 // (The fast-path is just a degenerate variant of the slow-path). 553 // Perform the dreaded state transition and pass control into the slow-path. 554 JRT_BLOCK; 555 Handle h_obj(current, obj); 556 ObjectSynchronizer::notify(h_obj, CHECK); 557 JRT_BLOCK_END; 558 JRT_END 559 560 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current)) 561 562 if (!SafepointSynchronize::is_synchronizing() ) { 563 if (ObjectSynchronizer::quick_notify(obj, current, true)) { 564 return; 565 } 566 } 567 568 // This is the case the fast-path above isn't provisioned to handle. 569 // The fast-path is designed to handle frequently arising cases in an efficient manner. 570 // (The fast-path is just a degenerate variant of the slow-path). 571 // Perform the dreaded state transition and pass control into the slow-path. 572 JRT_BLOCK; 573 Handle h_obj(current, obj); 574 ObjectSynchronizer::notifyall(h_obj, CHECK); 575 JRT_BLOCK_END; 576 JRT_END 577 578 static const TypeFunc* make_new_instance_Type() { 579 // create input type (domain) 580 const Type **fields = TypeTuple::fields(1); 581 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated 582 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 583 584 // create result type (range) 585 fields = TypeTuple::fields(1); 586 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 587 588 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 589 590 return TypeFunc::make(domain, range); 591 } 592 593 #if INCLUDE_JVMTI 594 static const TypeFunc* make_notify_jvmti_vthread_Type() { 595 // create input type (domain) 596 const Type **fields = TypeTuple::fields(2); 597 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop 598 fields[TypeFunc::Parms+1] = TypeInt::BOOL; // jboolean 599 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 600 601 // no result type needed 602 fields = TypeTuple::fields(1); 603 fields[TypeFunc::Parms+0] = nullptr; // void 604 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 605 606 return TypeFunc::make(domain,range); 607 } 608 #endif 609 610 static const TypeFunc* make_athrow_Type() { 611 // create input type (domain) 612 const Type **fields = TypeTuple::fields(1); 613 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated 614 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 615 616 // create result type (range) 617 fields = TypeTuple::fields(0); 618 619 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 620 621 return TypeFunc::make(domain, range); 622 } 623 624 static const TypeFunc* make_new_array_Type() { 625 // create input type (domain) 626 const Type **fields = TypeTuple::fields(2); 627 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 628 fields[TypeFunc::Parms+1] = TypeInt::INT; // array size 629 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 630 631 // create result type (range) 632 fields = TypeTuple::fields(1); 633 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 634 635 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 636 637 return TypeFunc::make(domain, range); 638 } 639 640 const TypeFunc* OptoRuntime::multianewarray_Type(int ndim) { 641 // create input type (domain) 642 const int nargs = ndim + 1; 643 const Type **fields = TypeTuple::fields(nargs); 644 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 645 for( int i = 1; i < nargs; i++ ) 646 fields[TypeFunc::Parms + i] = TypeInt::INT; // array size 647 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields); 648 649 // create result type (range) 650 fields = TypeTuple::fields(1); 651 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 652 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 653 654 return TypeFunc::make(domain, range); 655 } 656 657 static const TypeFunc* make_multianewarrayN_Type() { 658 // create input type (domain) 659 const Type **fields = TypeTuple::fields(2); 660 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // element klass 661 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // array of dim sizes 662 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 663 664 // create result type (range) 665 fields = TypeTuple::fields(1); 666 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 667 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 668 669 return TypeFunc::make(domain, range); 670 } 671 672 static const TypeFunc* make_uncommon_trap_Type() { 673 // create input type (domain) 674 const Type **fields = TypeTuple::fields(1); 675 fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action) 676 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 677 678 // create result type (range) 679 fields = TypeTuple::fields(0); 680 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 681 682 return TypeFunc::make(domain, range); 683 } 684 685 //----------------------------------------------------------------------------- 686 // Monitor Handling 687 688 static const TypeFunc* make_complete_monitor_enter_Type() { 689 // create input type (domain) 690 const Type **fields = TypeTuple::fields(2); 691 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 692 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock 693 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 694 695 // create result type (range) 696 fields = TypeTuple::fields(0); 697 698 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 699 700 return TypeFunc::make(domain,range); 701 } 702 703 //----------------------------------------------------------------------------- 704 705 static const TypeFunc* make_complete_monitor_exit_Type() { 706 // create input type (domain) 707 const Type **fields = TypeTuple::fields(3); 708 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 709 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock - BasicLock 710 fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM; // Thread pointer (Self) 711 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields); 712 713 // create result type (range) 714 fields = TypeTuple::fields(0); 715 716 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 717 718 return TypeFunc::make(domain, range); 719 } 720 721 static const TypeFunc* make_monitor_notify_Type() { 722 // create input type (domain) 723 const Type **fields = TypeTuple::fields(1); 724 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 725 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 726 727 // create result type (range) 728 fields = TypeTuple::fields(0); 729 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 730 return TypeFunc::make(domain, range); 731 } 732 733 static const TypeFunc* make_flush_windows_Type() { 734 // create input type (domain) 735 const Type** fields = TypeTuple::fields(1); 736 fields[TypeFunc::Parms+0] = nullptr; // void 737 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields); 738 739 // create result type 740 fields = TypeTuple::fields(1); 741 fields[TypeFunc::Parms+0] = nullptr; // void 742 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 743 744 return TypeFunc::make(domain, range); 745 } 746 747 static const TypeFunc* make_l2f_Type() { 748 // create input type (domain) 749 const Type **fields = TypeTuple::fields(2); 750 fields[TypeFunc::Parms+0] = TypeLong::LONG; 751 fields[TypeFunc::Parms+1] = Type::HALF; 752 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 753 754 // create result type (range) 755 fields = TypeTuple::fields(1); 756 fields[TypeFunc::Parms+0] = Type::FLOAT; 757 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 758 759 return TypeFunc::make(domain, range); 760 } 761 762 static const TypeFunc* make_modf_Type() { 763 const Type **fields = TypeTuple::fields(2); 764 fields[TypeFunc::Parms+0] = Type::FLOAT; 765 fields[TypeFunc::Parms+1] = Type::FLOAT; 766 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 767 768 // create result type (range) 769 fields = TypeTuple::fields(1); 770 fields[TypeFunc::Parms+0] = Type::FLOAT; 771 772 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 773 774 return TypeFunc::make(domain, range); 775 } 776 777 static const TypeFunc* make_Math_D_D_Type() { 778 // create input type (domain) 779 const Type **fields = TypeTuple::fields(2); 780 // Symbol* name of class to be loaded 781 fields[TypeFunc::Parms+0] = Type::DOUBLE; 782 fields[TypeFunc::Parms+1] = Type::HALF; 783 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); 784 785 // create result type (range) 786 fields = TypeTuple::fields(2); 787 fields[TypeFunc::Parms+0] = Type::DOUBLE; 788 fields[TypeFunc::Parms+1] = Type::HALF; 789 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 790 791 return TypeFunc::make(domain, range); 792 } 793 794 const TypeFunc* OptoRuntime::Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type) { 795 // create input type (domain) 796 const Type **fields = TypeTuple::fields(num_arg); 797 // Symbol* name of class to be loaded 798 assert(num_arg > 0, "must have at least 1 input"); 799 for (uint i = 0; i < num_arg; i++) { 800 fields[TypeFunc::Parms+i] = in_type; 801 } 802 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+num_arg, fields); 803 804 // create result type (range) 805 const uint num_ret = 1; 806 fields = TypeTuple::fields(num_ret); 807 fields[TypeFunc::Parms+0] = out_type; 808 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+num_ret, fields); 809 810 return TypeFunc::make(domain, range); 811 } 812 813 static const TypeFunc* make_Math_DD_D_Type() { 814 const Type **fields = TypeTuple::fields(4); 815 fields[TypeFunc::Parms+0] = Type::DOUBLE; 816 fields[TypeFunc::Parms+1] = Type::HALF; 817 fields[TypeFunc::Parms+2] = Type::DOUBLE; 818 fields[TypeFunc::Parms+3] = Type::HALF; 819 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields); 820 821 // create result type (range) 822 fields = TypeTuple::fields(2); 823 fields[TypeFunc::Parms+0] = Type::DOUBLE; 824 fields[TypeFunc::Parms+1] = Type::HALF; 825 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 826 827 return TypeFunc::make(domain, range); 828 } 829 830 //-------------- currentTimeMillis, currentTimeNanos, etc 831 832 static const TypeFunc* make_void_long_Type() { 833 // create input type (domain) 834 const Type **fields = TypeTuple::fields(0); 835 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields); 836 837 // create result type (range) 838 fields = TypeTuple::fields(2); 839 fields[TypeFunc::Parms+0] = TypeLong::LONG; 840 fields[TypeFunc::Parms+1] = Type::HALF; 841 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields); 842 843 return TypeFunc::make(domain, range); 844 } 845 846 static const TypeFunc* make_void_void_Type() { 847 // create input type (domain) 848 const Type **fields = TypeTuple::fields(0); 849 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields); 850 851 // create result type (range) 852 fields = TypeTuple::fields(0); 853 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); 854 return TypeFunc::make(domain, range); 855 } 856 857 static const TypeFunc* make_jfr_write_checkpoint_Type() { 858 // create input type (domain) 859 const Type **fields = TypeTuple::fields(0); 860 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields); 861 862 // create result type (range) 863 fields = TypeTuple::fields(0); 864 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 865 return TypeFunc::make(domain, range); 866 } 867 868 869 // Takes as parameters: 870 // void *dest 871 // long size 872 // uchar byte 873 874 static const TypeFunc* make_setmemory_Type() { 875 // create input type (domain) 876 int argcnt = NOT_LP64(3) LP64_ONLY(4); 877 const Type** fields = TypeTuple::fields(argcnt); 878 int argp = TypeFunc::Parms; 879 fields[argp++] = TypePtr::NOTNULL; // dest 880 fields[argp++] = TypeX_X; // size 881 LP64_ONLY(fields[argp++] = Type::HALF); // size 882 fields[argp++] = TypeInt::UBYTE; // bytevalue 883 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 884 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 885 886 // no result type needed 887 fields = TypeTuple::fields(1); 888 fields[TypeFunc::Parms+0] = nullptr; // void 889 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 890 return TypeFunc::make(domain, range); 891 } 892 893 // arraycopy stub variations: 894 enum ArrayCopyType { 895 ac_fast, // void(ptr, ptr, size_t) 896 ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr) 897 ac_slow, // void(ptr, int, ptr, int, int) 898 ac_generic // int(ptr, int, ptr, int, int) 899 }; 900 901 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) { 902 // create input type (domain) 903 int num_args = (act == ac_fast ? 3 : 5); 904 int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0); 905 int argcnt = num_args; 906 LP64_ONLY(argcnt += num_size_args); // halfwords for lengths 907 const Type** fields = TypeTuple::fields(argcnt); 908 int argp = TypeFunc::Parms; 909 fields[argp++] = TypePtr::NOTNULL; // src 910 if (num_size_args == 0) { 911 fields[argp++] = TypeInt::INT; // src_pos 912 } 913 fields[argp++] = TypePtr::NOTNULL; // dest 914 if (num_size_args == 0) { 915 fields[argp++] = TypeInt::INT; // dest_pos 916 fields[argp++] = TypeInt::INT; // length 917 } 918 while (num_size_args-- > 0) { 919 fields[argp++] = TypeX_X; // size in whatevers (size_t) 920 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length 921 } 922 if (act == ac_checkcast) { 923 fields[argp++] = TypePtr::NOTNULL; // super_klass 924 } 925 assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act"); 926 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 927 928 // create result type if needed 929 int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0); 930 fields = TypeTuple::fields(1); 931 if (retcnt == 0) 932 fields[TypeFunc::Parms+0] = nullptr; // void 933 else 934 fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed 935 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields); 936 return TypeFunc::make(domain, range); 937 } 938 939 static const TypeFunc* make_array_fill_Type() { 940 const Type** fields; 941 int argp = TypeFunc::Parms; 942 // create input type (domain): pointer, int, size_t 943 fields = TypeTuple::fields(3 LP64_ONLY( + 1)); 944 fields[argp++] = TypePtr::NOTNULL; 945 fields[argp++] = TypeInt::INT; 946 fields[argp++] = TypeX_X; // size in whatevers (size_t) 947 LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length 948 const TypeTuple *domain = TypeTuple::make(argp, fields); 949 950 // create result type 951 fields = TypeTuple::fields(1); 952 fields[TypeFunc::Parms+0] = nullptr; // void 953 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 954 955 return TypeFunc::make(domain, range); 956 } 957 958 static const TypeFunc* make_array_partition_Type() { 959 // create input type (domain) 960 int num_args = 7; 961 int argcnt = num_args; 962 const Type** fields = TypeTuple::fields(argcnt); 963 int argp = TypeFunc::Parms; 964 fields[argp++] = TypePtr::NOTNULL; // array 965 fields[argp++] = TypeInt::INT; // element type 966 fields[argp++] = TypeInt::INT; // low 967 fields[argp++] = TypeInt::INT; // end 968 fields[argp++] = TypePtr::NOTNULL; // pivot_indices (int array) 969 fields[argp++] = TypeInt::INT; // indexPivot1 970 fields[argp++] = TypeInt::INT; // indexPivot2 971 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 972 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 973 974 // no result type needed 975 fields = TypeTuple::fields(1); 976 fields[TypeFunc::Parms+0] = nullptr; // void 977 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 978 return TypeFunc::make(domain, range); 979 } 980 981 static const TypeFunc* make_array_sort_Type() { 982 // create input type (domain) 983 int num_args = 4; 984 int argcnt = num_args; 985 const Type** fields = TypeTuple::fields(argcnt); 986 int argp = TypeFunc::Parms; 987 fields[argp++] = TypePtr::NOTNULL; // array 988 fields[argp++] = TypeInt::INT; // element type 989 fields[argp++] = TypeInt::INT; // fromIndex 990 fields[argp++] = TypeInt::INT; // toIndex 991 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 992 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 993 994 // no result type needed 995 fields = TypeTuple::fields(1); 996 fields[TypeFunc::Parms+0] = nullptr; // void 997 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 998 return TypeFunc::make(domain, range); 999 } 1000 1001 static const TypeFunc* make_aescrypt_block_Type() { 1002 // create input type (domain) 1003 int num_args = 3; 1004 int argcnt = num_args; 1005 const Type** fields = TypeTuple::fields(argcnt); 1006 int argp = TypeFunc::Parms; 1007 fields[argp++] = TypePtr::NOTNULL; // src 1008 fields[argp++] = TypePtr::NOTNULL; // dest 1009 fields[argp++] = TypePtr::NOTNULL; // k array 1010 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1011 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1012 1013 // no result type needed 1014 fields = TypeTuple::fields(1); 1015 fields[TypeFunc::Parms+0] = nullptr; // void 1016 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1017 return TypeFunc::make(domain, range); 1018 } 1019 1020 static const TypeFunc* make_updateBytesCRC32_Type() { 1021 // create input type (domain) 1022 int num_args = 3; 1023 int argcnt = num_args; 1024 const Type** fields = TypeTuple::fields(argcnt); 1025 int argp = TypeFunc::Parms; 1026 fields[argp++] = TypeInt::INT; // crc 1027 fields[argp++] = TypePtr::NOTNULL; // src 1028 fields[argp++] = TypeInt::INT; // len 1029 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1030 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1031 1032 // result type needed 1033 fields = TypeTuple::fields(1); 1034 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 1035 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1036 return TypeFunc::make(domain, range); 1037 } 1038 1039 static const TypeFunc* make_updateBytesCRC32C_Type() { 1040 // create input type (domain) 1041 int num_args = 4; 1042 int argcnt = num_args; 1043 const Type** fields = TypeTuple::fields(argcnt); 1044 int argp = TypeFunc::Parms; 1045 fields[argp++] = TypeInt::INT; // crc 1046 fields[argp++] = TypePtr::NOTNULL; // buf 1047 fields[argp++] = TypeInt::INT; // len 1048 fields[argp++] = TypePtr::NOTNULL; // table 1049 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1050 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1051 1052 // result type needed 1053 fields = TypeTuple::fields(1); 1054 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 1055 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1056 return TypeFunc::make(domain, range); 1057 } 1058 1059 static const TypeFunc* make_updateBytesAdler32_Type() { 1060 // create input type (domain) 1061 int num_args = 3; 1062 int argcnt = num_args; 1063 const Type** fields = TypeTuple::fields(argcnt); 1064 int argp = TypeFunc::Parms; 1065 fields[argp++] = TypeInt::INT; // crc 1066 fields[argp++] = TypePtr::NOTNULL; // src + offset 1067 fields[argp++] = TypeInt::INT; // len 1068 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1069 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1070 1071 // result type needed 1072 fields = TypeTuple::fields(1); 1073 fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result 1074 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1075 return TypeFunc::make(domain, range); 1076 } 1077 1078 static const TypeFunc* make_cipherBlockChaining_aescrypt_Type() { 1079 // create input type (domain) 1080 int num_args = 5; 1081 int argcnt = num_args; 1082 const Type** fields = TypeTuple::fields(argcnt); 1083 int argp = TypeFunc::Parms; 1084 fields[argp++] = TypePtr::NOTNULL; // src 1085 fields[argp++] = TypePtr::NOTNULL; // dest 1086 fields[argp++] = TypePtr::NOTNULL; // k array 1087 fields[argp++] = TypePtr::NOTNULL; // r array 1088 fields[argp++] = TypeInt::INT; // src len 1089 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1090 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1091 1092 // returning cipher len (int) 1093 fields = TypeTuple::fields(1); 1094 fields[TypeFunc::Parms+0] = TypeInt::INT; 1095 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1096 return TypeFunc::make(domain, range); 1097 } 1098 1099 static const TypeFunc* make_electronicCodeBook_aescrypt_Type() { 1100 // create input type (domain) 1101 int num_args = 4; 1102 int argcnt = num_args; 1103 const Type** fields = TypeTuple::fields(argcnt); 1104 int argp = TypeFunc::Parms; 1105 fields[argp++] = TypePtr::NOTNULL; // src 1106 fields[argp++] = TypePtr::NOTNULL; // dest 1107 fields[argp++] = TypePtr::NOTNULL; // k array 1108 fields[argp++] = TypeInt::INT; // src len 1109 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1110 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1111 1112 // returning cipher len (int) 1113 fields = TypeTuple::fields(1); 1114 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1115 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1116 return TypeFunc::make(domain, range); 1117 } 1118 1119 static const TypeFunc* make_counterMode_aescrypt_Type() { 1120 // create input type (domain) 1121 int num_args = 7; 1122 int argcnt = num_args; 1123 const Type** fields = TypeTuple::fields(argcnt); 1124 int argp = TypeFunc::Parms; 1125 fields[argp++] = TypePtr::NOTNULL; // src 1126 fields[argp++] = TypePtr::NOTNULL; // dest 1127 fields[argp++] = TypePtr::NOTNULL; // k array 1128 fields[argp++] = TypePtr::NOTNULL; // counter array 1129 fields[argp++] = TypeInt::INT; // src len 1130 fields[argp++] = TypePtr::NOTNULL; // saved_encCounter 1131 fields[argp++] = TypePtr::NOTNULL; // saved used addr 1132 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1133 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1134 // returning cipher len (int) 1135 fields = TypeTuple::fields(1); 1136 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1137 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1138 return TypeFunc::make(domain, range); 1139 } 1140 1141 static const TypeFunc* make_galoisCounterMode_aescrypt_Type() { 1142 // create input type (domain) 1143 int num_args = 8; 1144 int argcnt = num_args; 1145 const Type** fields = TypeTuple::fields(argcnt); 1146 int argp = TypeFunc::Parms; 1147 fields[argp++] = TypePtr::NOTNULL; // byte[] in + inOfs 1148 fields[argp++] = TypeInt::INT; // int len 1149 fields[argp++] = TypePtr::NOTNULL; // byte[] ct + ctOfs 1150 fields[argp++] = TypePtr::NOTNULL; // byte[] out + outOfs 1151 fields[argp++] = TypePtr::NOTNULL; // byte[] key from AESCrypt obj 1152 fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj 1153 fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj 1154 fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj 1155 1156 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1157 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1158 // returning cipher len (int) 1159 fields = TypeTuple::fields(1); 1160 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1161 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1162 return TypeFunc::make(domain, range); 1163 } 1164 1165 static const TypeFunc* make_digestBase_implCompress_Type(bool is_sha3) { 1166 // create input type (domain) 1167 int num_args = is_sha3 ? 3 : 2; 1168 int argcnt = num_args; 1169 const Type** fields = TypeTuple::fields(argcnt); 1170 int argp = TypeFunc::Parms; 1171 fields[argp++] = TypePtr::NOTNULL; // buf 1172 fields[argp++] = TypePtr::NOTNULL; // state 1173 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size 1174 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1175 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1176 1177 // no result type needed 1178 fields = TypeTuple::fields(1); 1179 fields[TypeFunc::Parms+0] = nullptr; // void 1180 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1181 return TypeFunc::make(domain, range); 1182 } 1183 1184 /* 1185 * int implCompressMultiBlock(byte[] b, int ofs, int limit) 1186 */ 1187 static const TypeFunc* make_digestBase_implCompressMB_Type(bool is_sha3) { 1188 // create input type (domain) 1189 int num_args = is_sha3 ? 5 : 4; 1190 int argcnt = num_args; 1191 const Type** fields = TypeTuple::fields(argcnt); 1192 int argp = TypeFunc::Parms; 1193 fields[argp++] = TypePtr::NOTNULL; // buf 1194 fields[argp++] = TypePtr::NOTNULL; // state 1195 if (is_sha3) fields[argp++] = TypeInt::INT; // block_size 1196 fields[argp++] = TypeInt::INT; // ofs 1197 fields[argp++] = TypeInt::INT; // limit 1198 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1199 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1200 1201 // returning ofs (int) 1202 fields = TypeTuple::fields(1); 1203 fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs 1204 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1205 return TypeFunc::make(domain, range); 1206 } 1207 1208 // SHAKE128Parallel doubleKeccak function 1209 static const TypeFunc* make_double_keccak_Type() { 1210 int argcnt = 2; 1211 1212 const Type** fields = TypeTuple::fields(argcnt); 1213 int argp = TypeFunc::Parms; 1214 fields[argp++] = TypePtr::NOTNULL; // status0 1215 fields[argp++] = TypePtr::NOTNULL; // status1 1216 1217 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1218 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1219 1220 // result type needed 1221 fields = TypeTuple::fields(1); 1222 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1223 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1224 return TypeFunc::make(domain, range); 1225 } 1226 1227 static const TypeFunc* make_multiplyToLen_Type() { 1228 // create input type (domain) 1229 int num_args = 5; 1230 int argcnt = num_args; 1231 const Type** fields = TypeTuple::fields(argcnt); 1232 int argp = TypeFunc::Parms; 1233 fields[argp++] = TypePtr::NOTNULL; // x 1234 fields[argp++] = TypeInt::INT; // xlen 1235 fields[argp++] = TypePtr::NOTNULL; // y 1236 fields[argp++] = TypeInt::INT; // ylen 1237 fields[argp++] = TypePtr::NOTNULL; // z 1238 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1239 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1240 1241 // no result type needed 1242 fields = TypeTuple::fields(1); 1243 fields[TypeFunc::Parms+0] = nullptr; 1244 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1245 return TypeFunc::make(domain, range); 1246 } 1247 1248 static const TypeFunc* make_squareToLen_Type() { 1249 // create input type (domain) 1250 int num_args = 4; 1251 int argcnt = num_args; 1252 const Type** fields = TypeTuple::fields(argcnt); 1253 int argp = TypeFunc::Parms; 1254 fields[argp++] = TypePtr::NOTNULL; // x 1255 fields[argp++] = TypeInt::INT; // len 1256 fields[argp++] = TypePtr::NOTNULL; // z 1257 fields[argp++] = TypeInt::INT; // zlen 1258 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1259 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1260 1261 // no result type needed 1262 fields = TypeTuple::fields(1); 1263 fields[TypeFunc::Parms+0] = nullptr; 1264 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1265 return TypeFunc::make(domain, range); 1266 } 1267 1268 static const TypeFunc* make_mulAdd_Type() { 1269 // create input type (domain) 1270 int num_args = 5; 1271 int argcnt = num_args; 1272 const Type** fields = TypeTuple::fields(argcnt); 1273 int argp = TypeFunc::Parms; 1274 fields[argp++] = TypePtr::NOTNULL; // out 1275 fields[argp++] = TypePtr::NOTNULL; // in 1276 fields[argp++] = TypeInt::INT; // offset 1277 fields[argp++] = TypeInt::INT; // len 1278 fields[argp++] = TypeInt::INT; // k 1279 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1280 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1281 1282 // returning carry (int) 1283 fields = TypeTuple::fields(1); 1284 fields[TypeFunc::Parms+0] = TypeInt::INT; 1285 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields); 1286 return TypeFunc::make(domain, range); 1287 } 1288 1289 static const TypeFunc* make_montgomeryMultiply_Type() { 1290 // create input type (domain) 1291 int num_args = 7; 1292 int argcnt = num_args; 1293 const Type** fields = TypeTuple::fields(argcnt); 1294 int argp = TypeFunc::Parms; 1295 fields[argp++] = TypePtr::NOTNULL; // a 1296 fields[argp++] = TypePtr::NOTNULL; // b 1297 fields[argp++] = TypePtr::NOTNULL; // n 1298 fields[argp++] = TypeInt::INT; // len 1299 fields[argp++] = TypeLong::LONG; // inv 1300 fields[argp++] = Type::HALF; 1301 fields[argp++] = TypePtr::NOTNULL; // result 1302 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1303 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1304 1305 // result type needed 1306 fields = TypeTuple::fields(1); 1307 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL; 1308 1309 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1310 return TypeFunc::make(domain, range); 1311 } 1312 1313 static const TypeFunc* make_montgomerySquare_Type() { 1314 // create input type (domain) 1315 int num_args = 6; 1316 int argcnt = num_args; 1317 const Type** fields = TypeTuple::fields(argcnt); 1318 int argp = TypeFunc::Parms; 1319 fields[argp++] = TypePtr::NOTNULL; // a 1320 fields[argp++] = TypePtr::NOTNULL; // n 1321 fields[argp++] = TypeInt::INT; // len 1322 fields[argp++] = TypeLong::LONG; // inv 1323 fields[argp++] = Type::HALF; 1324 fields[argp++] = TypePtr::NOTNULL; // result 1325 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1326 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1327 1328 // result type needed 1329 fields = TypeTuple::fields(1); 1330 fields[TypeFunc::Parms+0] = TypePtr::NOTNULL; 1331 1332 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1333 return TypeFunc::make(domain, range); 1334 } 1335 1336 static const TypeFunc* make_bigIntegerShift_Type() { 1337 int argcnt = 5; 1338 const Type** fields = TypeTuple::fields(argcnt); 1339 int argp = TypeFunc::Parms; 1340 fields[argp++] = TypePtr::NOTNULL; // newArr 1341 fields[argp++] = TypePtr::NOTNULL; // oldArr 1342 fields[argp++] = TypeInt::INT; // newIdx 1343 fields[argp++] = TypeInt::INT; // shiftCount 1344 fields[argp++] = TypeInt::INT; // numIter 1345 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1346 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1347 1348 // no result type needed 1349 fields = TypeTuple::fields(1); 1350 fields[TypeFunc::Parms + 0] = nullptr; 1351 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1352 return TypeFunc::make(domain, range); 1353 } 1354 1355 static const TypeFunc* make_vectorizedMismatch_Type() { 1356 // create input type (domain) 1357 int num_args = 4; 1358 int argcnt = num_args; 1359 const Type** fields = TypeTuple::fields(argcnt); 1360 int argp = TypeFunc::Parms; 1361 fields[argp++] = TypePtr::NOTNULL; // obja 1362 fields[argp++] = TypePtr::NOTNULL; // objb 1363 fields[argp++] = TypeInt::INT; // length, number of elements 1364 fields[argp++] = TypeInt::INT; // log2scale, element size 1365 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1366 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1367 1368 //return mismatch index (int) 1369 fields = TypeTuple::fields(1); 1370 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1371 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1372 return TypeFunc::make(domain, range); 1373 } 1374 1375 static const TypeFunc* make_ghash_processBlocks_Type() { 1376 int argcnt = 4; 1377 1378 const Type** fields = TypeTuple::fields(argcnt); 1379 int argp = TypeFunc::Parms; 1380 fields[argp++] = TypePtr::NOTNULL; // state 1381 fields[argp++] = TypePtr::NOTNULL; // subkeyH 1382 fields[argp++] = TypePtr::NOTNULL; // data 1383 fields[argp++] = TypeInt::INT; // blocks 1384 assert(argp == TypeFunc::Parms+argcnt, "correct decoding"); 1385 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1386 1387 // result type needed 1388 fields = TypeTuple::fields(1); 1389 fields[TypeFunc::Parms+0] = nullptr; // void 1390 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1391 return TypeFunc::make(domain, range); 1392 } 1393 1394 static const TypeFunc* make_chacha20Block_Type() { 1395 int argcnt = 2; 1396 1397 const Type** fields = TypeTuple::fields(argcnt); 1398 int argp = TypeFunc::Parms; 1399 fields[argp++] = TypePtr::NOTNULL; // state 1400 fields[argp++] = TypePtr::NOTNULL; // result 1401 1402 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1403 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1404 1405 // result type needed 1406 fields = TypeTuple::fields(1); 1407 fields[TypeFunc::Parms + 0] = TypeInt::INT; // key stream outlen as int 1408 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1409 return TypeFunc::make(domain, range); 1410 } 1411 1412 // Dilithium NTT function except for the final "normalization" to |coeff| < Q 1413 static const TypeFunc* make_dilithiumAlmostNtt_Type() { 1414 int argcnt = 2; 1415 1416 const Type** fields = TypeTuple::fields(argcnt); 1417 int argp = TypeFunc::Parms; 1418 fields[argp++] = TypePtr::NOTNULL; // coeffs 1419 fields[argp++] = TypePtr::NOTNULL; // NTT zetas 1420 1421 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1422 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1423 1424 // result type needed 1425 fields = TypeTuple::fields(1); 1426 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1427 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1428 return TypeFunc::make(domain, range); 1429 } 1430 1431 // Dilithium inverse NTT function except the final mod Q division by 2^256 1432 static const TypeFunc* make_dilithiumAlmostInverseNtt_Type() { 1433 int argcnt = 2; 1434 1435 const Type** fields = TypeTuple::fields(argcnt); 1436 int argp = TypeFunc::Parms; 1437 fields[argp++] = TypePtr::NOTNULL; // coeffs 1438 fields[argp++] = TypePtr::NOTNULL; // inverse NTT zetas 1439 1440 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1441 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1442 1443 // result type needed 1444 fields = TypeTuple::fields(1); 1445 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1446 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1447 return TypeFunc::make(domain, range); 1448 } 1449 1450 // Dilithium NTT multiply function 1451 static const TypeFunc* make_dilithiumNttMult_Type() { 1452 int argcnt = 3; 1453 1454 const Type** fields = TypeTuple::fields(argcnt); 1455 int argp = TypeFunc::Parms; 1456 fields[argp++] = TypePtr::NOTNULL; // result 1457 fields[argp++] = TypePtr::NOTNULL; // ntta 1458 fields[argp++] = TypePtr::NOTNULL; // nttb 1459 1460 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1461 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1462 1463 // result type needed 1464 fields = TypeTuple::fields(1); 1465 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1466 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1467 return TypeFunc::make(domain, range); 1468 } 1469 1470 // Dilithium Montgomery multiply a polynome coefficient array by a constant 1471 static const TypeFunc* make_dilithiumMontMulByConstant_Type() { 1472 int argcnt = 2; 1473 1474 const Type** fields = TypeTuple::fields(argcnt); 1475 int argp = TypeFunc::Parms; 1476 fields[argp++] = TypePtr::NOTNULL; // coeffs 1477 fields[argp++] = TypeInt::INT; // constant multiplier 1478 1479 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1480 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1481 1482 // result type needed 1483 fields = TypeTuple::fields(1); 1484 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1485 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1486 return TypeFunc::make(domain, range); 1487 } 1488 1489 // Dilithium decompose polynomial 1490 static const TypeFunc* make_dilithiumDecomposePoly_Type() { 1491 int argcnt = 5; 1492 1493 const Type** fields = TypeTuple::fields(argcnt); 1494 int argp = TypeFunc::Parms; 1495 fields[argp++] = TypePtr::NOTNULL; // input 1496 fields[argp++] = TypePtr::NOTNULL; // lowPart 1497 fields[argp++] = TypePtr::NOTNULL; // highPart 1498 fields[argp++] = TypeInt::INT; // 2 * gamma2 1499 fields[argp++] = TypeInt::INT; // multiplier 1500 1501 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1502 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields); 1503 1504 // result type needed 1505 fields = TypeTuple::fields(1); 1506 fields[TypeFunc::Parms + 0] = TypeInt::INT; 1507 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1508 return TypeFunc::make(domain, range); 1509 } 1510 1511 static const TypeFunc* make_base64_encodeBlock_Type() { 1512 int argcnt = 6; 1513 1514 const Type** fields = TypeTuple::fields(argcnt); 1515 int argp = TypeFunc::Parms; 1516 fields[argp++] = TypePtr::NOTNULL; // src array 1517 fields[argp++] = TypeInt::INT; // offset 1518 fields[argp++] = TypeInt::INT; // length 1519 fields[argp++] = TypePtr::NOTNULL; // dest array 1520 fields[argp++] = TypeInt::INT; // dp 1521 fields[argp++] = TypeInt::BOOL; // isURL 1522 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1523 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1524 1525 // result type needed 1526 fields = TypeTuple::fields(1); 1527 fields[TypeFunc::Parms + 0] = nullptr; // void 1528 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1529 return TypeFunc::make(domain, range); 1530 } 1531 1532 static const TypeFunc* make_string_IndexOf_Type() { 1533 int argcnt = 4; 1534 1535 const Type** fields = TypeTuple::fields(argcnt); 1536 int argp = TypeFunc::Parms; 1537 fields[argp++] = TypePtr::NOTNULL; // haystack array 1538 fields[argp++] = TypeInt::INT; // haystack length 1539 fields[argp++] = TypePtr::NOTNULL; // needle array 1540 fields[argp++] = TypeInt::INT; // needle length 1541 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1542 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1543 1544 // result type needed 1545 fields = TypeTuple::fields(1); 1546 fields[TypeFunc::Parms + 0] = TypeInt::INT; // Index of needle in haystack 1547 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1548 return TypeFunc::make(domain, range); 1549 } 1550 1551 static const TypeFunc* make_base64_decodeBlock_Type() { 1552 int argcnt = 7; 1553 1554 const Type** fields = TypeTuple::fields(argcnt); 1555 int argp = TypeFunc::Parms; 1556 fields[argp++] = TypePtr::NOTNULL; // src array 1557 fields[argp++] = TypeInt::INT; // src offset 1558 fields[argp++] = TypeInt::INT; // src length 1559 fields[argp++] = TypePtr::NOTNULL; // dest array 1560 fields[argp++] = TypeInt::INT; // dest offset 1561 fields[argp++] = TypeInt::BOOL; // isURL 1562 fields[argp++] = TypeInt::BOOL; // isMIME 1563 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1564 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1565 1566 // result type needed 1567 fields = TypeTuple::fields(1); 1568 fields[TypeFunc::Parms + 0] = TypeInt::INT; // count of bytes written to dst 1569 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields); 1570 return TypeFunc::make(domain, range); 1571 } 1572 1573 static const TypeFunc* make_poly1305_processBlocks_Type() { 1574 int argcnt = 4; 1575 1576 const Type** fields = TypeTuple::fields(argcnt); 1577 int argp = TypeFunc::Parms; 1578 fields[argp++] = TypePtr::NOTNULL; // input array 1579 fields[argp++] = TypeInt::INT; // input length 1580 fields[argp++] = TypePtr::NOTNULL; // accumulator array 1581 fields[argp++] = TypePtr::NOTNULL; // r array 1582 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1583 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1584 1585 // result type needed 1586 fields = TypeTuple::fields(1); 1587 fields[TypeFunc::Parms + 0] = nullptr; // void 1588 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1589 return TypeFunc::make(domain, range); 1590 } 1591 1592 static const TypeFunc* make_intpoly_montgomeryMult_P256_Type() { 1593 int argcnt = 3; 1594 1595 const Type** fields = TypeTuple::fields(argcnt); 1596 int argp = TypeFunc::Parms; 1597 fields[argp++] = TypePtr::NOTNULL; // a array 1598 fields[argp++] = TypePtr::NOTNULL; // b array 1599 fields[argp++] = TypePtr::NOTNULL; // r(esult) array 1600 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1601 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1602 1603 // result type needed 1604 fields = TypeTuple::fields(1); 1605 fields[TypeFunc::Parms + 0] = nullptr; // void 1606 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1607 return TypeFunc::make(domain, range); 1608 } 1609 1610 static const TypeFunc* make_intpoly_assign_Type() { 1611 int argcnt = 4; 1612 1613 const Type** fields = TypeTuple::fields(argcnt); 1614 int argp = TypeFunc::Parms; 1615 fields[argp++] = TypeInt::INT; // set flag 1616 fields[argp++] = TypePtr::NOTNULL; // a array (result) 1617 fields[argp++] = TypePtr::NOTNULL; // b array (if set is set) 1618 fields[argp++] = TypeInt::INT; // array length 1619 assert(argp == TypeFunc::Parms + argcnt, "correct decoding"); 1620 const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields); 1621 1622 // result type needed 1623 fields = TypeTuple::fields(1); 1624 fields[TypeFunc::Parms + 0] = nullptr; // void 1625 const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields); 1626 return TypeFunc::make(domain, range); 1627 } 1628 1629 //------------- Interpreter state for on stack replacement 1630 static const TypeFunc* make_osr_end_Type() { 1631 // create input type (domain) 1632 const Type **fields = TypeTuple::fields(1); 1633 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf 1634 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); 1635 1636 // create result type 1637 fields = TypeTuple::fields(1); 1638 // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop 1639 fields[TypeFunc::Parms+0] = nullptr; // void 1640 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); 1641 return TypeFunc::make(domain, range); 1642 } 1643 1644 //------------------------------------------------------------------------------------- 1645 // register policy 1646 1647 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) { 1648 assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register"); 1649 switch (register_save_policy[reg]) { 1650 case 'C': return false; //SOC 1651 case 'E': return true ; //SOE 1652 case 'N': return false; //NS 1653 case 'A': return false; //AS 1654 } 1655 ShouldNotReachHere(); 1656 return false; 1657 } 1658 1659 //----------------------------------------------------------------------- 1660 // Exceptions 1661 // 1662 1663 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg); 1664 1665 // The method is an entry that is always called by a C++ method not 1666 // directly from compiled code. Compiled code will call the C++ method following. 1667 // We can't allow async exception to be installed during exception processing. 1668 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm)) 1669 // The frame we rethrow the exception to might not have been processed by the GC yet. 1670 // The stack watermark barrier takes care of detecting that and ensuring the frame 1671 // has updated oops. 1672 StackWatermarkSet::after_unwind(current); 1673 1674 // Do not confuse exception_oop with pending_exception. The exception_oop 1675 // is only used to pass arguments into the method. Not for general 1676 // exception handling. DO NOT CHANGE IT to use pending_exception, since 1677 // the runtime stubs checks this on exit. 1678 assert(current->exception_oop() != nullptr, "exception oop is found"); 1679 address handler_address = nullptr; 1680 1681 Handle exception(current, current->exception_oop()); 1682 address pc = current->exception_pc(); 1683 1684 // Clear out the exception oop and pc since looking up an 1685 // exception handler can cause class loading, which might throw an 1686 // exception and those fields are expected to be clear during 1687 // normal bytecode execution. 1688 current->clear_exception_oop_and_pc(); 1689 1690 LogTarget(Info, exceptions) lt; 1691 if (lt.is_enabled()) { 1692 LogStream ls(lt); 1693 trace_exception(&ls, exception(), pc, ""); 1694 } 1695 1696 // for AbortVMOnException flag 1697 Exceptions::debug_check_abort(exception); 1698 1699 #ifdef ASSERT 1700 if (!(exception->is_a(vmClasses::Throwable_klass()))) { 1701 // should throw an exception here 1702 ShouldNotReachHere(); 1703 } 1704 #endif 1705 1706 // new exception handling: this method is entered only from adapters 1707 // exceptions from compiled java methods are handled in compiled code 1708 // using rethrow node 1709 1710 nm = CodeCache::find_nmethod(pc); 1711 assert(nm != nullptr, "No NMethod found"); 1712 if (nm->is_native_method()) { 1713 fatal("Native method should not have path to exception handling"); 1714 } else { 1715 // we are switching to old paradigm: search for exception handler in caller_frame 1716 // instead in exception handler of caller_frame.sender() 1717 1718 if (JvmtiExport::can_post_on_exceptions()) { 1719 // "Full-speed catching" is not necessary here, 1720 // since we're notifying the VM on every catch. 1721 // Force deoptimization and the rest of the lookup 1722 // will be fine. 1723 deoptimize_caller_frame(current); 1724 } 1725 1726 // Check the stack guard pages. If enabled, look for handler in this frame; 1727 // otherwise, forcibly unwind the frame. 1728 // 1729 // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate. 1730 bool force_unwind = !current->stack_overflow_state()->reguard_stack(); 1731 bool deopting = false; 1732 if (nm->is_deopt_pc(pc)) { 1733 deopting = true; 1734 RegisterMap map(current, 1735 RegisterMap::UpdateMap::skip, 1736 RegisterMap::ProcessFrames::include, 1737 RegisterMap::WalkContinuation::skip); 1738 frame deoptee = current->last_frame().sender(&map); 1739 assert(deoptee.is_deoptimized_frame(), "must be deopted"); 1740 // Adjust the pc back to the original throwing pc 1741 pc = deoptee.pc(); 1742 } 1743 1744 // If we are forcing an unwind because of stack overflow then deopt is 1745 // irrelevant since we are throwing the frame away anyway. 1746 1747 if (deopting && !force_unwind) { 1748 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception(); 1749 } else { 1750 1751 handler_address = 1752 force_unwind ? nullptr : nm->handler_for_exception_and_pc(exception, pc); 1753 1754 if (handler_address == nullptr) { 1755 bool recursive_exception = false; 1756 handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); 1757 assert (handler_address != nullptr, "must have compiled handler"); 1758 // Update the exception cache only when the unwind was not forced 1759 // and there didn't happen another exception during the computation of the 1760 // compiled exception handler. Checking for exception oop equality is not 1761 // sufficient because some exceptions are pre-allocated and reused. 1762 if (!force_unwind && !recursive_exception) { 1763 nm->add_handler_for_exception_and_pc(exception,pc,handler_address); 1764 } 1765 } else { 1766 #ifdef ASSERT 1767 bool recursive_exception = false; 1768 address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); 1769 vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT, 1770 p2i(handler_address), p2i(computed_address)); 1771 #endif 1772 } 1773 } 1774 1775 current->set_exception_pc(pc); 1776 current->set_exception_handler_pc(handler_address); 1777 1778 // Check if the exception PC is a MethodHandle call site. 1779 current->set_is_method_handle_return(nm->is_method_handle_return(pc)); 1780 } 1781 1782 // Restore correct return pc. Was saved above. 1783 current->set_exception_oop(exception()); 1784 return handler_address; 1785 1786 JRT_END 1787 1788 // We are entering here from exception_blob 1789 // If there is a compiled exception handler in this method, we will continue there; 1790 // otherwise we will unwind the stack and continue at the caller of top frame method 1791 // Note we enter without the usual JRT wrapper. We will call a helper routine that 1792 // will do the normal VM entry. We do it this way so that we can see if the nmethod 1793 // we looked up the handler for has been deoptimized in the meantime. If it has been 1794 // we must not use the handler and instead return the deopt blob. 1795 address OptoRuntime::handle_exception_C(JavaThread* current) { 1796 // 1797 // We are in Java not VM and in debug mode we have a NoHandleMark 1798 // 1799 #ifndef PRODUCT 1800 SharedRuntime::_find_handler_ctr++; // find exception handler 1801 #endif 1802 debug_only(NoHandleMark __hm;) 1803 nmethod* nm = nullptr; 1804 address handler_address = nullptr; 1805 { 1806 // Enter the VM 1807 1808 ResetNoHandleMark rnhm; 1809 handler_address = handle_exception_C_helper(current, nm); 1810 } 1811 1812 // Back in java: Use no oops, DON'T safepoint 1813 1814 // Now check to see if the handler we are returning is in a now 1815 // deoptimized frame 1816 1817 if (nm != nullptr) { 1818 RegisterMap map(current, 1819 RegisterMap::UpdateMap::skip, 1820 RegisterMap::ProcessFrames::skip, 1821 RegisterMap::WalkContinuation::skip); 1822 frame caller = current->last_frame().sender(&map); 1823 #ifdef ASSERT 1824 assert(caller.is_compiled_frame(), "must be"); 1825 #endif // ASSERT 1826 if (caller.is_deoptimized_frame()) { 1827 handler_address = SharedRuntime::deopt_blob()->unpack_with_exception(); 1828 } 1829 } 1830 return handler_address; 1831 } 1832 1833 //------------------------------rethrow---------------------------------------- 1834 // We get here after compiled code has executed a 'RethrowNode'. The callee 1835 // is either throwing or rethrowing an exception. The callee-save registers 1836 // have been restored, synchronized objects have been unlocked and the callee 1837 // stack frame has been removed. The return address was passed in. 1838 // Exception oop is passed as the 1st argument. This routine is then called 1839 // from the stub. On exit, we know where to jump in the caller's code. 1840 // After this C code exits, the stub will pop his frame and end in a jump 1841 // (instead of a return). We enter the caller's default handler. 1842 // 1843 // This must be JRT_LEAF: 1844 // - caller will not change its state as we cannot block on exit, 1845 // therefore raw_exception_handler_for_return_address is all it takes 1846 // to handle deoptimized blobs 1847 // 1848 // However, there needs to be a safepoint check in the middle! So compiled 1849 // safepoints are completely watertight. 1850 // 1851 // Thus, it cannot be a leaf since it contains the NoSafepointVerifier. 1852 // 1853 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE* 1854 // 1855 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) { 1856 // ret_pc will have been loaded from the stack, so for AArch64 will be signed. 1857 AARCH64_PORT_ONLY(ret_pc = pauth_strip_verifiable(ret_pc)); 1858 1859 #ifndef PRODUCT 1860 SharedRuntime::_rethrow_ctr++; // count rethrows 1861 #endif 1862 assert (exception != nullptr, "should have thrown a NullPointerException"); 1863 #ifdef ASSERT 1864 if (!(exception->is_a(vmClasses::Throwable_klass()))) { 1865 // should throw an exception here 1866 ShouldNotReachHere(); 1867 } 1868 #endif 1869 1870 thread->set_vm_result(exception); 1871 // Frame not compiled (handles deoptimization blob) 1872 return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc); 1873 } 1874 1875 static const TypeFunc* make_rethrow_Type() { 1876 // create input type (domain) 1877 const Type **fields = TypeTuple::fields(1); 1878 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop 1879 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields); 1880 1881 // create result type (range) 1882 fields = TypeTuple::fields(1); 1883 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop 1884 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 1885 1886 return TypeFunc::make(domain, range); 1887 } 1888 1889 1890 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) { 1891 // Deoptimize the caller before continuing, as the compiled 1892 // exception handler table may not be valid. 1893 if (!StressCompiledExceptionHandlers && doit) { 1894 deoptimize_caller_frame(thread); 1895 } 1896 } 1897 1898 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) { 1899 // Called from within the owner thread, so no need for safepoint 1900 RegisterMap reg_map(thread, 1901 RegisterMap::UpdateMap::include, 1902 RegisterMap::ProcessFrames::include, 1903 RegisterMap::WalkContinuation::skip); 1904 frame stub_frame = thread->last_frame(); 1905 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check"); 1906 frame caller_frame = stub_frame.sender(®_map); 1907 1908 // Deoptimize the caller frame. 1909 Deoptimization::deoptimize_frame(thread, caller_frame.id()); 1910 } 1911 1912 1913 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) { 1914 // Called from within the owner thread, so no need for safepoint 1915 RegisterMap reg_map(thread, 1916 RegisterMap::UpdateMap::include, 1917 RegisterMap::ProcessFrames::include, 1918 RegisterMap::WalkContinuation::skip); 1919 frame stub_frame = thread->last_frame(); 1920 assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check"); 1921 frame caller_frame = stub_frame.sender(®_map); 1922 return caller_frame.is_deoptimized_frame(); 1923 } 1924 1925 static const TypeFunc* make_register_finalizer_Type() { 1926 // create input type (domain) 1927 const Type **fields = TypeTuple::fields(1); 1928 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // oop; Receiver 1929 // // The JavaThread* is passed to each routine as the last argument 1930 // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread 1931 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields); 1932 1933 // create result type (range) 1934 fields = TypeTuple::fields(0); 1935 1936 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1937 1938 return TypeFunc::make(domain,range); 1939 } 1940 1941 #if INCLUDE_JFR 1942 static const TypeFunc* make_class_id_load_barrier_Type() { 1943 // create input type (domain) 1944 const Type **fields = TypeTuple::fields(1); 1945 fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS; 1946 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields); 1947 1948 // create result type (range) 1949 fields = TypeTuple::fields(0); 1950 1951 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields); 1952 1953 return TypeFunc::make(domain,range); 1954 } 1955 #endif // INCLUDE_JFR 1956 1957 //----------------------------------------------------------------------------- 1958 static const TypeFunc* make_dtrace_method_entry_exit_Type() { 1959 // create input type (domain) 1960 const Type **fields = TypeTuple::fields(2); 1961 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage 1962 fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering 1963 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 1964 1965 // create result type (range) 1966 fields = TypeTuple::fields(0); 1967 1968 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1969 1970 return TypeFunc::make(domain,range); 1971 } 1972 1973 static const TypeFunc* make_dtrace_object_alloc_Type() { 1974 // create input type (domain) 1975 const Type **fields = TypeTuple::fields(2); 1976 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage 1977 fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL; // oop; newly allocated object 1978 1979 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields); 1980 1981 // create result type (range) 1982 fields = TypeTuple::fields(0); 1983 1984 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1985 1986 return TypeFunc::make(domain,range); 1987 } 1988 1989 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer_C(oopDesc* obj, JavaThread* current)) 1990 assert(oopDesc::is_oop(obj), "must be a valid oop"); 1991 assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); 1992 InstanceKlass::register_finalizer(instanceOop(obj), CHECK); 1993 JRT_END 1994 1995 //----------------------------------------------------------------------------- 1996 1997 NamedCounter * volatile OptoRuntime::_named_counters = nullptr; 1998 1999 // 2000 // dump the collected NamedCounters. 2001 // 2002 void OptoRuntime::print_named_counters() { 2003 int total_lock_count = 0; 2004 int eliminated_lock_count = 0; 2005 2006 NamedCounter* c = _named_counters; 2007 while (c) { 2008 if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) { 2009 int count = c->count(); 2010 if (count > 0) { 2011 bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter; 2012 if (Verbose) { 2013 tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : ""); 2014 } 2015 total_lock_count += count; 2016 if (eliminated) { 2017 eliminated_lock_count += count; 2018 } 2019 } 2020 } 2021 c = c->next(); 2022 } 2023 if (total_lock_count > 0) { 2024 tty->print_cr("dynamic locks: %d", total_lock_count); 2025 if (eliminated_lock_count) { 2026 tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count, 2027 (int)(eliminated_lock_count * 100.0 / total_lock_count)); 2028 } 2029 } 2030 } 2031 2032 // 2033 // Allocate a new NamedCounter. The JVMState is used to generate the 2034 // name which consists of method@line for the inlining tree. 2035 // 2036 2037 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) { 2038 int max_depth = youngest_jvms->depth(); 2039 2040 // Visit scopes from youngest to oldest. 2041 bool first = true; 2042 stringStream st; 2043 for (int depth = max_depth; depth >= 1; depth--) { 2044 JVMState* jvms = youngest_jvms->of_depth(depth); 2045 ciMethod* m = jvms->has_method() ? jvms->method() : nullptr; 2046 if (!first) { 2047 st.print(" "); 2048 } else { 2049 first = false; 2050 } 2051 int bci = jvms->bci(); 2052 if (bci < 0) bci = 0; 2053 if (m != nullptr) { 2054 st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8()); 2055 } else { 2056 st.print("no method"); 2057 } 2058 st.print("@%d", bci); 2059 // To print linenumbers instead of bci use: m->line_number_from_bci(bci) 2060 } 2061 NamedCounter* c = new NamedCounter(st.freeze(), tag); 2062 2063 // atomically add the new counter to the head of the list. We only 2064 // add counters so this is safe. 2065 NamedCounter* head; 2066 do { 2067 c->set_next(nullptr); 2068 head = _named_counters; 2069 c->set_next(head); 2070 } while (Atomic::cmpxchg(&_named_counters, head, c) != head); 2071 return c; 2072 } 2073 2074 void OptoRuntime::initialize_types() { 2075 _new_instance_Type = make_new_instance_Type(); 2076 _new_array_Type = make_new_array_Type(); 2077 _multianewarray2_Type = multianewarray_Type(2); 2078 _multianewarray3_Type = multianewarray_Type(3); 2079 _multianewarray4_Type = multianewarray_Type(4); 2080 _multianewarray5_Type = multianewarray_Type(5); 2081 _multianewarrayN_Type = make_multianewarrayN_Type(); 2082 _complete_monitor_enter_Type = make_complete_monitor_enter_Type(); 2083 _complete_monitor_exit_Type = make_complete_monitor_exit_Type(); 2084 _monitor_notify_Type = make_monitor_notify_Type(); 2085 _uncommon_trap_Type = make_uncommon_trap_Type(); 2086 _athrow_Type = make_athrow_Type(); 2087 _rethrow_Type = make_rethrow_Type(); 2088 _Math_D_D_Type = make_Math_D_D_Type(); 2089 _Math_DD_D_Type = make_Math_DD_D_Type(); 2090 _modf_Type = make_modf_Type(); 2091 _l2f_Type = make_l2f_Type(); 2092 _void_long_Type = make_void_long_Type(); 2093 _void_void_Type = make_void_void_Type(); 2094 _jfr_write_checkpoint_Type = make_jfr_write_checkpoint_Type(); 2095 _flush_windows_Type = make_flush_windows_Type(); 2096 _fast_arraycopy_Type = make_arraycopy_Type(ac_fast); 2097 _checkcast_arraycopy_Type = make_arraycopy_Type(ac_checkcast); 2098 _generic_arraycopy_Type = make_arraycopy_Type(ac_generic); 2099 _slow_arraycopy_Type = make_arraycopy_Type(ac_slow); 2100 _unsafe_setmemory_Type = make_setmemory_Type(); 2101 _array_fill_Type = make_array_fill_Type(); 2102 _array_sort_Type = make_array_sort_Type(); 2103 _array_partition_Type = make_array_partition_Type(); 2104 _aescrypt_block_Type = make_aescrypt_block_Type(); 2105 _cipherBlockChaining_aescrypt_Type = make_cipherBlockChaining_aescrypt_Type(); 2106 _electronicCodeBook_aescrypt_Type = make_electronicCodeBook_aescrypt_Type(); 2107 _counterMode_aescrypt_Type = make_counterMode_aescrypt_Type(); 2108 _galoisCounterMode_aescrypt_Type = make_galoisCounterMode_aescrypt_Type(); 2109 _digestBase_implCompress_with_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ true); 2110 _digestBase_implCompress_without_sha3_Type = make_digestBase_implCompress_Type( /* is_sha3= */ false);; 2111 _digestBase_implCompressMB_with_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ true); 2112 _digestBase_implCompressMB_without_sha3_Type = make_digestBase_implCompressMB_Type(/* is_sha3= */ false); 2113 _double_keccak_Type = make_double_keccak_Type(); 2114 _multiplyToLen_Type = make_multiplyToLen_Type(); 2115 _montgomeryMultiply_Type = make_montgomeryMultiply_Type(); 2116 _montgomerySquare_Type = make_montgomerySquare_Type(); 2117 _squareToLen_Type = make_squareToLen_Type(); 2118 _mulAdd_Type = make_mulAdd_Type(); 2119 _bigIntegerShift_Type = make_bigIntegerShift_Type(); 2120 _vectorizedMismatch_Type = make_vectorizedMismatch_Type(); 2121 _ghash_processBlocks_Type = make_ghash_processBlocks_Type(); 2122 _chacha20Block_Type = make_chacha20Block_Type(); 2123 2124 _dilithiumAlmostNtt_Type = make_dilithiumAlmostNtt_Type(); 2125 _dilithiumAlmostInverseNtt_Type = make_dilithiumAlmostInverseNtt_Type(); 2126 _dilithiumNttMult_Type = make_dilithiumNttMult_Type(); 2127 _dilithiumMontMulByConstant_Type = make_dilithiumMontMulByConstant_Type(); 2128 _dilithiumDecomposePoly_Type = make_dilithiumDecomposePoly_Type(); 2129 2130 _base64_encodeBlock_Type = make_base64_encodeBlock_Type(); 2131 _base64_decodeBlock_Type = make_base64_decodeBlock_Type(); 2132 _string_IndexOf_Type = make_string_IndexOf_Type(); 2133 _poly1305_processBlocks_Type = make_poly1305_processBlocks_Type(); 2134 _intpoly_montgomeryMult_P256_Type = make_intpoly_montgomeryMult_P256_Type(); 2135 _intpoly_assign_Type = make_intpoly_assign_Type(); 2136 _updateBytesCRC32_Type = make_updateBytesCRC32_Type(); 2137 _updateBytesCRC32C_Type = make_updateBytesCRC32C_Type(); 2138 _updateBytesAdler32_Type = make_updateBytesAdler32_Type(); 2139 _osr_end_Type = make_osr_end_Type(); 2140 _register_finalizer_Type = make_register_finalizer_Type(); 2141 JFR_ONLY( 2142 _class_id_load_barrier_Type = make_class_id_load_barrier_Type(); 2143 ) 2144 #if INCLUDE_JVMTI 2145 _notify_jvmti_vthread_Type = make_notify_jvmti_vthread_Type(); 2146 #endif // INCLUDE_JVMTI 2147 _dtrace_method_entry_exit_Type = make_dtrace_method_entry_exit_Type(); 2148 _dtrace_object_alloc_Type = make_dtrace_object_alloc_Type(); 2149 } 2150 2151 int trace_exception_counter = 0; 2152 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) { 2153 trace_exception_counter++; 2154 stringStream tempst; 2155 2156 tempst.print("%d [Exception (%s): ", trace_exception_counter, msg); 2157 exception_oop->print_value_on(&tempst); 2158 tempst.print(" in "); 2159 CodeBlob* blob = CodeCache::find_blob(exception_pc); 2160 if (blob->is_nmethod()) { 2161 blob->as_nmethod()->method()->print_value_on(&tempst); 2162 } else if (blob->is_runtime_stub()) { 2163 tempst.print("<runtime-stub>"); 2164 } else { 2165 tempst.print("<unknown>"); 2166 } 2167 tempst.print(" at " INTPTR_FORMAT, p2i(exception_pc)); 2168 tempst.print("]"); 2169 2170 st->print_raw_cr(tempst.freeze()); 2171 }