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