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