1 /*
   2  * Copyright (c) 1998, 2024, 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 "precompiled.hpp"
  26 #include "classfile/vmClasses.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "code/compiledIC.hpp"
  30 #include "code/nmethod.hpp"
  31 #include "code/pcDesc.hpp"
  32 #include "code/scopeDesc.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "gc/g1/g1HeapRegion.hpp"
  37 #include "gc/shared/barrierSet.hpp"
  38 #include "gc/shared/collectedHeap.hpp"
  39 #include "gc/shared/gcLocker.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/flatArrayKlass.hpp"
  48 #include "oops/flatArrayOop.inline.hpp"
  49 #include "oops/objArrayKlass.hpp"
  50 #include "oops/klass.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/typeArrayOop.inline.hpp"
  53 #include "opto/ad.hpp"
  54 #include "opto/addnode.hpp"
  55 #include "opto/callnode.hpp"
  56 #include "opto/cfgnode.hpp"
  57 #include "opto/graphKit.hpp"
  58 #include "opto/machnode.hpp"
  59 #include "opto/matcher.hpp"
  60 #include "opto/memnode.hpp"
  61 #include "opto/mulnode.hpp"
  62 #include "opto/output.hpp"
  63 #include "opto/runtime.hpp"
  64 #include "opto/subnode.hpp"
  65 #include "prims/jvmtiExport.hpp"
  66 #include "runtime/atomic.hpp"
  67 #include "runtime/frame.inline.hpp"
  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/interfaceSupport.inline.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/sharedRuntime.hpp"
  72 #include "runtime/signature.hpp"
  73 #include "runtime/stackWatermarkSet.hpp"
  74 #include "runtime/synchronizer.hpp"
  75 #include "runtime/threadCritical.hpp"
  76 #include "runtime/threadWXSetters.inline.hpp"
  77 #include "runtime/vframe.hpp"
  78 #include "runtime/vframeArray.hpp"
  79 #include "runtime/vframe_hp.hpp"
  80 #include "utilities/copy.hpp"
  81 #include "utilities/preserveException.hpp"
  82 
  83 
  84 // For debugging purposes:
  85 //  To force FullGCALot inside a runtime function, add the following two lines
  86 //
  87 //  Universe::release_fullgc_alot_dummy();
  88 //  Universe::heap()->collect();
  89 //
  90 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
  91 
  92 
  93 
  94 
  95 // Compiled code entry points
  96 address OptoRuntime::_new_instance_Java                           = nullptr;
  97 address OptoRuntime::_new_array_Java                              = nullptr;
  98 address OptoRuntime::_new_array_nozero_Java                       = nullptr;
  99 address OptoRuntime::_multianewarray2_Java                        = nullptr;
 100 address OptoRuntime::_multianewarray3_Java                        = nullptr;
 101 address OptoRuntime::_multianewarray4_Java                        = nullptr;
 102 address OptoRuntime::_multianewarray5_Java                        = nullptr;
 103 address OptoRuntime::_multianewarrayN_Java                        = nullptr;
 104 address OptoRuntime::_vtable_must_compile_Java                    = nullptr;
 105 address OptoRuntime::_complete_monitor_locking_Java               = nullptr;
 106 address OptoRuntime::_monitor_notify_Java                         = nullptr;
 107 address OptoRuntime::_monitor_notifyAll_Java                      = nullptr;
 108 address OptoRuntime::_rethrow_Java                                = nullptr;
 109 address OptoRuntime::_slow_arraycopy_Java                         = nullptr;
 110 address OptoRuntime::_register_finalizer_Java                     = nullptr;
 111 address OptoRuntime::_load_unknown_inline                         = nullptr;
 112 #if INCLUDE_JVMTI
 113 address OptoRuntime::_notify_jvmti_vthread_start                  = nullptr;
 114 address OptoRuntime::_notify_jvmti_vthread_end                    = nullptr;
 115 address OptoRuntime::_notify_jvmti_vthread_mount                  = nullptr;
 116 address OptoRuntime::_notify_jvmti_vthread_unmount                = nullptr;
 117 #endif
 118 
 119 UncommonTrapBlob*   OptoRuntime::_uncommon_trap_blob;
 120 ExceptionBlob*      OptoRuntime::_exception_blob;
 121 
 122 // This should be called in an assertion at the start of OptoRuntime routines
 123 // which are entered from compiled code (all of them)
 124 #ifdef ASSERT
 125 static bool check_compiled_frame(JavaThread* thread) {
 126   assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
 127   RegisterMap map(thread,
 128                   RegisterMap::UpdateMap::skip,
 129                   RegisterMap::ProcessFrames::include,
 130                   RegisterMap::WalkContinuation::skip);
 131   frame caller = thread->last_frame().sender(&map);
 132   assert(caller.is_compiled_frame(), "not being called from compiled like code");
 133   return true;
 134 }
 135 #endif // ASSERT
 136 
 137 
 138 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, return_pc) \
 139   var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, return_pc); \
 140   if (var == nullptr) { return false; }
 141 
 142 bool OptoRuntime::generate(ciEnv* env) {
 143 
 144   generate_uncommon_trap_blob();
 145   generate_exception_blob();
 146 
 147   // Note: tls: Means fetching the return oop out of the thread-local storage
 148   //
 149   //   variable/name                       type-function-gen              , runtime method                  ,fncy_jp, tls,retpc
 150   // -------------------------------------------------------------------------------------------------------------------------------
 151   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true, false);
 152   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true, false);
 153   gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true, false);
 154   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true, false);
 155   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true, false);
 156   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true, false);
 157   gen(env, _multianewarray5_Java           , multianewarray5_Type         , multianewarray5_C               ,    0 , true, false);
 158   gen(env, _multianewarrayN_Java           , multianewarrayN_Type         , multianewarrayN_C               ,    0 , true, false);
 159 #if INCLUDE_JVMTI
 160   gen(env, _notify_jvmti_vthread_start     , notify_jvmti_vthread_Type    , SharedRuntime::notify_jvmti_vthread_start, 0, true, false);
 161   gen(env, _notify_jvmti_vthread_end       , notify_jvmti_vthread_Type    , SharedRuntime::notify_jvmti_vthread_end,   0, true, false);
 162   gen(env, _notify_jvmti_vthread_mount     , notify_jvmti_vthread_Type    , SharedRuntime::notify_jvmti_vthread_mount, 0, true, false);
 163   gen(env, _notify_jvmti_vthread_unmount   , notify_jvmti_vthread_Type    , SharedRuntime::notify_jvmti_vthread_unmount, 0, true, false);
 164 #endif
 165   gen(env, _complete_monitor_locking_Java  , complete_monitor_enter_Type  , SharedRuntime::complete_monitor_locking_C, 0, false, false);
 166   gen(env, _monitor_notify_Java            , monitor_notify_Type          , monitor_notify_C                ,    0 , false, false);
 167   gen(env, _monitor_notifyAll_Java         , monitor_notify_Type          , monitor_notifyAll_C             ,    0 , false, false);
 168   gen(env, _rethrow_Java                   , rethrow_Type                 , rethrow_C                       ,    2 , true , true );
 169   gen(env, _slow_arraycopy_Java            , slow_arraycopy_Type          , SharedRuntime::slow_arraycopy_C ,    0 , false, false);
 170   gen(env, _register_finalizer_Java        , register_finalizer_Type      , register_finalizer              ,    0 , false, false);
 171   gen(env, _load_unknown_inline            , load_unknown_inline_type     , load_unknown_inline             ,    0 , true,  false);
 172 
 173   return true;
 174 }
 175 
 176 #undef gen
 177 
 178 
 179 // Helper method to do generation of RunTimeStub's
 180 address OptoRuntime::generate_stub(ciEnv* env,
 181                                    TypeFunc_generator gen, address C_function,
 182                                    const char *name, int is_fancy_jump,
 183                                    bool pass_tls,
 184                                    bool return_pc) {
 185 
 186   // Matching the default directive, we currently have no method to match.
 187   DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
 188   ResourceMark rm;
 189   Compile C(env, gen, C_function, name, is_fancy_jump, pass_tls, return_pc, directive);
 190   DirectivesStack::release(directive);
 191   return  C.stub_entry_point();
 192 }
 193 
 194 const char* OptoRuntime::stub_name(address entry) {
 195 #ifndef PRODUCT
 196   CodeBlob* cb = CodeCache::find_blob(entry);
 197   RuntimeStub* rs =(RuntimeStub *)cb;
 198   assert(rs != nullptr && rs->is_runtime_stub(), "not a runtime stub");
 199   return rs->name();
 200 #else
 201   // Fast implementation for product mode (maybe it should be inlined too)
 202   return "runtime stub";
 203 #endif
 204 }
 205 
 206 
 207 //=============================================================================
 208 // Opto compiler runtime routines
 209 //=============================================================================
 210 
 211 
 212 //=============================allocation======================================
 213 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 214 // and try allocation again.
 215 
 216 // object allocation
 217 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, bool is_larval, JavaThread* current))
 218   JRT_BLOCK;
 219 #ifndef PRODUCT
 220   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 221 #endif
 222   assert(check_compiled_frame(current), "incorrect caller");
 223 
 224   // These checks are cheap to make and support reflective allocation.
 225   int lh = klass->layout_helper();
 226   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 227     Handle holder(current, klass->klass_holder()); // keep the klass alive
 228     klass->check_valid_for_instantiation(false, THREAD);
 229     if (!HAS_PENDING_EXCEPTION) {
 230       InstanceKlass::cast(klass)->initialize(THREAD);
 231     }
 232   }
 233 
 234   if (!HAS_PENDING_EXCEPTION) {
 235     // Scavenge and allocate an instance.
 236     Handle holder(current, klass->klass_holder()); // keep the klass alive
 237     instanceOop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 238     if (is_larval) {
 239       // Check if this is a larval buffer allocation
 240       result->set_mark(result->mark().enter_larval_state());
 241     }
 242     current->set_vm_result(result);
 243 
 244     // Pass oops back through thread local storage.  Our apparent type to Java
 245     // is that we return an oop, but we can block on exit from this routine and
 246     // a GC can trash the oop in C's return register.  The generated stub will
 247     // fetch the oop from TLS after any possible GC.
 248   }
 249 
 250   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 251   JRT_BLOCK_END;
 252 
 253   // inform GC that we won't do card marks for initializing writes.
 254   SharedRuntime::on_slowpath_allocation_exit(current);
 255 JRT_END
 256 
 257 
 258 // array allocation
 259 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread* current))
 260   JRT_BLOCK;
 261 #ifndef PRODUCT
 262   SharedRuntime::_new_array_ctr++;            // new array requires GC
 263 #endif
 264   assert(check_compiled_frame(current), "incorrect caller");
 265 
 266   // Scavenge and allocate an instance.
 267   oop result;
 268 
 269   if (array_type->is_flatArray_klass()) {
 270     Klass* elem_type = FlatArrayKlass::cast(array_type)->element_klass();
 271     result = oopFactory::new_valueArray(elem_type, len, THREAD);
 272   } else if (array_type->is_typeArray_klass()) {
 273     // The oopFactory likes to work with the element type.
 274     // (We could bypass the oopFactory, since it doesn't add much value.)
 275     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 276     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 277   } else {
 278     Handle holder(current, array_type->klass_holder()); // keep the array klass alive
 279     result = ObjArrayKlass::cast(array_type)->allocate(len, THREAD);
 280   }
 281 
 282   // Pass oops back through thread local storage.  Our apparent type to Java
 283   // is that we return an oop, but we can block on exit from this routine and
 284   // a GC can trash the oop in C's return register.  The generated stub will
 285   // fetch the oop from TLS after any possible GC.
 286   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 287   current->set_vm_result(result);
 288   JRT_BLOCK_END;
 289 
 290   // inform GC that we won't do card marks for initializing writes.
 291   SharedRuntime::on_slowpath_allocation_exit(current);
 292 JRT_END
 293 
 294 // array allocation without zeroing
 295 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread* current))
 296   JRT_BLOCK;
 297 #ifndef PRODUCT
 298   SharedRuntime::_new_array_ctr++;            // new array requires GC
 299 #endif
 300   assert(check_compiled_frame(current), "incorrect caller");
 301 
 302   // Scavenge and allocate an instance.
 303   oop result;
 304 
 305   assert(array_type->is_typeArray_klass(), "should be called only for type array");
 306   // The oopFactory likes to work with the element type.
 307   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 308   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
 309 
 310   // Pass oops back through thread local storage.  Our apparent type to Java
 311   // is that we return an oop, but we can block on exit from this routine and
 312   // a GC can trash the oop in C's return register.  The generated stub will
 313   // fetch the oop from TLS after any possible GC.
 314   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 315   current->set_vm_result(result);
 316   JRT_BLOCK_END;
 317 
 318 
 319   // inform GC that we won't do card marks for initializing writes.
 320   SharedRuntime::on_slowpath_allocation_exit(current);
 321 
 322   oop result = current->vm_result();
 323   if ((len > 0) && (result != nullptr) &&
 324       is_deoptimized_caller_frame(current)) {
 325     // Zero array here if the caller is deoptimized.
 326     const size_t size = TypeArrayKlass::cast(array_type)->oop_size(result);
 327     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 328     size_t hs_bytes = arrayOopDesc::base_offset_in_bytes(elem_type);
 329     assert(is_aligned(hs_bytes, BytesPerInt), "must be 4 byte aligned");
 330     HeapWord* obj = cast_from_oop<HeapWord*>(result);
 331     if (!is_aligned(hs_bytes, BytesPerLong)) {
 332       *reinterpret_cast<jint*>(reinterpret_cast<char*>(obj) + hs_bytes) = 0;
 333       hs_bytes += BytesPerInt;
 334     }
 335 
 336     // Optimized zeroing.
 337     assert(is_aligned(hs_bytes, BytesPerLong), "must be 8-byte aligned");
 338     const size_t aligned_hs = hs_bytes / BytesPerLong;
 339     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
 340   }
 341 
 342 JRT_END
 343 
 344 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
 345 
 346 // multianewarray for 2 dimensions
 347 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread* current))
 348 #ifndef PRODUCT
 349   SharedRuntime::_multi2_ctr++;                // multianewarray for 1 dimension
 350 #endif
 351   assert(check_compiled_frame(current), "incorrect caller");
 352   assert(elem_type->is_klass(), "not a class");
 353   jint dims[2];
 354   dims[0] = len1;
 355   dims[1] = len2;
 356   Handle holder(current, elem_type->klass_holder()); // keep the klass alive
 357   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
 358   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 359   current->set_vm_result(obj);
 360 JRT_END
 361 
 362 // multianewarray for 3 dimensions
 363 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread* current))
 364 #ifndef PRODUCT
 365   SharedRuntime::_multi3_ctr++;                // multianewarray for 1 dimension
 366 #endif
 367   assert(check_compiled_frame(current), "incorrect caller");
 368   assert(elem_type->is_klass(), "not a class");
 369   jint dims[3];
 370   dims[0] = len1;
 371   dims[1] = len2;
 372   dims[2] = len3;
 373   Handle holder(current, elem_type->klass_holder()); // keep the klass alive
 374   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
 375   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 376   current->set_vm_result(obj);
 377 JRT_END
 378 
 379 // multianewarray for 4 dimensions
 380 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread* current))
 381 #ifndef PRODUCT
 382   SharedRuntime::_multi4_ctr++;                // multianewarray for 1 dimension
 383 #endif
 384   assert(check_compiled_frame(current), "incorrect caller");
 385   assert(elem_type->is_klass(), "not a class");
 386   jint dims[4];
 387   dims[0] = len1;
 388   dims[1] = len2;
 389   dims[2] = len3;
 390   dims[3] = len4;
 391   Handle holder(current, elem_type->klass_holder()); // keep the klass alive
 392   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
 393   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 394   current->set_vm_result(obj);
 395 JRT_END
 396 
 397 // multianewarray for 5 dimensions
 398 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread* current))
 399 #ifndef PRODUCT
 400   SharedRuntime::_multi5_ctr++;                // multianewarray for 1 dimension
 401 #endif
 402   assert(check_compiled_frame(current), "incorrect caller");
 403   assert(elem_type->is_klass(), "not a class");
 404   jint dims[5];
 405   dims[0] = len1;
 406   dims[1] = len2;
 407   dims[2] = len3;
 408   dims[3] = len4;
 409   dims[4] = len5;
 410   Handle holder(current, elem_type->klass_holder()); // keep the klass alive
 411   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
 412   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 413   current->set_vm_result(obj);
 414 JRT_END
 415 
 416 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread* current))
 417   assert(check_compiled_frame(current), "incorrect caller");
 418   assert(elem_type->is_klass(), "not a class");
 419   assert(oop(dims)->is_typeArray(), "not an array");
 420 
 421   ResourceMark rm;
 422   jint len = dims->length();
 423   assert(len > 0, "Dimensions array should contain data");
 424   jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
 425   ArrayAccess<>::arraycopy_to_native<>(dims, typeArrayOopDesc::element_offset<jint>(0),
 426                                        c_dims, len);
 427 
 428   Handle holder(current, elem_type->klass_holder()); // keep the klass alive
 429   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
 430   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
 431   current->set_vm_result(obj);
 432 JRT_END
 433 
 434 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread* current))
 435 
 436   // Very few notify/notifyAll operations find any threads on the waitset, so
 437   // the dominant fast-path is to simply return.
 438   // Relatedly, it's critical that notify/notifyAll be fast in order to
 439   // reduce lock hold times.
 440   if (!SafepointSynchronize::is_synchronizing()) {
 441     if (ObjectSynchronizer::quick_notify(obj, current, false)) {
 442       return;
 443     }
 444   }
 445 
 446   // This is the case the fast-path above isn't provisioned to handle.
 447   // The fast-path is designed to handle frequently arising cases in an efficient manner.
 448   // (The fast-path is just a degenerate variant of the slow-path).
 449   // Perform the dreaded state transition and pass control into the slow-path.
 450   JRT_BLOCK;
 451   Handle h_obj(current, obj);
 452   ObjectSynchronizer::notify(h_obj, CHECK);
 453   JRT_BLOCK_END;
 454 JRT_END
 455 
 456 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread* current))
 457 
 458   if (!SafepointSynchronize::is_synchronizing() ) {
 459     if (ObjectSynchronizer::quick_notify(obj, current, true)) {
 460       return;
 461     }
 462   }
 463 
 464   // This is the case the fast-path above isn't provisioned to handle.
 465   // The fast-path is designed to handle frequently arising cases in an efficient manner.
 466   // (The fast-path is just a degenerate variant of the slow-path).
 467   // Perform the dreaded state transition and pass control into the slow-path.
 468   JRT_BLOCK;
 469   Handle h_obj(current, obj);
 470   ObjectSynchronizer::notifyall(h_obj, CHECK);
 471   JRT_BLOCK_END;
 472 JRT_END
 473 
 474 const TypeFunc *OptoRuntime::new_instance_Type() {
 475   // create input type (domain)
 476   const Type **fields = TypeTuple::fields(2);
 477   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 478   fields[TypeFunc::Parms+1] = TypeInt::BOOL;        // is_larval
 479   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 480 
 481   // create result type (range)
 482   fields = TypeTuple::fields(1);
 483   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 484 
 485   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 486 
 487   return TypeFunc::make(domain, range);
 488 }
 489 
 490 #if INCLUDE_JVMTI
 491 const TypeFunc *OptoRuntime::notify_jvmti_vthread_Type() {
 492   // create input type (domain)
 493   const Type **fields = TypeTuple::fields(2);
 494   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // VirtualThread oop
 495   fields[TypeFunc::Parms+1] = TypeInt::BOOL;        // jboolean
 496   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 497 
 498   // no result type needed
 499   fields = TypeTuple::fields(1);
 500   fields[TypeFunc::Parms+0] = nullptr; // void
 501   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 502 
 503   return TypeFunc::make(domain,range);
 504 }
 505 #endif
 506 
 507 const TypeFunc *OptoRuntime::athrow_Type() {
 508   // create input type (domain)
 509   const Type **fields = TypeTuple::fields(1);
 510   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 511   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 512 
 513   // create result type (range)
 514   fields = TypeTuple::fields(0);
 515 
 516   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 517 
 518   return TypeFunc::make(domain, range);
 519 }
 520 
 521 
 522 const TypeFunc *OptoRuntime::new_array_Type() {
 523   // create input type (domain)
 524   const Type **fields = TypeTuple::fields(2);
 525   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 526   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 527   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 528 
 529   // create result type (range)
 530   fields = TypeTuple::fields(1);
 531   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 532 
 533   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 534 
 535   return TypeFunc::make(domain, range);
 536 }
 537 
 538 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
 539   // create input type (domain)
 540   const int nargs = ndim + 1;
 541   const Type **fields = TypeTuple::fields(nargs);
 542   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 543   for( int i = 1; i < nargs; i++ )
 544     fields[TypeFunc::Parms + i] = TypeInt::INT;       // array size
 545   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
 546 
 547   // create result type (range)
 548   fields = TypeTuple::fields(1);
 549   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 550   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 551 
 552   return TypeFunc::make(domain, range);
 553 }
 554 
 555 const TypeFunc *OptoRuntime::multianewarray2_Type() {
 556   return multianewarray_Type(2);
 557 }
 558 
 559 const TypeFunc *OptoRuntime::multianewarray3_Type() {
 560   return multianewarray_Type(3);
 561 }
 562 
 563 const TypeFunc *OptoRuntime::multianewarray4_Type() {
 564   return multianewarray_Type(4);
 565 }
 566 
 567 const TypeFunc *OptoRuntime::multianewarray5_Type() {
 568   return multianewarray_Type(5);
 569 }
 570 
 571 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
 572   // create input type (domain)
 573   const Type **fields = TypeTuple::fields(2);
 574   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 575   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;   // array of dim sizes
 576   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 577 
 578   // create result type (range)
 579   fields = TypeTuple::fields(1);
 580   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 581   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 582 
 583   return TypeFunc::make(domain, range);
 584 }
 585 
 586 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
 587   // create input type (domain)
 588   const Type **fields = TypeTuple::fields(1);
 589   fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
 590   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 591 
 592   // create result type (range)
 593   fields = TypeTuple::fields(0);
 594   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 595 
 596   return TypeFunc::make(domain, range);
 597 }
 598 
 599 //-----------------------------------------------------------------------------
 600 // Monitor Handling
 601 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
 602   // create input type (domain)
 603   const Type **fields = TypeTuple::fields(2);
 604   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 605   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;   // Address of stack location for lock
 606   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 607 
 608   // create result type (range)
 609   fields = TypeTuple::fields(0);
 610 
 611   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
 612 
 613   return TypeFunc::make(domain, range);
 614 }
 615 
 616 
 617 //-----------------------------------------------------------------------------
 618 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
 619   // create input type (domain)
 620   const Type **fields = TypeTuple::fields(3);
 621   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 622   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;    // Address of stack location for lock - BasicLock
 623   fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM;    // Thread pointer (Self)
 624   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 625 
 626   // create result type (range)
 627   fields = TypeTuple::fields(0);
 628 
 629   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 630 
 631   return TypeFunc::make(domain, range);
 632 }
 633 
 634 const TypeFunc *OptoRuntime::monitor_notify_Type() {
 635   // create input type (domain)
 636   const Type **fields = TypeTuple::fields(1);
 637   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 638   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 639 
 640   // create result type (range)
 641   fields = TypeTuple::fields(0);
 642   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 643   return TypeFunc::make(domain, range);
 644 }
 645 
 646 const TypeFunc* OptoRuntime::flush_windows_Type() {
 647   // create input type (domain)
 648   const Type** fields = TypeTuple::fields(1);
 649   fields[TypeFunc::Parms+0] = nullptr; // void
 650   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
 651 
 652   // create result type
 653   fields = TypeTuple::fields(1);
 654   fields[TypeFunc::Parms+0] = nullptr; // void
 655   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 656 
 657   return TypeFunc::make(domain, range);
 658 }
 659 
 660 const TypeFunc* OptoRuntime::l2f_Type() {
 661   // create input type (domain)
 662   const Type **fields = TypeTuple::fields(2);
 663   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 664   fields[TypeFunc::Parms+1] = Type::HALF;
 665   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 666 
 667   // create result type (range)
 668   fields = TypeTuple::fields(1);
 669   fields[TypeFunc::Parms+0] = Type::FLOAT;
 670   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 671 
 672   return TypeFunc::make(domain, range);
 673 }
 674 
 675 const TypeFunc* OptoRuntime::modf_Type() {
 676   const Type **fields = TypeTuple::fields(2);
 677   fields[TypeFunc::Parms+0] = Type::FLOAT;
 678   fields[TypeFunc::Parms+1] = Type::FLOAT;
 679   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 680 
 681   // create result type (range)
 682   fields = TypeTuple::fields(1);
 683   fields[TypeFunc::Parms+0] = Type::FLOAT;
 684 
 685   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 686 
 687   return TypeFunc::make(domain, range);
 688 }
 689 
 690 const TypeFunc *OptoRuntime::Math_D_D_Type() {
 691   // create input type (domain)
 692   const Type **fields = TypeTuple::fields(2);
 693   // Symbol* name of class to be loaded
 694   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 695   fields[TypeFunc::Parms+1] = Type::HALF;
 696   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 697 
 698   // create result type (range)
 699   fields = TypeTuple::fields(2);
 700   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 701   fields[TypeFunc::Parms+1] = Type::HALF;
 702   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 703 
 704   return TypeFunc::make(domain, range);
 705 }
 706 
 707 const TypeFunc *OptoRuntime::Math_Vector_Vector_Type(uint num_arg, const TypeVect* in_type, const TypeVect* out_type) {
 708   // create input type (domain)
 709   const Type **fields = TypeTuple::fields(num_arg);
 710   // Symbol* name of class to be loaded
 711   assert(num_arg > 0, "must have at least 1 input");
 712   for (uint i = 0; i < num_arg; i++) {
 713     fields[TypeFunc::Parms+i] = in_type;
 714   }
 715   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+num_arg, fields);
 716 
 717   // create result type (range)
 718   const uint num_ret = 1;
 719   fields = TypeTuple::fields(num_ret);
 720   fields[TypeFunc::Parms+0] = out_type;
 721   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+num_ret, fields);
 722 
 723   return TypeFunc::make(domain, range);
 724 }
 725 
 726 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
 727   const Type **fields = TypeTuple::fields(4);
 728   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 729   fields[TypeFunc::Parms+1] = Type::HALF;
 730   fields[TypeFunc::Parms+2] = Type::DOUBLE;
 731   fields[TypeFunc::Parms+3] = Type::HALF;
 732   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
 733 
 734   // create result type (range)
 735   fields = TypeTuple::fields(2);
 736   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 737   fields[TypeFunc::Parms+1] = Type::HALF;
 738   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 739 
 740   return TypeFunc::make(domain, range);
 741 }
 742 
 743 //-------------- currentTimeMillis, currentTimeNanos, etc
 744 
 745 const TypeFunc* OptoRuntime::void_long_Type() {
 746   // create input type (domain)
 747   const Type **fields = TypeTuple::fields(0);
 748   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
 749 
 750   // create result type (range)
 751   fields = TypeTuple::fields(2);
 752   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 753   fields[TypeFunc::Parms+1] = Type::HALF;
 754   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 755 
 756   return TypeFunc::make(domain, range);
 757 }
 758 
 759 const TypeFunc* OptoRuntime::void_void_Type() {
 760    // create input type (domain)
 761    const Type **fields = TypeTuple::fields(0);
 762    const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
 763 
 764    // create result type (range)
 765    fields = TypeTuple::fields(0);
 766    const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 767    return TypeFunc::make(domain, range);
 768  }
 769 
 770  const TypeFunc* OptoRuntime::jfr_write_checkpoint_Type() {
 771    // create input type (domain)
 772    const Type **fields = TypeTuple::fields(0);
 773    const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
 774 
 775    // create result type (range)
 776    fields = TypeTuple::fields(0);
 777    const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 778    return TypeFunc::make(domain, range);
 779  }
 780 
 781 
 782 // Takes as parameters:
 783 // void *dest
 784 // long size
 785 // uchar byte
 786 const TypeFunc* OptoRuntime::make_setmemory_Type() {
 787   // create input type (domain)
 788   int argcnt = NOT_LP64(3) LP64_ONLY(4);
 789   const Type** fields = TypeTuple::fields(argcnt);
 790   int argp = TypeFunc::Parms;
 791   fields[argp++] = TypePtr::NOTNULL;        // dest
 792   fields[argp++] = TypeX_X;                 // size
 793   LP64_ONLY(fields[argp++] = Type::HALF);   // size
 794   fields[argp++] = TypeInt::UBYTE;          // bytevalue
 795   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 796   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 797 
 798   // no result type needed
 799   fields = TypeTuple::fields(1);
 800   fields[TypeFunc::Parms+0] = nullptr; // void
 801   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 802   return TypeFunc::make(domain, range);
 803 }
 804 
 805 // arraycopy stub variations:
 806 enum ArrayCopyType {
 807   ac_fast,                      // void(ptr, ptr, size_t)
 808   ac_checkcast,                 //  int(ptr, ptr, size_t, size_t, ptr)
 809   ac_slow,                      // void(ptr, int, ptr, int, int)
 810   ac_generic                    //  int(ptr, int, ptr, int, int)
 811 };
 812 
 813 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
 814   // create input type (domain)
 815   int num_args      = (act == ac_fast ? 3 : 5);
 816   int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
 817   int argcnt = num_args;
 818   LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
 819   const Type** fields = TypeTuple::fields(argcnt);
 820   int argp = TypeFunc::Parms;
 821   fields[argp++] = TypePtr::NOTNULL;    // src
 822   if (num_size_args == 0) {
 823     fields[argp++] = TypeInt::INT;      // src_pos
 824   }
 825   fields[argp++] = TypePtr::NOTNULL;    // dest
 826   if (num_size_args == 0) {
 827     fields[argp++] = TypeInt::INT;      // dest_pos
 828     fields[argp++] = TypeInt::INT;      // length
 829   }
 830   while (num_size_args-- > 0) {
 831     fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 832     LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 833   }
 834   if (act == ac_checkcast) {
 835     fields[argp++] = TypePtr::NOTNULL;  // super_klass
 836   }
 837   assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
 838   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 839 
 840   // create result type if needed
 841   int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
 842   fields = TypeTuple::fields(1);
 843   if (retcnt == 0)
 844     fields[TypeFunc::Parms+0] = nullptr; // void
 845   else
 846     fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
 847   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
 848   return TypeFunc::make(domain, range);
 849 }
 850 
 851 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
 852   // This signature is simple:  Two base pointers and a size_t.
 853   return make_arraycopy_Type(ac_fast);
 854 }
 855 
 856 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
 857   // An extension of fast_arraycopy_Type which adds type checking.
 858   return make_arraycopy_Type(ac_checkcast);
 859 }
 860 
 861 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
 862   // This signature is exactly the same as System.arraycopy.
 863   // There are no intptr_t (int/long) arguments.
 864   return make_arraycopy_Type(ac_slow);
 865 }
 866 
 867 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
 868   // This signature is like System.arraycopy, except that it returns status.
 869   return make_arraycopy_Type(ac_generic);
 870 }
 871 
 872 
 873 const TypeFunc* OptoRuntime::array_fill_Type() {
 874   const Type** fields;
 875   int argp = TypeFunc::Parms;
 876   // create input type (domain): pointer, int, size_t
 877   fields = TypeTuple::fields(3 LP64_ONLY( + 1));
 878   fields[argp++] = TypePtr::NOTNULL;
 879   fields[argp++] = TypeInt::INT;
 880   fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 881   LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 882   const TypeTuple *domain = TypeTuple::make(argp, fields);
 883 
 884   // create result type
 885   fields = TypeTuple::fields(1);
 886   fields[TypeFunc::Parms+0] = nullptr; // void
 887   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 888 
 889   return TypeFunc::make(domain, range);
 890 }
 891 
 892 const TypeFunc* OptoRuntime::array_partition_Type() {
 893   // create input type (domain)
 894   int num_args = 7;
 895   int argcnt = num_args;
 896   const Type** fields = TypeTuple::fields(argcnt);
 897   int argp = TypeFunc::Parms;
 898   fields[argp++] = TypePtr::NOTNULL;  // array
 899   fields[argp++] = TypeInt::INT;      // element type
 900   fields[argp++] = TypeInt::INT;      // low
 901   fields[argp++] = TypeInt::INT;      // end
 902   fields[argp++] = TypePtr::NOTNULL;  // pivot_indices (int array)
 903   fields[argp++] = TypeInt::INT;      // indexPivot1
 904   fields[argp++] = TypeInt::INT;      // indexPivot2
 905   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 906   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 907 
 908   // no result type needed
 909   fields = TypeTuple::fields(1);
 910   fields[TypeFunc::Parms+0] = nullptr; // void
 911   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 912   return TypeFunc::make(domain, range);
 913 }
 914 
 915 const TypeFunc* OptoRuntime::array_sort_Type() {
 916   // create input type (domain)
 917   int num_args      = 4;
 918   int argcnt = num_args;
 919   const Type** fields = TypeTuple::fields(argcnt);
 920   int argp = TypeFunc::Parms;
 921   fields[argp++] = TypePtr::NOTNULL;    // array
 922   fields[argp++] = TypeInt::INT;    // element type
 923   fields[argp++] = TypeInt::INT;    // fromIndex
 924   fields[argp++] = TypeInt::INT;    // toIndex
 925   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 926   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 927 
 928   // no result type needed
 929   fields = TypeTuple::fields(1);
 930   fields[TypeFunc::Parms+0] = nullptr; // void
 931   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 932   return TypeFunc::make(domain, range);
 933 }
 934 
 935 // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant)
 936 const TypeFunc* OptoRuntime::aescrypt_block_Type() {
 937   // create input type (domain)
 938   int num_args      = 3;
 939   int argcnt = num_args;
 940   const Type** fields = TypeTuple::fields(argcnt);
 941   int argp = TypeFunc::Parms;
 942   fields[argp++] = TypePtr::NOTNULL;    // src
 943   fields[argp++] = TypePtr::NOTNULL;    // dest
 944   fields[argp++] = TypePtr::NOTNULL;    // k array
 945   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 946   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 947 
 948   // no result type needed
 949   fields = TypeTuple::fields(1);
 950   fields[TypeFunc::Parms+0] = nullptr; // void
 951   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 952   return TypeFunc::make(domain, range);
 953 }
 954 
 955 /**
 956  * int updateBytesCRC32(int crc, byte* b, int len)
 957  */
 958 const TypeFunc* OptoRuntime::updateBytesCRC32_Type() {
 959   // create input type (domain)
 960   int num_args      = 3;
 961   int argcnt = num_args;
 962   const Type** fields = TypeTuple::fields(argcnt);
 963   int argp = TypeFunc::Parms;
 964   fields[argp++] = TypeInt::INT;        // crc
 965   fields[argp++] = TypePtr::NOTNULL;    // src
 966   fields[argp++] = TypeInt::INT;        // len
 967   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 968   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 969 
 970   // result type needed
 971   fields = TypeTuple::fields(1);
 972   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 973   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 974   return TypeFunc::make(domain, range);
 975 }
 976 
 977 /**
 978  * int updateBytesCRC32C(int crc, byte* buf, int len, int* table)
 979  */
 980 const TypeFunc* OptoRuntime::updateBytesCRC32C_Type() {
 981   // create input type (domain)
 982   int num_args      = 4;
 983   int argcnt = num_args;
 984   const Type** fields = TypeTuple::fields(argcnt);
 985   int argp = TypeFunc::Parms;
 986   fields[argp++] = TypeInt::INT;        // crc
 987   fields[argp++] = TypePtr::NOTNULL;    // buf
 988   fields[argp++] = TypeInt::INT;        // len
 989   fields[argp++] = TypePtr::NOTNULL;    // table
 990   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 991   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 992 
 993   // result type needed
 994   fields = TypeTuple::fields(1);
 995   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 996   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 997   return TypeFunc::make(domain, range);
 998 }
 999 
