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