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