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