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