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