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