1000 /**
1001 *  int updateBytesAdler32(int adler, bytes* b, int off, int len)
1002 */
1003 const TypeFunc* OptoRuntime::updateBytesAdler32_Type() {
1004   // create input type (domain)
1005   int num_args      = 3;
1006   int argcnt = num_args;
1007   const Type** fields = TypeTuple::fields(argcnt);
1008   int argp = TypeFunc::Parms;
1009   fields[argp++] = TypeInt::INT;        // crc
1010   fields[argp++] = TypePtr::NOTNULL;    // src + offset
1011   fields[argp++] = TypeInt::INT;        // len
1012   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1013   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1014 
1015   // result type needed
1016   fields = TypeTuple::fields(1);
1017   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
1018   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1019   return TypeFunc::make(domain, range);
1020 }
1021 
1022 // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
1023 const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() {
1024   // create input type (domain)
1025   int num_args      = 5;
1026   int argcnt = num_args;
1027   const Type** fields = TypeTuple::fields(argcnt);
1028   int argp = TypeFunc::Parms;
1029   fields[argp++] = TypePtr::NOTNULL;    // src
1030   fields[argp++] = TypePtr::NOTNULL;    // dest
1031   fields[argp++] = TypePtr::NOTNULL;    // k array
1032   fields[argp++] = TypePtr::NOTNULL;    // r array
1033   fields[argp++] = TypeInt::INT;        // src len
1034   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1035   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1036 
1037   // returning cipher len (int)
1038   fields = TypeTuple::fields(1);
1039   fields[TypeFunc::Parms+0] = TypeInt::INT;
1040   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1041   return TypeFunc::make(domain, range);
1042 }
1043 
1044 // for electronicCodeBook calls of aescrypt encrypt/decrypt, three pointers and a length, returning int
1045 const TypeFunc* OptoRuntime::electronicCodeBook_aescrypt_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++] = TypePtr::NOTNULL;    // src
1052   fields[argp++] = TypePtr::NOTNULL;    // dest
1053   fields[argp++] = TypePtr::NOTNULL;    // k array
1054   fields[argp++] = TypeInt::INT;        // src len
1055   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1056   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1057 
1058   // returning cipher len (int)
1059   fields = TypeTuple::fields(1);
1060   fields[TypeFunc::Parms + 0] = TypeInt::INT;
1061   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1062   return TypeFunc::make(domain, range);
1063 }
1064 
1065 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
1066 const TypeFunc* OptoRuntime::counterMode_aescrypt_Type() {
1067   // create input type (domain)
1068   int num_args = 7;
1069   int argcnt = num_args;
1070   const Type** fields = TypeTuple::fields(argcnt);
1071   int argp = TypeFunc::Parms;
1072   fields[argp++] = TypePtr::NOTNULL; // src
1073   fields[argp++] = TypePtr::NOTNULL; // dest
1074   fields[argp++] = TypePtr::NOTNULL; // k array
1075   fields[argp++] = TypePtr::NOTNULL; // counter array
1076   fields[argp++] = TypeInt::INT; // src len
1077   fields[argp++] = TypePtr::NOTNULL; // saved_encCounter
1078   fields[argp++] = TypePtr::NOTNULL; // saved used addr
1079   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1080   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1081   // returning cipher len (int)
1082   fields = TypeTuple::fields(1);
1083   fields[TypeFunc::Parms + 0] = TypeInt::INT;
1084   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1085   return TypeFunc::make(domain, range);
1086 }
1087 
1088 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
1089 const TypeFunc* OptoRuntime::galoisCounterMode_aescrypt_Type() {
1090   // create input type (domain)
1091   int num_args = 8;
1092   int argcnt = num_args;
1093   const Type** fields = TypeTuple::fields(argcnt);
1094   int argp = TypeFunc::Parms;
1095   fields[argp++] = TypePtr::NOTNULL; // byte[] in + inOfs
1096   fields[argp++] = TypeInt::INT;     // int len
1097   fields[argp++] = TypePtr::NOTNULL; // byte[] ct + ctOfs
1098   fields[argp++] = TypePtr::NOTNULL; // byte[] out + outOfs
1099   fields[argp++] = TypePtr::NOTNULL; // byte[] key from AESCrypt obj
1100   fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj
1101   fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj
1102   fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj
1103 
1104   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1105   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1106   // returning cipher len (int)
1107   fields = TypeTuple::fields(1);
1108   fields[TypeFunc::Parms + 0] = TypeInt::INT;
1109   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1110   return TypeFunc::make(domain, range);
1111 }
1112 
1113 /*
1114  * void implCompress(byte[] buf, int ofs)
1115  */
1116 const TypeFunc* OptoRuntime::digestBase_implCompress_Type(bool is_sha3) {
1117   // create input type (domain)
1118   int num_args = is_sha3 ? 3 : 2;
1119   int argcnt = num_args;
1120   const Type** fields = TypeTuple::fields(argcnt);
1121   int argp = TypeFunc::Parms;
1122   fields[argp++] = TypePtr::NOTNULL; // buf
1123   fields[argp++] = TypePtr::NOTNULL; // state
1124   if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1125   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1126   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1127 
1128   // no result type needed
1129   fields = TypeTuple::fields(1);
1130   fields[TypeFunc::Parms+0] = nullptr; // void
1131   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1132   return TypeFunc::make(domain, range);
1133 }
1134 
1135 /*
1136  * int implCompressMultiBlock(byte[] b, int ofs, int limit)
1137  */
1138 const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type(bool is_sha3) {
1139   // create input type (domain)
1140   int num_args = is_sha3 ? 5 : 4;
1141   int argcnt = num_args;
1142   const Type** fields = TypeTuple::fields(argcnt);
1143   int argp = TypeFunc::Parms;
1144   fields[argp++] = TypePtr::NOTNULL; // buf
1145   fields[argp++] = TypePtr::NOTNULL; // state
1146   if (is_sha3) fields[argp++] = TypeInt::INT; // block_size
1147   fields[argp++] = TypeInt::INT;     // ofs
1148   fields[argp++] = TypeInt::INT;     // limit
1149   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1150   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1151 
1152   // returning ofs (int)
1153   fields = TypeTuple::fields(1);
1154   fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs
1155   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1156   return TypeFunc::make(domain, range);
1157 }
1158 
1159 const TypeFunc* OptoRuntime::multiplyToLen_Type() {
1160   // create input type (domain)
1161   int num_args      = 5;
1162   int argcnt = num_args;
1163   const Type** fields = TypeTuple::fields(argcnt);
1164   int argp = TypeFunc::Parms;
1165   fields[argp++] = TypePtr::NOTNULL;    // x
1166   fields[argp++] = TypeInt::INT;        // xlen
1167   fields[argp++] = TypePtr::NOTNULL;    // y
1168   fields[argp++] = TypeInt::INT;        // ylen
1169   fields[argp++] = TypePtr::NOTNULL;    // z
1170   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1171   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1172 
1173   // no result type needed
1174   fields = TypeTuple::fields(1);
1175   fields[TypeFunc::Parms+0] = nullptr;
1176   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1177   return TypeFunc::make(domain, range);
1178 }
1179 
1180 const TypeFunc* OptoRuntime::squareToLen_Type() {
1181   // create input type (domain)
1182   int num_args      = 4;
1183   int argcnt = num_args;
1184   const Type** fields = TypeTuple::fields(argcnt);
1185   int argp = TypeFunc::Parms;
1186   fields[argp++] = TypePtr::NOTNULL;    // x
1187   fields[argp++] = TypeInt::INT;        // len
1188   fields[argp++] = TypePtr::NOTNULL;    // z
1189   fields[argp++] = TypeInt::INT;        // zlen
1190   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1191   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1192 
1193   // no result type needed
1194   fields = TypeTuple::fields(1);
1195   fields[TypeFunc::Parms+0] = nullptr;
1196   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1197   return TypeFunc::make(domain, range);
1198 }
1199 
1200 // for mulAdd calls, 2 pointers and 3 ints, returning int
1201 const TypeFunc* OptoRuntime::mulAdd_Type() {
1202   // create input type (domain)
1203   int num_args      = 5;
1204   int argcnt = num_args;
1205   const Type** fields = TypeTuple::fields(argcnt);
1206   int argp = TypeFunc::Parms;
1207   fields[argp++] = TypePtr::NOTNULL;    // out
1208   fields[argp++] = TypePtr::NOTNULL;    // in
1209   fields[argp++] = TypeInt::INT;        // offset
1210   fields[argp++] = TypeInt::INT;        // len
1211   fields[argp++] = TypeInt::INT;        // k
1212   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1213   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1214 
1215   // returning carry (int)
1216   fields = TypeTuple::fields(1);
1217   fields[TypeFunc::Parms+0] = TypeInt::INT;
1218   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1219   return TypeFunc::make(domain, range);
1220 }
1221 
1222 const TypeFunc* OptoRuntime::montgomeryMultiply_Type() {
1223   // create input type (domain)
1224   int num_args      = 7;
1225   int argcnt = num_args;
1226   const Type** fields = TypeTuple::fields(argcnt);
1227   int argp = TypeFunc::Parms;
1228   fields[argp++] = TypePtr::NOTNULL;    // a
1229   fields[argp++] = TypePtr::NOTNULL;    // b
1230   fields[argp++] = TypePtr::NOTNULL;    // n
1231   fields[argp++] = TypeInt::INT;        // len
1232   fields[argp++] = TypeLong::LONG;      // inv
1233   fields[argp++] = Type::HALF;
1234   fields[argp++] = TypePtr::NOTNULL;    // result
1235   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1236   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1237 
1238   // result type needed
1239   fields = TypeTuple::fields(1);
1240   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1241 
1242   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1243   return TypeFunc::make(domain, range);
1244 }
1245 
1246 const TypeFunc* OptoRuntime::montgomerySquare_Type() {
1247   // create input type (domain)
1248   int num_args      = 6;
1249   int argcnt = num_args;
1250   const Type** fields = TypeTuple::fields(argcnt);
1251   int argp = TypeFunc::Parms;
1252   fields[argp++] = TypePtr::NOTNULL;    // a
1253   fields[argp++] = TypePtr::NOTNULL;    // n
1254   fields[argp++] = TypeInt::INT;        // len
1255   fields[argp++] = TypeLong::LONG;      // inv
1256   fields[argp++] = Type::HALF;
1257   fields[argp++] = TypePtr::NOTNULL;    // result
1258   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1259   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1260 
1261   // result type needed
1262   fields = TypeTuple::fields(1);
1263   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1264 
1265   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1266   return TypeFunc::make(domain, range);
1267 }
1268 
1269 const TypeFunc * OptoRuntime::bigIntegerShift_Type() {
1270   int argcnt = 5;
1271   const Type** fields = TypeTuple::fields(argcnt);
1272   int argp = TypeFunc::Parms;
1273   fields[argp++] = TypePtr::NOTNULL;    // newArr
1274   fields[argp++] = TypePtr::NOTNULL;    // oldArr
1275   fields[argp++] = TypeInt::INT;        // newIdx
1276   fields[argp++] = TypeInt::INT;        // shiftCount
1277   fields[argp++] = TypeInt::INT;        // numIter
1278   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1279   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1280 
1281   // no result type needed
1282   fields = TypeTuple::fields(1);
1283   fields[TypeFunc::Parms + 0] = nullptr;
1284   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1285   return TypeFunc::make(domain, range);
1286 }
1287 
1288 const TypeFunc* OptoRuntime::vectorizedMismatch_Type() {
1289   // create input type (domain)
1290   int num_args = 4;
1291   int argcnt = num_args;
1292   const Type** fields = TypeTuple::fields(argcnt);
1293   int argp = TypeFunc::Parms;
1294   fields[argp++] = TypePtr::NOTNULL;    // obja
1295   fields[argp++] = TypePtr::NOTNULL;    // objb
1296   fields[argp++] = TypeInt::INT;        // length, number of elements
1297   fields[argp++] = TypeInt::INT;        // log2scale, element size
1298   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1299   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1300 
1301   //return mismatch index (int)
1302   fields = TypeTuple::fields(1);
1303   fields[TypeFunc::Parms + 0] = TypeInt::INT;
1304   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1305   return TypeFunc::make(domain, range);
1306 }
1307 
1308 // GHASH block processing
1309 const TypeFunc* OptoRuntime::ghash_processBlocks_Type() {
1310     int argcnt = 4;
1311 
1312     const Type** fields = TypeTuple::fields(argcnt);
1313     int argp = TypeFunc::Parms;
1314     fields[argp++] = TypePtr::NOTNULL;    // state
1315     fields[argp++] = TypePtr::NOTNULL;    // subkeyH
1316     fields[argp++] = TypePtr::NOTNULL;    // data
1317     fields[argp++] = TypeInt::INT;        // blocks
1318     assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1319     const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1320 
1321     // result type needed
1322     fields = TypeTuple::fields(1);
1323     fields[TypeFunc::Parms+0] = nullptr; // void
1324     const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1325     return TypeFunc::make(domain, range);
1326 }
1327 
1328 // ChaCha20 Block function
1329 const TypeFunc* OptoRuntime::chacha20Block_Type() {
1330     int argcnt = 2;
1331 
1332     const Type** fields = TypeTuple::fields(argcnt);
1333     int argp = TypeFunc::Parms;
1334     fields[argp++] = TypePtr::NOTNULL;      // state
1335     fields[argp++] = TypePtr::NOTNULL;      // result
1336 
1337     assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1338     const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1339 
1340     // result type needed
1341     fields = TypeTuple::fields(1);
1342     fields[TypeFunc::Parms + 0] = TypeInt::INT;     // key stream outlen as int
1343     const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1344     return TypeFunc::make(domain, range);
1345 }
1346 
1347 // Base64 encode function
1348 const TypeFunc* OptoRuntime::base64_encodeBlock_Type() {
1349   int argcnt = 6;
1350 
1351   const Type** fields = TypeTuple::fields(argcnt);
1352   int argp = TypeFunc::Parms;
1353   fields[argp++] = TypePtr::NOTNULL;    // src array
1354   fields[argp++] = TypeInt::INT;        // offset
1355   fields[argp++] = TypeInt::INT;        // length
1356   fields[argp++] = TypePtr::NOTNULL;    // dest array
1357   fields[argp++] = TypeInt::INT;       // dp
1358   fields[argp++] = TypeInt::BOOL;       // isURL
1359   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1360   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1361 
1362   // result type needed
1363   fields = TypeTuple::fields(1);
1364   fields[TypeFunc::Parms + 0] = nullptr; // void
1365   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1366   return TypeFunc::make(domain, range);
1367 }
1368 
1369 // String IndexOf function
1370 const TypeFunc* OptoRuntime::string_IndexOf_Type() {
1371   int argcnt = 4;
1372 
1373   const Type** fields = TypeTuple::fields(argcnt);
1374   int argp = TypeFunc::Parms;
1375   fields[argp++] = TypePtr::NOTNULL;    // haystack array
1376   fields[argp++] = TypeInt::INT;        // haystack length
1377   fields[argp++] = TypePtr::NOTNULL;    // needle array
1378   fields[argp++] = TypeInt::INT;        // needle length
1379   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1380   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1381 
1382   // result type needed
1383   fields = TypeTuple::fields(1);
1384   fields[TypeFunc::Parms + 0] = TypeInt::INT; // Index of needle in haystack
1385   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1386   return TypeFunc::make(domain, range);
1387 }
1388 
1389 // Base64 decode function
1390 const TypeFunc* OptoRuntime::base64_decodeBlock_Type() {
1391   int argcnt = 7;
1392 
1393   const Type** fields = TypeTuple::fields(argcnt);
1394   int argp = TypeFunc::Parms;
1395   fields[argp++] = TypePtr::NOTNULL;    // src array
1396   fields[argp++] = TypeInt::INT;        // src offset
1397   fields[argp++] = TypeInt::INT;        // src length
1398   fields[argp++] = TypePtr::NOTNULL;    // dest array
1399   fields[argp++] = TypeInt::INT;        // dest offset
1400   fields[argp++] = TypeInt::BOOL;       // isURL
1401   fields[argp++] = TypeInt::BOOL;       // isMIME
1402   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1403   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1404 
1405   // result type needed
1406   fields = TypeTuple::fields(1);
1407   fields[TypeFunc::Parms + 0] = TypeInt::INT; // count of bytes written to dst
1408   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1409   return TypeFunc::make(domain, range);
1410 }
1411 
1412 // Poly1305 processMultipleBlocks function
1413 const TypeFunc* OptoRuntime::poly1305_processBlocks_Type() {
1414   int argcnt = 4;
1415 
1416   const Type** fields = TypeTuple::fields(argcnt);
1417   int argp = TypeFunc::Parms;
1418   fields[argp++] = TypePtr::NOTNULL;    // input array
1419   fields[argp++] = TypeInt::INT;        // input length
1420   fields[argp++] = TypePtr::NOTNULL;    // accumulator array
1421   fields[argp++] = TypePtr::NOTNULL;    // r array
1422   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1423   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1424 
1425   // result type needed
1426   fields = TypeTuple::fields(1);
1427   fields[TypeFunc::Parms + 0] = nullptr; // void
1428   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1429   return TypeFunc::make(domain, range);
1430 }
1431 
1432 // MontgomeryIntegerPolynomialP256 multiply function
1433 const TypeFunc* OptoRuntime::intpoly_montgomeryMult_P256_Type() {
1434   int argcnt = 3;
1435 
1436   const Type** fields = TypeTuple::fields(argcnt);
1437   int argp = TypeFunc::Parms;
1438   fields[argp++] = TypePtr::NOTNULL;    // a array
1439   fields[argp++] = TypePtr::NOTNULL;    // b array
1440   fields[argp++] = TypePtr::NOTNULL;    // r(esult) array
1441   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1442   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1443 
1444   // result type needed
1445   fields = TypeTuple::fields(1);
1446   fields[TypeFunc::Parms + 0] = nullptr; // void
1447   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1448   return TypeFunc::make(domain, range);
1449 }
1450 
1451 // IntegerPolynomial constant time assignment function
1452 const TypeFunc* OptoRuntime::intpoly_assign_Type() {
1453   int argcnt = 4;
1454 
1455   const Type** fields = TypeTuple::fields(argcnt);
1456   int argp = TypeFunc::Parms;
1457   fields[argp++] = TypeInt::INT;        // set flag
1458   fields[argp++] = TypePtr::NOTNULL;    // a array (result)
1459   fields[argp++] = TypePtr::NOTNULL;    // b array (if set is set)
1460   fields[argp++] = TypeInt::INT;        // array length
1461   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1462   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1463 
1464   // result type needed
1465   fields = TypeTuple::fields(1);
1466   fields[TypeFunc::Parms + 0] = nullptr; // void
1467   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1468   return TypeFunc::make(domain, range);
1469 }
1470 
1471 //------------- Interpreter state access for on stack replacement
1472 const TypeFunc* OptoRuntime::osr_end_Type() {
1473   // create input type (domain)
1474   const Type **fields = TypeTuple::fields(1);
1475   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
1476   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1477 
1478   // create result type
1479   fields = TypeTuple::fields(1);
1480   // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
1481   fields[TypeFunc::Parms+0] = nullptr; // void
1482   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1483   return TypeFunc::make(domain, range);
1484 }
1485 
1486 //-------------------------------------------------------------------------------------
1487 // register policy
1488 
1489 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
1490   assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1491   switch (register_save_policy[reg]) {
1492     case 'C': return false; //SOC
1493     case 'E': return true ; //SOE
1494     case 'N': return false; //NS
1495     case 'A': return false; //AS
1496   }
1497   ShouldNotReachHere();
1498   return false;
1499 }
1500 
1501 //-----------------------------------------------------------------------
1502 // Exceptions
1503 //
1504 
1505 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1506 
1507 // The method is an entry that is always called by a C++ method not
1508 // directly from compiled code. Compiled code will call the C++ method following.
1509 // We can't allow async exception to be installed during  exception processing.
1510 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* current, nmethod* &nm))
1511   // The frame we rethrow the exception to might not have been processed by the GC yet.
1512   // The stack watermark barrier takes care of detecting that and ensuring the frame
1513   // has updated oops.
1514   StackWatermarkSet::after_unwind(current);
1515 
1516   // Do not confuse exception_oop with pending_exception. The exception_oop
1517   // is only used to pass arguments into the method. Not for general
1518   // exception handling.  DO NOT CHANGE IT to use pending_exception, since
1519   // the runtime stubs checks this on exit.
1520   assert(current->exception_oop() != nullptr, "exception oop is found");
1521   address handler_address = nullptr;
1522 
1523   Handle exception(current, current->exception_oop());
1524   address pc = current->exception_pc();
1525 
1526   // Clear out the exception oop and pc since looking up an
1527   // exception handler can cause class loading, which might throw an
1528   // exception and those fields are expected to be clear during
1529   // normal bytecode execution.
1530   current->clear_exception_oop_and_pc();
1531 
1532   LogTarget(Info, exceptions) lt;
1533   if (lt.is_enabled()) {
1534     ResourceMark rm;
1535     LogStream ls(lt);
1536     trace_exception(&ls, exception(), pc, "");
1537   }
1538 
1539   // for AbortVMOnException flag
1540   Exceptions::debug_check_abort(exception);
1541 
1542 #ifdef ASSERT
1543   if (!(exception->is_a(vmClasses::Throwable_klass()))) {
1544     // should throw an exception here
1545     ShouldNotReachHere();
1546   }
1547 #endif
1548 
1549   // new exception handling: this method is entered only from adapters
1550   // exceptions from compiled java methods are handled in compiled code
1551   // using rethrow node
1552 
1553   nm = CodeCache::find_nmethod(pc);
1554   assert(nm != nullptr, "No NMethod found");
1555   if (nm->is_native_method()) {
1556     fatal("Native method should not have path to exception handling");
1557   } else {
1558     // we are switching to old paradigm: search for exception handler in caller_frame
1559     // instead in exception handler of caller_frame.sender()
1560 
1561     if (JvmtiExport::can_post_on_exceptions()) {
1562       // "Full-speed catching" is not necessary here,
1563       // since we're notifying the VM on every catch.
1564       // Force deoptimization and the rest of the lookup
1565       // will be fine.
1566       deoptimize_caller_frame(current);
1567     }
1568 
1569     // Check the stack guard pages.  If enabled, look for handler in this frame;
1570     // otherwise, forcibly unwind the frame.
1571     //
1572     // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
1573     bool force_unwind = !current->stack_overflow_state()->reguard_stack();
1574     bool deopting = false;
1575     if (nm->is_deopt_pc(pc)) {
1576       deopting = true;
1577       RegisterMap map(current,
1578                       RegisterMap::UpdateMap::skip,
1579                       RegisterMap::ProcessFrames::include,
1580                       RegisterMap::WalkContinuation::skip);
1581       frame deoptee = current->last_frame().sender(&map);
1582       assert(deoptee.is_deoptimized_frame(), "must be deopted");
1583       // Adjust the pc back to the original throwing pc
1584       pc = deoptee.pc();
1585     }
1586 
1587     // If we are forcing an unwind because of stack overflow then deopt is
1588     // irrelevant since we are throwing the frame away anyway.
1589 
1590     if (deopting && !force_unwind) {
1591       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1592     } else {
1593 
1594       handler_address =
1595         force_unwind ? nullptr : nm->handler_for_exception_and_pc(exception, pc);
1596 
1597       if (handler_address == nullptr) {
1598         bool recursive_exception = false;
1599         handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1600         assert (handler_address != nullptr, "must have compiled handler");
1601         // Update the exception cache only when the unwind was not forced
1602         // and there didn't happen another exception during the computation of the
1603         // compiled exception handler. Checking for exception oop equality is not
1604         // sufficient because some exceptions are pre-allocated and reused.
1605         if (!force_unwind && !recursive_exception) {
1606           nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
1607         }
1608       } else {
1609 #ifdef ASSERT
1610         bool recursive_exception = false;
1611         address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1612         vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT,
1613                  p2i(handler_address), p2i(computed_address));
1614 #endif
1615       }
1616     }
1617 
1618     current->set_exception_pc(pc);
1619     current->set_exception_handler_pc(handler_address);
1620 
1621     // Check if the exception PC is a MethodHandle call site.
1622     current->set_is_method_handle_return(nm->is_method_handle_return(pc));
1623   }
1624 
1625   // Restore correct return pc.  Was saved above.
1626   current->set_exception_oop(exception());
1627   return handler_address;
1628 
1629 JRT_END
1630 
1631 // We are entering here from exception_blob
1632 // If there is a compiled exception handler in this method, we will continue there;
1633 // otherwise we will unwind the stack and continue at the caller of top frame method
1634 // Note we enter without the usual JRT wrapper. We will call a helper routine that
1635 // will do the normal VM entry. We do it this way so that we can see if the nmethod
1636 // we looked up the handler for has been deoptimized in the meantime. If it has been
1637 // we must not use the handler and instead return the deopt blob.
1638 address OptoRuntime::handle_exception_C(JavaThread* current) {
1639 //
1640 // We are in Java not VM and in debug mode we have a NoHandleMark
1641 //
1642 #ifndef PRODUCT
1643   SharedRuntime::_find_handler_ctr++;          // find exception handler
1644 #endif
1645   debug_only(NoHandleMark __hm;)
1646   nmethod* nm = nullptr;
1647   address handler_address = nullptr;
1648   {
1649     // Enter the VM
1650 
1651     ResetNoHandleMark rnhm;
1652     handler_address = handle_exception_C_helper(current, nm);
1653   }
1654 
1655   // Back in java: Use no oops, DON'T safepoint
1656 
1657   // Now check to see if the handler we are returning is in a now
1658   // deoptimized frame
1659 
1660   if (nm != nullptr) {
1661     RegisterMap map(current,
1662                     RegisterMap::UpdateMap::skip,
1663                     RegisterMap::ProcessFrames::skip,
1664                     RegisterMap::WalkContinuation::skip);
1665     frame caller = current->last_frame().sender(&map);
1666 #ifdef ASSERT
1667     assert(caller.is_compiled_frame(), "must be");
1668 #endif // ASSERT
1669     if (caller.is_deoptimized_frame()) {
1670       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1671     }
1672   }
1673   return handler_address;
1674 }
1675 
1676 //------------------------------rethrow----------------------------------------
1677 // We get here after compiled code has executed a 'RethrowNode'.  The callee
1678 // is either throwing or rethrowing an exception.  The callee-save registers
1679 // have been restored, synchronized objects have been unlocked and the callee
1680 // stack frame has been removed.  The return address was passed in.
1681 // Exception oop is passed as the 1st argument.  This routine is then called
1682 // from the stub.  On exit, we know where to jump in the caller's code.
1683 // After this C code exits, the stub will pop his frame and end in a jump
1684 // (instead of a return).  We enter the caller's default handler.
1685 //
1686 // This must be JRT_LEAF:
1687 //     - caller will not change its state as we cannot block on exit,
1688 //       therefore raw_exception_handler_for_return_address is all it takes
1689 //       to handle deoptimized blobs
1690 //
1691 // However, there needs to be a safepoint check in the middle!  So compiled
1692 // safepoints are completely watertight.
1693 //
1694 // Thus, it cannot be a leaf since it contains the NoSafepointVerifier.
1695 //
1696 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
1697 //
1698 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
1699   // ret_pc will have been loaded from the stack, so for AArch64 will be signed.
1700   AARCH64_PORT_ONLY(ret_pc = pauth_strip_verifiable(ret_pc));
1701 
1702 #ifndef PRODUCT
1703   SharedRuntime::_rethrow_ctr++;               // count rethrows
1704 #endif
1705   assert (exception != nullptr, "should have thrown a NullPointerException");
1706 #ifdef ASSERT
1707   if (!(exception->is_a(vmClasses::Throwable_klass()))) {
1708     // should throw an exception here
1709     ShouldNotReachHere();
1710   }
1711 #endif
1712 
1713   thread->set_vm_result(exception);
1714   // Frame not compiled (handles deoptimization blob)
1715   return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
1716 }
1717 
1718 
1719 const TypeFunc *OptoRuntime::rethrow_Type() {
1720   // create input type (domain)
1721   const Type **fields = TypeTuple::fields(1);
1722   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1723   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1724 
1725   // create result type (range)
1726   fields = TypeTuple::fields(1);
1727   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1728   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1729 
1730   return TypeFunc::make(domain, range);
1731 }
1732 
1733 
1734 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
1735   // Deoptimize the caller before continuing, as the compiled
1736   // exception handler table may not be valid.
1737   if (!StressCompiledExceptionHandlers && doit) {
1738     deoptimize_caller_frame(thread);
1739   }
1740 }
1741 
1742 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) {
1743   // Called from within the owner thread, so no need for safepoint
1744   RegisterMap reg_map(thread,
1745                       RegisterMap::UpdateMap::include,
1746                       RegisterMap::ProcessFrames::include,
1747                       RegisterMap::WalkContinuation::skip);
1748   frame stub_frame = thread->last_frame();
1749   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1750   frame caller_frame = stub_frame.sender(&reg_map);
1751 
1752   // Deoptimize the caller frame.
1753   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1754 }
1755 
1756 
1757 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
1758   // Called from within the owner thread, so no need for safepoint
1759   RegisterMap reg_map(thread,
1760                       RegisterMap::UpdateMap::include,
1761                       RegisterMap::ProcessFrames::include,
1762                       RegisterMap::WalkContinuation::skip);
1763   frame stub_frame = thread->last_frame();
1764   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1765   frame caller_frame = stub_frame.sender(&reg_map);
1766   return caller_frame.is_deoptimized_frame();
1767 }
1768 
1769 
1770 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1771   // create input type (domain)
1772   const Type **fields = TypeTuple::fields(1);
1773   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // oop;          Receiver
1774   // // The JavaThread* is passed to each routine as the last argument
1775   // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // JavaThread *; Executing thread
1776   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1777 
1778   // create result type (range)
1779   fields = TypeTuple::fields(0);
1780 
1781   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1782 
1783   return TypeFunc::make(domain, range);
1784 }
1785 
1786 #if INCLUDE_JFR
1787 const TypeFunc *OptoRuntime::class_id_load_barrier_Type() {
1788   // create input type (domain)
1789   const Type **fields = TypeTuple::fields(1);
1790   fields[TypeFunc::Parms+0] = TypeInstPtr::KLASS;
1791   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms + 1, fields);
1792 
1793   // create result type (range)
1794   fields = TypeTuple::fields(0);
1795 
1796   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms + 0, fields);
1797 
1798   return TypeFunc::make(domain,range);
1799 }
1800 #endif
1801 
1802 //-----------------------------------------------------------------------------
1803 // Dtrace support.  entry and exit probes have the same signature
1804 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1805   // create input type (domain)
1806   const Type **fields = TypeTuple::fields(2);
1807   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1808   fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM;  // Method*;    Method we are entering
1809   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1810 
1811   // create result type (range)
1812   fields = TypeTuple::fields(0);
1813 
1814   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1815 
1816   return TypeFunc::make(domain, range);
1817 }
1818 
1819 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1820   // create input type (domain)
1821   const Type **fields = TypeTuple::fields(2);
1822   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1823   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;  // oop;    newly allocated object
1824 
1825   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1826 
1827   // create result type (range)
1828   fields = TypeTuple::fields(0);
1829 
1830   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1831 
1832   return TypeFunc::make(domain, range);
1833 }
1834 
1835 
1836 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* current))
1837   assert(oopDesc::is_oop(obj), "must be a valid oop");
1838   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1839   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1840 JRT_END
1841 
1842 //-----------------------------------------------------------------------------
1843 
1844 NamedCounter * volatile OptoRuntime::_named_counters = nullptr;
1845 
1846 //
1847 // dump the collected NamedCounters.
1848 //
1849 void OptoRuntime::print_named_counters() {
1850   int total_lock_count = 0;
1851   int eliminated_lock_count = 0;
1852 
1853   NamedCounter* c = _named_counters;
1854   while (c) {
1855     if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1856       int count = c->count();
1857       if (count > 0) {
1858         bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1859         if (Verbose) {
1860           tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1861         }
1862         total_lock_count += count;
1863         if (eliminated) {
1864           eliminated_lock_count += count;
1865         }
1866       }
1867     }
1868     c = c->next();
1869   }
1870   if (total_lock_count > 0) {
1871     tty->print_cr("dynamic locks: %d", total_lock_count);
1872     if (eliminated_lock_count) {
1873       tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1874                     (int)(eliminated_lock_count * 100.0 / total_lock_count));
1875     }
1876   }
1877 }
1878 
1879 //
1880 //  Allocate a new NamedCounter.  The JVMState is used to generate the
1881 //  name which consists of method@line for the inlining tree.
1882 //
1883 
1884 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1885   int max_depth = youngest_jvms->depth();
1886 
1887   // Visit scopes from youngest to oldest.
1888   bool first = true;
1889   stringStream st;
1890   for (int depth = max_depth; depth >= 1; depth--) {
1891     JVMState* jvms = youngest_jvms->of_depth(depth);
1892     ciMethod* m = jvms->has_method() ? jvms->method() : nullptr;
1893     if (!first) {
1894       st.print(" ");
1895     } else {
1896       first = false;
1897     }
1898     int bci = jvms->bci();
1899     if (bci < 0) bci = 0;
1900     if (m != nullptr) {
1901       st.print("%s.%s", m->holder()->name()->as_utf8(), m->name()->as_utf8());
1902     } else {
1903       st.print("no method");
1904     }
1905     st.print("@%d", bci);
1906     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1907   }
1908   NamedCounter* c = new NamedCounter(st.freeze(), tag);
1909 
1910   // atomically add the new counter to the head of the list.  We only
1911   // add counters so this is safe.
1912   NamedCounter* head;
1913   do {
1914     c->set_next(nullptr);
1915     head = _named_counters;
1916     c->set_next(head);
1917   } while (Atomic::cmpxchg(&_named_counters, head, c) != head);
1918   return c;
1919 }
1920 
1921 int trace_exception_counter = 0;
1922 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1923   trace_exception_counter++;
1924   stringStream tempst;
1925 
1926   tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1927   exception_oop->print_value_on(&tempst);
1928   tempst.print(" in ");
1929   CodeBlob* blob = CodeCache::find_blob(exception_pc);
1930   if (blob->is_nmethod()) {
1931     blob->as_nmethod()->method()->print_value_on(&tempst);
1932   } else if (blob->is_runtime_stub()) {
1933     tempst.print("<runtime-stub>");
1934   } else {
1935     tempst.print("<unknown>");
1936   }
1937   tempst.print(" at " INTPTR_FORMAT,  p2i(exception_pc));
1938   tempst.print("]");
1939 
1940   st->print_raw_cr(tempst.freeze());
1941 }
1942 
1943 const TypeFunc *OptoRuntime::store_inline_type_fields_Type() {
1944   // create input type (domain)
1945   uint total = SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
1946   const Type **fields = TypeTuple::fields(total);
1947   // We don't know the number of returned values and their
1948   // types. Assume all registers available to the return convention
1949   // are used.
1950   fields[TypeFunc::Parms] = TypePtr::BOTTOM;
1951   uint i = 1;
1952   for (; i < SharedRuntime::java_return_convention_max_int; i++) {
1953     fields[TypeFunc::Parms+i] = TypeInt::INT;
1954   }
1955   for (; i < total; i+=2) {
1956     fields[TypeFunc::Parms+i] = Type::DOUBLE;
1957     fields[TypeFunc::Parms+i+1] = Type::HALF;
1958   }
1959   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
1960 
1961   // create result type (range)
1962   fields = TypeTuple::fields(1);
1963   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
1964 
1965   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
1966 
1967   return TypeFunc::make(domain, range);
1968 }
1969 
1970 const TypeFunc *OptoRuntime::pack_inline_type_Type() {
1971   // create input type (domain)
1972   uint total = 1 + SharedRuntime::java_return_convention_max_int + SharedRuntime::java_return_convention_max_float*2;
1973   const Type **fields = TypeTuple::fields(total);
1974   // We don't know the number of returned values and their
1975   // types. Assume all registers available to the return convention
1976   // are used.
1977   fields[TypeFunc::Parms] = TypeRawPtr::BOTTOM;
1978   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;
1979   uint i = 2;
1980   for (; i < SharedRuntime::java_return_convention_max_int+1; i++) {
1981     fields[TypeFunc::Parms+i] = TypeInt::INT;
1982   }
1983   for (; i < total; i+=2) {
1984     fields[TypeFunc::Parms+i] = Type::DOUBLE;
1985     fields[TypeFunc::Parms+i+1] = Type::HALF;
1986   }
1987   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + total, fields);
1988 
1989   // create result type (range)
1990   fields = TypeTuple::fields(1);
1991   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
1992 
1993   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1,fields);
1994 
1995   return TypeFunc::make(domain, range);
1996 }
1997 
1998 JRT_BLOCK_ENTRY(void, OptoRuntime::load_unknown_inline(flatArrayOopDesc* array, int index, JavaThread* current))
1999   JRT_BLOCK;
2000   flatArrayHandle vah(current, array);
2001   oop buffer = flatArrayOopDesc::value_alloc_copy_from_index(vah, index, THREAD);
2002   deoptimize_caller_frame(current, HAS_PENDING_EXCEPTION);
2003   current->set_vm_result(buffer);
2004   JRT_BLOCK_END;
2005 JRT_END
2006 
2007 const TypeFunc* OptoRuntime::load_unknown_inline_type() {
2008   // create input type (domain)
2009   const Type** fields = TypeTuple::fields(2);
2010   fields[TypeFunc::Parms] = TypeOopPtr::NOTNULL;
2011   fields[TypeFunc::Parms+1] = TypeInt::POS;
2012 
2013   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+2, fields);
2014 
2015   // create result type (range)
2016   fields = TypeTuple::fields(1);
2017   fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2018 
2019   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
2020 
2021   return TypeFunc::make(domain, range);
2022 }
2023 
2024 JRT_LEAF(void, OptoRuntime::store_unknown_inline(instanceOopDesc* buffer, flatArrayOopDesc* array, int index))
2025 {
2026   assert(buffer != nullptr, "can't store null into flat array");
2027   array->value_copy_to_index(buffer, index);
2028 }
2029 JRT_END
2030 
2031 const TypeFunc* OptoRuntime::store_unknown_inline_type() {
2032   // create input type (domain)
2033   const Type** fields = TypeTuple::fields(3);
2034   fields[TypeFunc::Parms] = TypeInstPtr::NOTNULL;
2035   fields[TypeFunc::Parms+1] = TypeOopPtr::NOTNULL;
2036   fields[TypeFunc::Parms+2] = TypeInt::POS;
2037 
2038   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+3, fields);
2039 
2040   // create result type (range)
2041   fields = TypeTuple::fields(0);
2042   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
2043 
2044   return TypeFunc::make(domain, range);
2045 }