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