rev 49674 : 8198285: More consistent Access API for arraycopy

   1 /*
   2  * Copyright (c) 1998, 2018, 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/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "code/compiledMethod.inline.hpp"
  30 #include "code/compiledIC.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "code/nmethod.hpp"
  33 #include "code/pcDesc.hpp"
  34 #include "code/scopeDesc.hpp"
  35 #include "code/vtableStubs.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "compiler/oopMap.hpp"
  38 #include "gc/g1/heapRegion.hpp"
  39 #include "gc/shared/barrierSet.hpp"
  40 #include "gc/shared/collectedHeap.hpp"
  41 #include "gc/shared/gcLocker.hpp"
  42 #include "interpreter/bytecode.hpp"
  43 #include "interpreter/interpreter.hpp"
  44 #include "interpreter/linkResolver.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/oopFactory.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "oops/objArrayKlass.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/typeArrayOop.inline.hpp"
  52 #include "opto/ad.hpp"
  53 #include "opto/addnode.hpp"
  54 #include "opto/callnode.hpp"
  55 #include "opto/cfgnode.hpp"
  56 #include "opto/graphKit.hpp"
  57 #include "opto/machnode.hpp"
  58 #include "opto/matcher.hpp"
  59 #include "opto/memnode.hpp"
  60 #include "opto/mulnode.hpp"
  61 #include "opto/runtime.hpp"
  62 #include "opto/subnode.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/frame.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/sharedRuntime.hpp"
  69 #include "runtime/signature.hpp"
  70 #include "runtime/threadCritical.hpp"
  71 #include "runtime/vframe.hpp"
  72 #include "runtime/vframeArray.hpp"
  73 #include "runtime/vframe_hp.hpp"
  74 #include "utilities/copy.hpp"
  75 #include "utilities/preserveException.hpp"
  76 
  77 
  78 // For debugging purposes:
  79 //  To force FullGCALot inside a runtime function, add the following two lines
  80 //
  81 //  Universe::release_fullgc_alot_dummy();
  82 //  MarkSweep::invoke(0, "Debugging");
  83 //
  84 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
  85 
  86 
  87 
  88 
  89 // Compiled code entry points
  90 address OptoRuntime::_new_instance_Java                           = NULL;
  91 address OptoRuntime::_new_array_Java                              = NULL;
  92 address OptoRuntime::_new_array_nozero_Java                       = NULL;
  93 address OptoRuntime::_multianewarray2_Java                        = NULL;
  94 address OptoRuntime::_multianewarray3_Java                        = NULL;
  95 address OptoRuntime::_multianewarray4_Java                        = NULL;
  96 address OptoRuntime::_multianewarray5_Java                        = NULL;
  97 address OptoRuntime::_multianewarrayN_Java                        = NULL;
  98 address OptoRuntime::_g1_wb_pre_Java                              = NULL;
  99 address OptoRuntime::_g1_wb_post_Java                             = NULL;
 100 address OptoRuntime::_vtable_must_compile_Java                    = NULL;
 101 address OptoRuntime::_complete_monitor_locking_Java               = NULL;
 102 address OptoRuntime::_monitor_notify_Java                         = NULL;
 103 address OptoRuntime::_monitor_notifyAll_Java                      = NULL;
 104 address OptoRuntime::_rethrow_Java                                = NULL;
 105 
 106 address OptoRuntime::_slow_arraycopy_Java                         = NULL;
 107 address OptoRuntime::_register_finalizer_Java                     = NULL;
 108 
 109 ExceptionBlob* OptoRuntime::_exception_blob;
 110 
 111 // This should be called in an assertion at the start of OptoRuntime routines
 112 // which are entered from compiled code (all of them)
 113 #ifdef ASSERT
 114 static bool check_compiled_frame(JavaThread* thread) {
 115   assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
 116   RegisterMap map(thread, false);
 117   frame caller = thread->last_frame().sender(&map);
 118   assert(caller.is_compiled_frame(), "not being called from compiled like code");
 119   return true;
 120 }
 121 #endif // ASSERT
 122 
 123 
 124 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
 125   var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc); \
 126   if (var == NULL) { return false; }
 127 
 128 bool OptoRuntime::generate(ciEnv* env) {
 129 
 130   generate_exception_blob();
 131 
 132   // Note: tls: Means fetching the return oop out of the thread-local storage
 133   //
 134   //   variable/name                       type-function-gen              , runtime method                  ,fncy_jp, tls,save_args,retpc
 135   // -------------------------------------------------------------------------------------------------------------------------------
 136   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true , false, false);
 137   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true , false, false);
 138   gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true , false, false);
 139   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true , false, false);
 140   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true , false, false);
 141   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true , false, false);
 142   gen(env, _multianewarray5_Java           , multianewarray5_Type         , multianewarray5_C               ,    0 , true , false, false);
 143   gen(env, _multianewarrayN_Java           , multianewarrayN_Type         , multianewarrayN_C               ,    0 , true , false, false);
 144   gen(env, _g1_wb_pre_Java                 , g1_wb_pre_Type               , SharedRuntime::g1_wb_pre        ,    0 , false, false, false);
 145   gen(env, _g1_wb_post_Java                , g1_wb_post_Type              , SharedRuntime::g1_wb_post       ,    0 , false, false, false);
 146   gen(env, _complete_monitor_locking_Java  , complete_monitor_enter_Type  , SharedRuntime::complete_monitor_locking_C, 0, false, false, false);
 147   gen(env, _monitor_notify_Java            , monitor_notify_Type          , monitor_notify_C                ,    0 , false, false, false);
 148   gen(env, _monitor_notifyAll_Java         , monitor_notify_Type          , monitor_notifyAll_C             ,    0 , false, false, false);
 149   gen(env, _rethrow_Java                   , rethrow_Type                 , rethrow_C                       ,    2 , true , false, true );
 150 
 151   gen(env, _slow_arraycopy_Java            , slow_arraycopy_Type          , SharedRuntime::slow_arraycopy_C ,    0 , false, false, false);
 152   gen(env, _register_finalizer_Java        , register_finalizer_Type      , register_finalizer              ,    0 , false, false, false);
 153 
 154   return true;
 155 }
 156 
 157 #undef gen
 158 
 159 
 160 // Helper method to do generation of RunTimeStub's
 161 address OptoRuntime::generate_stub( ciEnv* env,
 162                                     TypeFunc_generator gen, address C_function,
 163                                     const char *name, int is_fancy_jump,
 164                                     bool pass_tls,
 165                                     bool save_argument_registers,
 166                                     bool return_pc) {
 167 
 168   // Matching the default directive, we currently have no method to match.
 169   DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
 170   ResourceMark rm;
 171   Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc, directive);
 172   DirectivesStack::release(directive);
 173   return  C.stub_entry_point();
 174 }
 175 
 176 const char* OptoRuntime::stub_name(address entry) {
 177 #ifndef PRODUCT
 178   CodeBlob* cb = CodeCache::find_blob(entry);
 179   RuntimeStub* rs =(RuntimeStub *)cb;
 180   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
 181   return rs->name();
 182 #else
 183   // Fast implementation for product mode (maybe it should be inlined too)
 184   return "runtime stub";
 185 #endif
 186 }
 187 
 188 
 189 //=============================================================================
 190 // Opto compiler runtime routines
 191 //=============================================================================
 192 
 193 
 194 //=============================allocation======================================
 195 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 196 // and try allocation again.
 197 
 198 // object allocation
 199 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))
 200   JRT_BLOCK;
 201 #ifndef PRODUCT
 202   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 203 #endif
 204   assert(check_compiled_frame(thread), "incorrect caller");
 205 
 206   // These checks are cheap to make and support reflective allocation.
 207   int lh = klass->layout_helper();
 208   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 209     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 210     klass->check_valid_for_instantiation(false, THREAD);
 211     if (!HAS_PENDING_EXCEPTION) {
 212       InstanceKlass::cast(klass)->initialize(THREAD);
 213     }
 214   }
 215 
 216   if (!HAS_PENDING_EXCEPTION) {
 217     // Scavenge and allocate an instance.
 218     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 219     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 220     thread->set_vm_result(result);
 221 
 222     // Pass oops back through thread local storage.  Our apparent type to Java
 223     // is that we return an oop, but we can block on exit from this routine and
 224     // a GC can trash the oop in C's return register.  The generated stub will
 225     // fetch the oop from TLS after any possible GC.
 226   }
 227 
 228   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 229   JRT_BLOCK_END;
 230 
 231   // inform GC that we won't do card marks for initializing writes.
 232   SharedRuntime::on_slowpath_allocation_exit(thread);
 233 JRT_END
 234 
 235 
 236 // array allocation
 237 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))
 238   JRT_BLOCK;
 239 #ifndef PRODUCT
 240   SharedRuntime::_new_array_ctr++;            // new array requires GC
 241 #endif
 242   assert(check_compiled_frame(thread), "incorrect caller");
 243 
 244   // Scavenge and allocate an instance.
 245   oop result;
 246 
 247   if (array_type->is_typeArray_klass()) {
 248     // The oopFactory likes to work with the element type.
 249     // (We could bypass the oopFactory, since it doesn't add much value.)
 250     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 251     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 252   } else {
 253     // Although the oopFactory likes to work with the elem_type,
 254     // the compiler prefers the array_type, since it must already have
 255     // that latter value in hand for the fast path.
 256     Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive
 257     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
 258     result = oopFactory::new_objArray(elem_type, len, THREAD);
 259   }
 260 
 261   // Pass oops back through thread local storage.  Our apparent type to Java
 262   // is that we return an oop, but we can block on exit from this routine and
 263   // a GC can trash the oop in C's return register.  The generated stub will
 264   // fetch the oop from TLS after any possible GC.
 265   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 266   thread->set_vm_result(result);
 267   JRT_BLOCK_END;
 268 
 269   // inform GC that we won't do card marks for initializing writes.
 270   SharedRuntime::on_slowpath_allocation_exit(thread);
 271 JRT_END
 272 
 273 // array allocation without zeroing
 274 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))
 275   JRT_BLOCK;
 276 #ifndef PRODUCT
 277   SharedRuntime::_new_array_ctr++;            // new array requires GC
 278 #endif
 279   assert(check_compiled_frame(thread), "incorrect caller");
 280 
 281   // Scavenge and allocate an instance.
 282   oop result;
 283 
 284   assert(array_type->is_typeArray_klass(), "should be called only for type array");
 285   // The oopFactory likes to work with the element type.
 286   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 287   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
 288 
 289   // Pass oops back through thread local storage.  Our apparent type to Java
 290   // is that we return an oop, but we can block on exit from this routine and
 291   // a GC can trash the oop in C's return register.  The generated stub will
 292   // fetch the oop from TLS after any possible GC.
 293   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 294   thread->set_vm_result(result);
 295   JRT_BLOCK_END;
 296 
 297 
 298   // inform GC that we won't do card marks for initializing writes.
 299   SharedRuntime::on_slowpath_allocation_exit(thread);
 300 
 301   oop result = thread->vm_result();
 302   if ((len > 0) && (result != NULL) &&
 303       is_deoptimized_caller_frame(thread)) {
 304     // Zero array here if the caller is deoptimized.
 305     int size = ((typeArrayOop)result)->object_size();
 306     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 307     const size_t hs = arrayOopDesc::header_size(elem_type);
 308     // Align to next 8 bytes to avoid trashing arrays's length.
 309     const size_t aligned_hs = align_object_offset(hs);
 310     HeapWord* obj = (HeapWord*)result;
 311     if (aligned_hs > hs) {
 312       Copy::zero_to_words(obj+hs, aligned_hs-hs);
 313     }
 314     // Optimized zeroing.
 315     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
 316   }
 317 
 318 JRT_END
 319 
 320 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
 321 
 322 // multianewarray for 2 dimensions
 323 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread *thread))
 324 #ifndef PRODUCT
 325   SharedRuntime::_multi2_ctr++;                // multianewarray for 1 dimension
 326 #endif
 327   assert(check_compiled_frame(thread), "incorrect caller");
 328   assert(elem_type->is_klass(), "not a class");
 329   jint dims[2];
 330   dims[0] = len1;
 331   dims[1] = len2;
 332   Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
 333   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
 334   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 335   thread->set_vm_result(obj);
 336 JRT_END
 337 
 338 // multianewarray for 3 dimensions
 339 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread *thread))
 340 #ifndef PRODUCT
 341   SharedRuntime::_multi3_ctr++;                // multianewarray for 1 dimension
 342 #endif
 343   assert(check_compiled_frame(thread), "incorrect caller");
 344   assert(elem_type->is_klass(), "not a class");
 345   jint dims[3];
 346   dims[0] = len1;
 347   dims[1] = len2;
 348   dims[2] = len3;
 349   Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
 350   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
 351   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 352   thread->set_vm_result(obj);
 353 JRT_END
 354 
 355 // multianewarray for 4 dimensions
 356 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
 357 #ifndef PRODUCT
 358   SharedRuntime::_multi4_ctr++;                // multianewarray for 1 dimension
 359 #endif
 360   assert(check_compiled_frame(thread), "incorrect caller");
 361   assert(elem_type->is_klass(), "not a class");
 362   jint dims[4];
 363   dims[0] = len1;
 364   dims[1] = len2;
 365   dims[2] = len3;
 366   dims[3] = len4;
 367   Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
 368   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
 369   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 370   thread->set_vm_result(obj);
 371 JRT_END
 372 
 373 // multianewarray for 5 dimensions
 374 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
 375 #ifndef PRODUCT
 376   SharedRuntime::_multi5_ctr++;                // multianewarray for 1 dimension
 377 #endif
 378   assert(check_compiled_frame(thread), "incorrect caller");
 379   assert(elem_type->is_klass(), "not a class");
 380   jint dims[5];
 381   dims[0] = len1;
 382   dims[1] = len2;
 383   dims[2] = len3;
 384   dims[3] = len4;
 385   dims[4] = len5;
 386   Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
 387   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
 388   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 389   thread->set_vm_result(obj);
 390 JRT_END
 391 
 392 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread *thread))
 393   assert(check_compiled_frame(thread), "incorrect caller");
 394   assert(elem_type->is_klass(), "not a class");
 395   assert(oop(dims)->is_typeArray(), "not an array");
 396 
 397   ResourceMark rm;
 398   jint len = dims->length();
 399   assert(len > 0, "Dimensions array should contain data");
 400   jint *j_dims = typeArrayOop(dims)->int_at_addr(0);
 401   jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
 402   Copy::conjoint_jints_atomic(j_dims, c_dims, len);

 403 
 404   Handle holder(THREAD, elem_type->klass_holder()); // keep the klass alive
 405   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
 406   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 407   thread->set_vm_result(obj);
 408 JRT_END
 409 
 410 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread *thread))
 411 
 412   // Very few notify/notifyAll operations find any threads on the waitset, so
 413   // the dominant fast-path is to simply return.
 414   // Relatedly, it's critical that notify/notifyAll be fast in order to
 415   // reduce lock hold times.
 416   if (!SafepointSynchronize::is_synchronizing()) {
 417     if (ObjectSynchronizer::quick_notify(obj, thread, false)) {
 418       return;
 419     }
 420   }
 421 
 422   // This is the case the fast-path above isn't provisioned to handle.
 423   // The fast-path is designed to handle frequently arising cases in an efficient manner.
 424   // (The fast-path is just a degenerate variant of the slow-path).
 425   // Perform the dreaded state transition and pass control into the slow-path.
 426   JRT_BLOCK;
 427   Handle h_obj(THREAD, obj);
 428   ObjectSynchronizer::notify(h_obj, CHECK);
 429   JRT_BLOCK_END;
 430 JRT_END
 431 
 432 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread *thread))
 433 
 434   if (!SafepointSynchronize::is_synchronizing() ) {
 435     if (ObjectSynchronizer::quick_notify(obj, thread, true)) {
 436       return;
 437     }
 438   }
 439 
 440   // This is the case the fast-path above isn't provisioned to handle.
 441   // The fast-path is designed to handle frequently arising cases in an efficient manner.
 442   // (The fast-path is just a degenerate variant of the slow-path).
 443   // Perform the dreaded state transition and pass control into the slow-path.
 444   JRT_BLOCK;
 445   Handle h_obj(THREAD, obj);
 446   ObjectSynchronizer::notifyall(h_obj, CHECK);
 447   JRT_BLOCK_END;
 448 JRT_END
 449 
 450 const TypeFunc *OptoRuntime::new_instance_Type() {
 451   // create input type (domain)
 452   const Type **fields = TypeTuple::fields(1);
 453   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 454   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 455 
 456   // create result type (range)
 457   fields = TypeTuple::fields(1);
 458   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 459 
 460   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 461 
 462   return TypeFunc::make(domain, range);
 463 }
 464 
 465 
 466 const TypeFunc *OptoRuntime::athrow_Type() {
 467   // create input type (domain)
 468   const Type **fields = TypeTuple::fields(1);
 469   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 470   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 471 
 472   // create result type (range)
 473   fields = TypeTuple::fields(0);
 474 
 475   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 476 
 477   return TypeFunc::make(domain, range);
 478 }
 479 
 480 
 481 const TypeFunc *OptoRuntime::new_array_Type() {
 482   // create input type (domain)
 483   const Type **fields = TypeTuple::fields(2);
 484   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 485   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 486   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 487 
 488   // create result type (range)
 489   fields = TypeTuple::fields(1);
 490   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 491 
 492   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 493 
 494   return TypeFunc::make(domain, range);
 495 }
 496 
 497 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
 498   // create input type (domain)
 499   const int nargs = ndim + 1;
 500   const Type **fields = TypeTuple::fields(nargs);
 501   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 502   for( int i = 1; i < nargs; i++ )
 503     fields[TypeFunc::Parms + i] = TypeInt::INT;       // array size
 504   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
 505 
 506   // create result type (range)
 507   fields = TypeTuple::fields(1);
 508   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 509   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 510 
 511   return TypeFunc::make(domain, range);
 512 }
 513 
 514 const TypeFunc *OptoRuntime::multianewarray2_Type() {
 515   return multianewarray_Type(2);
 516 }
 517 
 518 const TypeFunc *OptoRuntime::multianewarray3_Type() {
 519   return multianewarray_Type(3);
 520 }
 521 
 522 const TypeFunc *OptoRuntime::multianewarray4_Type() {
 523   return multianewarray_Type(4);
 524 }
 525 
 526 const TypeFunc *OptoRuntime::multianewarray5_Type() {
 527   return multianewarray_Type(5);
 528 }
 529 
 530 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
 531   // create input type (domain)
 532   const Type **fields = TypeTuple::fields(2);
 533   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 534   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;   // array of dim sizes
 535   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 536 
 537   // create result type (range)
 538   fields = TypeTuple::fields(1);
 539   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 540   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 541 
 542   return TypeFunc::make(domain, range);
 543 }
 544 
 545 const TypeFunc *OptoRuntime::g1_wb_pre_Type() {
 546   const Type **fields = TypeTuple::fields(2);
 547   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
 548   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
 549   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 550 
 551   // create result type (range)
 552   fields = TypeTuple::fields(0);
 553   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 554 
 555   return TypeFunc::make(domain, range);
 556 }
 557 
 558 const TypeFunc *OptoRuntime::g1_wb_post_Type() {
 559 
 560   const Type **fields = TypeTuple::fields(2);
 561   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL;  // Card addr
 562   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // thread
 563   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 564 
 565   // create result type (range)
 566   fields = TypeTuple::fields(0);
 567   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 568 
 569   return TypeFunc::make(domain, range);
 570 }
 571 
 572 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
 573   // create input type (domain)
 574   const Type **fields = TypeTuple::fields(1);
 575   fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
 576   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 577 
 578   // create result type (range)
 579   fields = TypeTuple::fields(0);
 580   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 581 
 582   return TypeFunc::make(domain, range);
 583 }
 584 
 585 //-----------------------------------------------------------------------------
 586 // Monitor Handling
 587 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
 588   // create input type (domain)
 589   const Type **fields = TypeTuple::fields(2);
 590   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 591   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;   // Address of stack location for lock
 592   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
 593 
 594   // create result type (range)
 595   fields = TypeTuple::fields(0);
 596 
 597   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
 598 
 599   return TypeFunc::make(domain,range);
 600 }
 601 
 602 
 603 //-----------------------------------------------------------------------------
 604 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
 605   // create input type (domain)
 606   const Type **fields = TypeTuple::fields(3);
 607   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 608   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;    // Address of stack location for lock - BasicLock
 609   fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM;    // Thread pointer (Self)
 610   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 611 
 612   // create result type (range)
 613   fields = TypeTuple::fields(0);
 614 
 615   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 616 
 617   return TypeFunc::make(domain, range);
 618 }
 619 
 620 const TypeFunc *OptoRuntime::monitor_notify_Type() {
 621   // create input type (domain)
 622   const Type **fields = TypeTuple::fields(1);
 623   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 624   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 625 
 626   // create result type (range)
 627   fields = TypeTuple::fields(0);
 628   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 629   return TypeFunc::make(domain, range);
 630 }
 631 
 632 const TypeFunc* OptoRuntime::flush_windows_Type() {
 633   // create input type (domain)
 634   const Type** fields = TypeTuple::fields(1);
 635   fields[TypeFunc::Parms+0] = NULL; // void
 636   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
 637 
 638   // create result type
 639   fields = TypeTuple::fields(1);
 640   fields[TypeFunc::Parms+0] = NULL; // void
 641   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 642 
 643   return TypeFunc::make(domain, range);
 644 }
 645 
 646 const TypeFunc* OptoRuntime::l2f_Type() {
 647   // create input type (domain)
 648   const Type **fields = TypeTuple::fields(2);
 649   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 650   fields[TypeFunc::Parms+1] = Type::HALF;
 651   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 652 
 653   // create result type (range)
 654   fields = TypeTuple::fields(1);
 655   fields[TypeFunc::Parms+0] = Type::FLOAT;
 656   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 657 
 658   return TypeFunc::make(domain, range);
 659 }
 660 
 661 const TypeFunc* OptoRuntime::modf_Type() {
 662   const Type **fields = TypeTuple::fields(2);
 663   fields[TypeFunc::Parms+0] = Type::FLOAT;
 664   fields[TypeFunc::Parms+1] = Type::FLOAT;
 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 
 671   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 672 
 673   return TypeFunc::make(domain, range);
 674 }
 675 
 676 const TypeFunc *OptoRuntime::Math_D_D_Type() {
 677   // create input type (domain)
 678   const Type **fields = TypeTuple::fields(2);
 679   // Symbol* name of class to be loaded
 680   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 681   fields[TypeFunc::Parms+1] = Type::HALF;
 682   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 683 
 684   // create result type (range)
 685   fields = TypeTuple::fields(2);
 686   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 687   fields[TypeFunc::Parms+1] = Type::HALF;
 688   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 689 
 690   return TypeFunc::make(domain, range);
 691 }
 692 
 693 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
 694   const Type **fields = TypeTuple::fields(4);
 695   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 696   fields[TypeFunc::Parms+1] = Type::HALF;
 697   fields[TypeFunc::Parms+2] = Type::DOUBLE;
 698   fields[TypeFunc::Parms+3] = Type::HALF;
 699   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
 700 
 701   // create result type (range)
 702   fields = TypeTuple::fields(2);
 703   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 704   fields[TypeFunc::Parms+1] = Type::HALF;
 705   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 706 
 707   return TypeFunc::make(domain, range);
 708 }
 709 
 710 //-------------- currentTimeMillis, currentTimeNanos, etc
 711 
 712 const TypeFunc* OptoRuntime::void_long_Type() {
 713   // create input type (domain)
 714   const Type **fields = TypeTuple::fields(0);
 715   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
 716 
 717   // create result type (range)
 718   fields = TypeTuple::fields(2);
 719   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 720   fields[TypeFunc::Parms+1] = Type::HALF;
 721   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 722 
 723   return TypeFunc::make(domain, range);
 724 }
 725 
 726 // arraycopy stub variations:
 727 enum ArrayCopyType {
 728   ac_fast,                      // void(ptr, ptr, size_t)
 729   ac_checkcast,                 //  int(ptr, ptr, size_t, size_t, ptr)
 730   ac_slow,                      // void(ptr, int, ptr, int, int)
 731   ac_generic                    //  int(ptr, int, ptr, int, int)
 732 };
 733 
 734 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
 735   // create input type (domain)
 736   int num_args      = (act == ac_fast ? 3 : 5);
 737   int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
 738   int argcnt = num_args;
 739   LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
 740   const Type** fields = TypeTuple::fields(argcnt);
 741   int argp = TypeFunc::Parms;
 742   fields[argp++] = TypePtr::NOTNULL;    // src
 743   if (num_size_args == 0) {
 744     fields[argp++] = TypeInt::INT;      // src_pos
 745   }
 746   fields[argp++] = TypePtr::NOTNULL;    // dest
 747   if (num_size_args == 0) {
 748     fields[argp++] = TypeInt::INT;      // dest_pos
 749     fields[argp++] = TypeInt::INT;      // length
 750   }
 751   while (num_size_args-- > 0) {
 752     fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 753     LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 754   }
 755   if (act == ac_checkcast) {
 756     fields[argp++] = TypePtr::NOTNULL;  // super_klass
 757   }
 758   assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
 759   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 760 
 761   // create result type if needed
 762   int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
 763   fields = TypeTuple::fields(1);
 764   if (retcnt == 0)
 765     fields[TypeFunc::Parms+0] = NULL; // void
 766   else
 767     fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
 768   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
 769   return TypeFunc::make(domain, range);
 770 }
 771 
 772 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
 773   // This signature is simple:  Two base pointers and a size_t.
 774   return make_arraycopy_Type(ac_fast);
 775 }
 776 
 777 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
 778   // An extension of fast_arraycopy_Type which adds type checking.
 779   return make_arraycopy_Type(ac_checkcast);
 780 }
 781 
 782 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
 783   // This signature is exactly the same as System.arraycopy.
 784   // There are no intptr_t (int/long) arguments.
 785   return make_arraycopy_Type(ac_slow);
 786 }
 787 
 788 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
 789   // This signature is like System.arraycopy, except that it returns status.
 790   return make_arraycopy_Type(ac_generic);
 791 }
 792 
 793 
 794 const TypeFunc* OptoRuntime::array_fill_Type() {
 795   const Type** fields;
 796   int argp = TypeFunc::Parms;
 797   // create input type (domain): pointer, int, size_t
 798   fields = TypeTuple::fields(3 LP64_ONLY( + 1));
 799   fields[argp++] = TypePtr::NOTNULL;
 800   fields[argp++] = TypeInt::INT;
 801   fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 802   LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 803   const TypeTuple *domain = TypeTuple::make(argp, fields);
 804 
 805   // create result type
 806   fields = TypeTuple::fields(1);
 807   fields[TypeFunc::Parms+0] = NULL; // void
 808   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 809 
 810   return TypeFunc::make(domain, range);
 811 }
 812 
 813 // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant)
 814 const TypeFunc* OptoRuntime::aescrypt_block_Type() {
 815   // create input type (domain)
 816   int num_args      = 3;
 817   if (Matcher::pass_original_key_for_aes()) {
 818     num_args = 4;
 819   }
 820   int argcnt = num_args;
 821   const Type** fields = TypeTuple::fields(argcnt);
 822   int argp = TypeFunc::Parms;
 823   fields[argp++] = TypePtr::NOTNULL;    // src
 824   fields[argp++] = TypePtr::NOTNULL;    // dest
 825   fields[argp++] = TypePtr::NOTNULL;    // k array
 826   if (Matcher::pass_original_key_for_aes()) {
 827     fields[argp++] = TypePtr::NOTNULL;    // original k array
 828   }
 829   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 830   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 831 
 832   // no result type needed
 833   fields = TypeTuple::fields(1);
 834   fields[TypeFunc::Parms+0] = NULL; // void
 835   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 836   return TypeFunc::make(domain, range);
 837 }
 838 
 839 /**
 840  * int updateBytesCRC32(int crc, byte* b, int len)
 841  */
 842 const TypeFunc* OptoRuntime::updateBytesCRC32_Type() {
 843   // create input type (domain)
 844   int num_args      = 3;
 845   int argcnt = num_args;
 846   const Type** fields = TypeTuple::fields(argcnt);
 847   int argp = TypeFunc::Parms;
 848   fields[argp++] = TypeInt::INT;        // crc
 849   fields[argp++] = TypePtr::NOTNULL;    // src
 850   fields[argp++] = TypeInt::INT;        // len
 851   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 852   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 853 
 854   // result type needed
 855   fields = TypeTuple::fields(1);
 856   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 857   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 858   return TypeFunc::make(domain, range);
 859 }
 860 
 861 /**
 862  * int updateBytesCRC32C(int crc, byte* buf, int len, int* table)
 863  */
 864 const TypeFunc* OptoRuntime::updateBytesCRC32C_Type() {
 865   // create input type (domain)
 866   int num_args      = 4;
 867   int argcnt = num_args;
 868   const Type** fields = TypeTuple::fields(argcnt);
 869   int argp = TypeFunc::Parms;
 870   fields[argp++] = TypeInt::INT;        // crc
 871   fields[argp++] = TypePtr::NOTNULL;    // buf
 872   fields[argp++] = TypeInt::INT;        // len
 873   fields[argp++] = TypePtr::NOTNULL;    // table
 874   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 875   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 876 
 877   // result type needed
 878   fields = TypeTuple::fields(1);
 879   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 880   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 881   return TypeFunc::make(domain, range);
 882 }
 883 
 884 /**
 885 *  int updateBytesAdler32(int adler, bytes* b, int off, int len)
 886 */
 887 const TypeFunc* OptoRuntime::updateBytesAdler32_Type() {
 888   // create input type (domain)
 889   int num_args      = 3;
 890   int argcnt = num_args;
 891   const Type** fields = TypeTuple::fields(argcnt);
 892   int argp = TypeFunc::Parms;
 893   fields[argp++] = TypeInt::INT;        // crc
 894   fields[argp++] = TypePtr::NOTNULL;    // src + offset
 895   fields[argp++] = TypeInt::INT;        // len
 896   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 897   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 898 
 899   // result type needed
 900   fields = TypeTuple::fields(1);
 901   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 902   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 903   return TypeFunc::make(domain, range);
 904 }
 905 
 906 // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
 907 const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() {
 908   // create input type (domain)
 909   int num_args      = 5;
 910   if (Matcher::pass_original_key_for_aes()) {
 911     num_args = 6;
 912   }
 913   int argcnt = num_args;
 914   const Type** fields = TypeTuple::fields(argcnt);
 915   int argp = TypeFunc::Parms;
 916   fields[argp++] = TypePtr::NOTNULL;    // src
 917   fields[argp++] = TypePtr::NOTNULL;    // dest
 918   fields[argp++] = TypePtr::NOTNULL;    // k array
 919   fields[argp++] = TypePtr::NOTNULL;    // r array
 920   fields[argp++] = TypeInt::INT;        // src len
 921   if (Matcher::pass_original_key_for_aes()) {
 922     fields[argp++] = TypePtr::NOTNULL;    // original k array
 923   }
 924   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 925   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 926 
 927   // returning cipher len (int)
 928   fields = TypeTuple::fields(1);
 929   fields[TypeFunc::Parms+0] = TypeInt::INT;
 930   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 931   return TypeFunc::make(domain, range);
 932 }
 933 
 934 //for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
 935 const TypeFunc* OptoRuntime::counterMode_aescrypt_Type() {
 936   // create input type (domain)
 937   int num_args = 7;
 938   if (Matcher::pass_original_key_for_aes()) {
 939     num_args = 8;
 940   }
 941   int argcnt = num_args;
 942   const Type** fields = TypeTuple::fields(argcnt);
 943   int argp = TypeFunc::Parms;
 944   fields[argp++] = TypePtr::NOTNULL; // src
 945   fields[argp++] = TypePtr::NOTNULL; // dest
 946   fields[argp++] = TypePtr::NOTNULL; // k array
 947   fields[argp++] = TypePtr::NOTNULL; // counter array
 948   fields[argp++] = TypeInt::INT; // src len
 949   fields[argp++] = TypePtr::NOTNULL; // saved_encCounter
 950   fields[argp++] = TypePtr::NOTNULL; // saved used addr
 951   if (Matcher::pass_original_key_for_aes()) {
 952     fields[argp++] = TypePtr::NOTNULL; // original k array
 953   }
 954   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
 955   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
 956   // returning cipher len (int)
 957   fields = TypeTuple::fields(1);
 958   fields[TypeFunc::Parms + 0] = TypeInt::INT;
 959   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
 960   return TypeFunc::make(domain, range);
 961 }
 962 
 963 /*
 964  * void implCompress(byte[] buf, int ofs)
 965  */
 966 const TypeFunc* OptoRuntime::sha_implCompress_Type() {
 967   // create input type (domain)
 968   int num_args = 2;
 969   int argcnt = num_args;
 970   const Type** fields = TypeTuple::fields(argcnt);
 971   int argp = TypeFunc::Parms;
 972   fields[argp++] = TypePtr::NOTNULL; // buf
 973   fields[argp++] = TypePtr::NOTNULL; // state
 974   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 975   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 976 
 977   // no result type needed
 978   fields = TypeTuple::fields(1);
 979   fields[TypeFunc::Parms+0] = NULL; // void
 980   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 981   return TypeFunc::make(domain, range);
 982 }
 983 
 984 /*
 985  * int implCompressMultiBlock(byte[] b, int ofs, int limit)
 986  */
 987 const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type() {
 988   // create input type (domain)
 989   int num_args = 4;
 990   int argcnt = num_args;
 991   const Type** fields = TypeTuple::fields(argcnt);
 992   int argp = TypeFunc::Parms;
 993   fields[argp++] = TypePtr::NOTNULL; // buf
 994   fields[argp++] = TypePtr::NOTNULL; // state
 995   fields[argp++] = TypeInt::INT;     // ofs
 996   fields[argp++] = TypeInt::INT;     // limit
 997   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 998   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 999 
1000   // returning ofs (int)
1001   fields = TypeTuple::fields(1);
1002   fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs
1003   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1004   return TypeFunc::make(domain, range);
1005 }
1006 
1007 const TypeFunc* OptoRuntime::multiplyToLen_Type() {
1008   // create input type (domain)
1009   int num_args      = 6;
1010   int argcnt = num_args;
1011   const Type** fields = TypeTuple::fields(argcnt);
1012   int argp = TypeFunc::Parms;
1013   fields[argp++] = TypePtr::NOTNULL;    // x
1014   fields[argp++] = TypeInt::INT;        // xlen
1015   fields[argp++] = TypePtr::NOTNULL;    // y
1016   fields[argp++] = TypeInt::INT;        // ylen
1017   fields[argp++] = TypePtr::NOTNULL;    // z
1018   fields[argp++] = TypeInt::INT;        // zlen
1019   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1020   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1021 
1022   // no result type needed
1023   fields = TypeTuple::fields(1);
1024   fields[TypeFunc::Parms+0] = NULL;
1025   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1026   return TypeFunc::make(domain, range);
1027 }
1028 
1029 const TypeFunc* OptoRuntime::squareToLen_Type() {
1030   // create input type (domain)
1031   int num_args      = 4;
1032   int argcnt = num_args;
1033   const Type** fields = TypeTuple::fields(argcnt);
1034   int argp = TypeFunc::Parms;
1035   fields[argp++] = TypePtr::NOTNULL;    // x
1036   fields[argp++] = TypeInt::INT;        // len
1037   fields[argp++] = TypePtr::NOTNULL;    // z
1038   fields[argp++] = TypeInt::INT;        // zlen
1039   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1040   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1041 
1042   // no result type needed
1043   fields = TypeTuple::fields(1);
1044   fields[TypeFunc::Parms+0] = NULL;
1045   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1046   return TypeFunc::make(domain, range);
1047 }
1048 
1049 // for mulAdd calls, 2 pointers and 3 ints, returning int
1050 const TypeFunc* OptoRuntime::mulAdd_Type() {
1051   // create input type (domain)
1052   int num_args      = 5;
1053   int argcnt = num_args;
1054   const Type** fields = TypeTuple::fields(argcnt);
1055   int argp = TypeFunc::Parms;
1056   fields[argp++] = TypePtr::NOTNULL;    // out
1057   fields[argp++] = TypePtr::NOTNULL;    // in
1058   fields[argp++] = TypeInt::INT;        // offset
1059   fields[argp++] = TypeInt::INT;        // len
1060   fields[argp++] = TypeInt::INT;        // k
1061   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1062   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1063 
1064   // returning carry (int)
1065   fields = TypeTuple::fields(1);
1066   fields[TypeFunc::Parms+0] = TypeInt::INT;
1067   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1068   return TypeFunc::make(domain, range);
1069 }
1070 
1071 const TypeFunc* OptoRuntime::montgomeryMultiply_Type() {
1072   // create input type (domain)
1073   int num_args      = 7;
1074   int argcnt = num_args;
1075   const Type** fields = TypeTuple::fields(argcnt);
1076   int argp = TypeFunc::Parms;
1077   fields[argp++] = TypePtr::NOTNULL;    // a
1078   fields[argp++] = TypePtr::NOTNULL;    // b
1079   fields[argp++] = TypePtr::NOTNULL;    // n
1080   fields[argp++] = TypeInt::INT;        // len
1081   fields[argp++] = TypeLong::LONG;      // inv
1082   fields[argp++] = Type::HALF;
1083   fields[argp++] = TypePtr::NOTNULL;    // result
1084   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1085   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1086 
1087   // result type needed
1088   fields = TypeTuple::fields(1);
1089   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1090 
1091   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1092   return TypeFunc::make(domain, range);
1093 }
1094 
1095 const TypeFunc* OptoRuntime::montgomerySquare_Type() {
1096   // create input type (domain)
1097   int num_args      = 6;
1098   int argcnt = num_args;
1099   const Type** fields = TypeTuple::fields(argcnt);
1100   int argp = TypeFunc::Parms;
1101   fields[argp++] = TypePtr::NOTNULL;    // a
1102   fields[argp++] = TypePtr::NOTNULL;    // n
1103   fields[argp++] = TypeInt::INT;        // len
1104   fields[argp++] = TypeLong::LONG;      // inv
1105   fields[argp++] = Type::HALF;
1106   fields[argp++] = TypePtr::NOTNULL;    // result
1107   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1108   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1109 
1110   // result type needed
1111   fields = TypeTuple::fields(1);
1112   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1113 
1114   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1115   return TypeFunc::make(domain, range);
1116 }
1117 
1118 const TypeFunc* OptoRuntime::vectorizedMismatch_Type() {
1119   // create input type (domain)
1120   int num_args = 4;
1121   int argcnt = num_args;
1122   const Type** fields = TypeTuple::fields(argcnt);
1123   int argp = TypeFunc::Parms;
1124   fields[argp++] = TypePtr::NOTNULL;    // obja
1125   fields[argp++] = TypePtr::NOTNULL;    // objb
1126   fields[argp++] = TypeInt::INT;        // length, number of elements
1127   fields[argp++] = TypeInt::INT;        // log2scale, element size
1128   assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
1129   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
1130 
1131   //return mismatch index (int)
1132   fields = TypeTuple::fields(1);
1133   fields[TypeFunc::Parms + 0] = TypeInt::INT;
1134   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 1, fields);
1135   return TypeFunc::make(domain, range);
1136 }
1137 
1138 // GHASH block processing
1139 const TypeFunc* OptoRuntime::ghash_processBlocks_Type() {
1140     int argcnt = 4;
1141 
1142     const Type** fields = TypeTuple::fields(argcnt);
1143     int argp = TypeFunc::Parms;
1144     fields[argp++] = TypePtr::NOTNULL;    // state
1145     fields[argp++] = TypePtr::NOTNULL;    // subkeyH
1146     fields[argp++] = TypePtr::NOTNULL;    // data
1147     fields[argp++] = TypeInt::INT;        // blocks
1148     assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1149     const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1150 
1151     // result type needed
1152     fields = TypeTuple::fields(1);
1153     fields[TypeFunc::Parms+0] = NULL; // void
1154     const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1155     return TypeFunc::make(domain, range);
1156 }
1157 
1158 //------------- Interpreter state access for on stack replacement
1159 const TypeFunc* OptoRuntime::osr_end_Type() {
1160   // create input type (domain)
1161   const Type **fields = TypeTuple::fields(1);
1162   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
1163   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1164 
1165   // create result type
1166   fields = TypeTuple::fields(1);
1167   // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
1168   fields[TypeFunc::Parms+0] = NULL; // void
1169   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1170   return TypeFunc::make(domain, range);
1171 }
1172 
1173 //-------------- methodData update helpers
1174 
1175 const TypeFunc* OptoRuntime::profile_receiver_type_Type() {
1176   // create input type (domain)
1177   const Type **fields = TypeTuple::fields(2);
1178   fields[TypeFunc::Parms+0] = TypeAryPtr::NOTNULL;    // methodData pointer
1179   fields[TypeFunc::Parms+1] = TypeInstPtr::BOTTOM;    // receiver oop
1180   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
1181 
1182   // create result type
1183   fields = TypeTuple::fields(1);
1184   fields[TypeFunc::Parms+0] = NULL; // void
1185   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1186   return TypeFunc::make(domain,range);
1187 }
1188 
1189 JRT_LEAF(void, OptoRuntime::profile_receiver_type_C(DataLayout* data, oopDesc* receiver))
1190   if (receiver == NULL) return;
1191   Klass* receiver_klass = receiver->klass();
1192 
1193   intptr_t* mdp = ((intptr_t*)(data)) + DataLayout::header_size_in_cells();
1194   int empty_row = -1;           // free row, if any is encountered
1195 
1196   // ReceiverTypeData* vc = new ReceiverTypeData(mdp);
1197   for (uint row = 0; row < ReceiverTypeData::row_limit(); row++) {
1198     // if (vc->receiver(row) == receiver_klass)
1199     int receiver_off = ReceiverTypeData::receiver_cell_index(row);
1200     intptr_t row_recv = *(mdp + receiver_off);
1201     if (row_recv == (intptr_t) receiver_klass) {
1202       // vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
1203       int count_off = ReceiverTypeData::receiver_count_cell_index(row);
1204       *(mdp + count_off) += DataLayout::counter_increment;
1205       return;
1206     } else if (row_recv == 0) {
1207       // else if (vc->receiver(row) == NULL)
1208       empty_row = (int) row;
1209     }
1210   }
1211 
1212   if (empty_row != -1) {
1213     int receiver_off = ReceiverTypeData::receiver_cell_index(empty_row);
1214     // vc->set_receiver(empty_row, receiver_klass);
1215     *(mdp + receiver_off) = (intptr_t) receiver_klass;
1216     // vc->set_receiver_count(empty_row, DataLayout::counter_increment);
1217     int count_off = ReceiverTypeData::receiver_count_cell_index(empty_row);
1218     *(mdp + count_off) = DataLayout::counter_increment;
1219   } else {
1220     // Receiver did not match any saved receiver and there is no empty row for it.
1221     // Increment total counter to indicate polymorphic case.
1222     intptr_t* count_p = (intptr_t*)(((uint8_t*)(data)) + in_bytes(CounterData::count_offset()));
1223     *count_p += DataLayout::counter_increment;
1224   }
1225 JRT_END
1226 
1227 //-------------------------------------------------------------------------------------
1228 // register policy
1229 
1230 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
1231   assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1232   switch (register_save_policy[reg]) {
1233     case 'C': return false; //SOC
1234     case 'E': return true ; //SOE
1235     case 'N': return false; //NS
1236     case 'A': return false; //AS
1237   }
1238   ShouldNotReachHere();
1239   return false;
1240 }
1241 
1242 //-----------------------------------------------------------------------
1243 // Exceptions
1244 //
1245 
1246 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1247 
1248 // The method is an entry that is always called by a C++ method not
1249 // directly from compiled code. Compiled code will call the C++ method following.
1250 // We can't allow async exception to be installed during  exception processing.
1251 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
1252 
1253   // Do not confuse exception_oop with pending_exception. The exception_oop
1254   // is only used to pass arguments into the method. Not for general
1255   // exception handling.  DO NOT CHANGE IT to use pending_exception, since
1256   // the runtime stubs checks this on exit.
1257   assert(thread->exception_oop() != NULL, "exception oop is found");
1258   address handler_address = NULL;
1259 
1260   Handle exception(thread, thread->exception_oop());
1261   address pc = thread->exception_pc();
1262 
1263   // Clear out the exception oop and pc since looking up an
1264   // exception handler can cause class loading, which might throw an
1265   // exception and those fields are expected to be clear during
1266   // normal bytecode execution.
1267   thread->clear_exception_oop_and_pc();
1268 
1269   LogTarget(Info, exceptions) lt;
1270   if (lt.is_enabled()) {
1271     ResourceMark rm;
1272     LogStream ls(lt);
1273     trace_exception(&ls, exception(), pc, "");
1274   }
1275 
1276   // for AbortVMOnException flag
1277   Exceptions::debug_check_abort(exception);
1278 
1279 #ifdef ASSERT
1280   if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
1281     // should throw an exception here
1282     ShouldNotReachHere();
1283   }
1284 #endif
1285 
1286   // new exception handling: this method is entered only from adapters
1287   // exceptions from compiled java methods are handled in compiled code
1288   // using rethrow node
1289 
1290   nm = CodeCache::find_nmethod(pc);
1291   assert(nm != NULL, "No NMethod found");
1292   if (nm->is_native_method()) {
1293     fatal("Native method should not have path to exception handling");
1294   } else {
1295     // we are switching to old paradigm: search for exception handler in caller_frame
1296     // instead in exception handler of caller_frame.sender()
1297 
1298     if (JvmtiExport::can_post_on_exceptions()) {
1299       // "Full-speed catching" is not necessary here,
1300       // since we're notifying the VM on every catch.
1301       // Force deoptimization and the rest of the lookup
1302       // will be fine.
1303       deoptimize_caller_frame(thread);
1304     }
1305 
1306     // Check the stack guard pages.  If enabled, look for handler in this frame;
1307     // otherwise, forcibly unwind the frame.
1308     //
1309     // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
1310     bool force_unwind = !thread->reguard_stack();
1311     bool deopting = false;
1312     if (nm->is_deopt_pc(pc)) {
1313       deopting = true;
1314       RegisterMap map(thread, false);
1315       frame deoptee = thread->last_frame().sender(&map);
1316       assert(deoptee.is_deoptimized_frame(), "must be deopted");
1317       // Adjust the pc back to the original throwing pc
1318       pc = deoptee.pc();
1319     }
1320 
1321     // If we are forcing an unwind because of stack overflow then deopt is
1322     // irrelevant since we are throwing the frame away anyway.
1323 
1324     if (deopting && !force_unwind) {
1325       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1326     } else {
1327 
1328       handler_address =
1329         force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
1330 
1331       if (handler_address == NULL) {
1332         bool recursive_exception = false;
1333         handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1334         assert (handler_address != NULL, "must have compiled handler");
1335         // Update the exception cache only when the unwind was not forced
1336         // and there didn't happen another exception during the computation of the
1337         // compiled exception handler. Checking for exception oop equality is not
1338         // sufficient because some exceptions are pre-allocated and reused.
1339         if (!force_unwind && !recursive_exception) {
1340           nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
1341         }
1342       } else {
1343 #ifdef ASSERT
1344         bool recursive_exception = false;
1345         address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception);
1346         vmassert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency: " PTR_FORMAT " != " PTR_FORMAT,
1347                  p2i(handler_address), p2i(computed_address));
1348 #endif
1349       }
1350     }
1351 
1352     thread->set_exception_pc(pc);
1353     thread->set_exception_handler_pc(handler_address);
1354 
1355     // Check if the exception PC is a MethodHandle call site.
1356     thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
1357   }
1358 
1359   // Restore correct return pc.  Was saved above.
1360   thread->set_exception_oop(exception());
1361   return handler_address;
1362 
1363 JRT_END
1364 
1365 // We are entering here from exception_blob
1366 // If there is a compiled exception handler in this method, we will continue there;
1367 // otherwise we will unwind the stack and continue at the caller of top frame method
1368 // Note we enter without the usual JRT wrapper. We will call a helper routine that
1369 // will do the normal VM entry. We do it this way so that we can see if the nmethod
1370 // we looked up the handler for has been deoptimized in the meantime. If it has been
1371 // we must not use the handler and instead return the deopt blob.
1372 address OptoRuntime::handle_exception_C(JavaThread* thread) {
1373 //
1374 // We are in Java not VM and in debug mode we have a NoHandleMark
1375 //
1376 #ifndef PRODUCT
1377   SharedRuntime::_find_handler_ctr++;          // find exception handler
1378 #endif
1379   debug_only(NoHandleMark __hm;)
1380   nmethod* nm = NULL;
1381   address handler_address = NULL;
1382   {
1383     // Enter the VM
1384 
1385     ResetNoHandleMark rnhm;
1386     handler_address = handle_exception_C_helper(thread, nm);
1387   }
1388 
1389   // Back in java: Use no oops, DON'T safepoint
1390 
1391   // Now check to see if the handler we are returning is in a now
1392   // deoptimized frame
1393 
1394   if (nm != NULL) {
1395     RegisterMap map(thread, false);
1396     frame caller = thread->last_frame().sender(&map);
1397 #ifdef ASSERT
1398     assert(caller.is_compiled_frame(), "must be");
1399 #endif // ASSERT
1400     if (caller.is_deoptimized_frame()) {
1401       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1402     }
1403   }
1404   return handler_address;
1405 }
1406 
1407 //------------------------------rethrow----------------------------------------
1408 // We get here after compiled code has executed a 'RethrowNode'.  The callee
1409 // is either throwing or rethrowing an exception.  The callee-save registers
1410 // have been restored, synchronized objects have been unlocked and the callee
1411 // stack frame has been removed.  The return address was passed in.
1412 // Exception oop is passed as the 1st argument.  This routine is then called
1413 // from the stub.  On exit, we know where to jump in the caller's code.
1414 // After this C code exits, the stub will pop his frame and end in a jump
1415 // (instead of a return).  We enter the caller's default handler.
1416 //
1417 // This must be JRT_LEAF:
1418 //     - caller will not change its state as we cannot block on exit,
1419 //       therefore raw_exception_handler_for_return_address is all it takes
1420 //       to handle deoptimized blobs
1421 //
1422 // However, there needs to be a safepoint check in the middle!  So compiled
1423 // safepoints are completely watertight.
1424 //
1425 // Thus, it cannot be a leaf since it contains the NoGCVerifier.
1426 //
1427 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
1428 //
1429 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
1430 #ifndef PRODUCT
1431   SharedRuntime::_rethrow_ctr++;               // count rethrows
1432 #endif
1433   assert (exception != NULL, "should have thrown a NULLPointerException");
1434 #ifdef ASSERT
1435   if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
1436     // should throw an exception here
1437     ShouldNotReachHere();
1438   }
1439 #endif
1440 
1441   thread->set_vm_result(exception);
1442   // Frame not compiled (handles deoptimization blob)
1443   return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
1444 }
1445 
1446 
1447 const TypeFunc *OptoRuntime::rethrow_Type() {
1448   // create input type (domain)
1449   const Type **fields = TypeTuple::fields(1);
1450   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1451   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1452 
1453   // create result type (range)
1454   fields = TypeTuple::fields(1);
1455   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1456   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1457 
1458   return TypeFunc::make(domain, range);
1459 }
1460 
1461 
1462 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
1463   // Deoptimize the caller before continuing, as the compiled
1464   // exception handler table may not be valid.
1465   if (!StressCompiledExceptionHandlers && doit) {
1466     deoptimize_caller_frame(thread);
1467   }
1468 }
1469 
1470 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) {
1471   // Called from within the owner thread, so no need for safepoint
1472   RegisterMap reg_map(thread);
1473   frame stub_frame = thread->last_frame();
1474   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1475   frame caller_frame = stub_frame.sender(&reg_map);
1476 
1477   // Deoptimize the caller frame.
1478   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1479 }
1480 
1481 
1482 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
1483   // Called from within the owner thread, so no need for safepoint
1484   RegisterMap reg_map(thread);
1485   frame stub_frame = thread->last_frame();
1486   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1487   frame caller_frame = stub_frame.sender(&reg_map);
1488   return caller_frame.is_deoptimized_frame();
1489 }
1490 
1491 
1492 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1493   // create input type (domain)
1494   const Type **fields = TypeTuple::fields(1);
1495   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // oop;          Receiver
1496   // // The JavaThread* is passed to each routine as the last argument
1497   // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // JavaThread *; Executing thread
1498   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1499 
1500   // create result type (range)
1501   fields = TypeTuple::fields(0);
1502 
1503   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1504 
1505   return TypeFunc::make(domain,range);
1506 }
1507 
1508 
1509 //-----------------------------------------------------------------------------
1510 // Dtrace support.  entry and exit probes have the same signature
1511 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1512   // create input type (domain)
1513   const Type **fields = TypeTuple::fields(2);
1514   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1515   fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM;  // Method*;    Method we are entering
1516   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1517 
1518   // create result type (range)
1519   fields = TypeTuple::fields(0);
1520 
1521   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1522 
1523   return TypeFunc::make(domain,range);
1524 }
1525 
1526 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1527   // create input type (domain)
1528   const Type **fields = TypeTuple::fields(2);
1529   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1530   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;  // oop;    newly allocated object
1531 
1532   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1533 
1534   // create result type (range)
1535   fields = TypeTuple::fields(0);
1536 
1537   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1538 
1539   return TypeFunc::make(domain,range);
1540 }
1541 
1542 
1543 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* thread))
1544   assert(oopDesc::is_oop(obj), "must be a valid oop");
1545   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1546   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1547 JRT_END
1548 
1549 //-----------------------------------------------------------------------------
1550 
1551 NamedCounter * volatile OptoRuntime::_named_counters = NULL;
1552 
1553 //
1554 // dump the collected NamedCounters.
1555 //
1556 void OptoRuntime::print_named_counters() {
1557   int total_lock_count = 0;
1558   int eliminated_lock_count = 0;
1559 
1560   NamedCounter* c = _named_counters;
1561   while (c) {
1562     if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1563       int count = c->count();
1564       if (count > 0) {
1565         bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1566         if (Verbose) {
1567           tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1568         }
1569         total_lock_count += count;
1570         if (eliminated) {
1571           eliminated_lock_count += count;
1572         }
1573       }
1574     } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1575       BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1576       if (blc->nonzero()) {
1577         tty->print_cr("%s", c->name());
1578         blc->print_on(tty);
1579       }
1580 #if INCLUDE_RTM_OPT
1581     } else if (c->tag() == NamedCounter::RTMLockingCounter) {
1582       RTMLockingCounters* rlc = ((RTMLockingNamedCounter*)c)->counters();
1583       if (rlc->nonzero()) {
1584         tty->print_cr("%s", c->name());
1585         rlc->print_on(tty);
1586       }
1587 #endif
1588     }
1589     c = c->next();
1590   }
1591   if (total_lock_count > 0) {
1592     tty->print_cr("dynamic locks: %d", total_lock_count);
1593     if (eliminated_lock_count) {
1594       tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1595                     (int)(eliminated_lock_count * 100.0 / total_lock_count));
1596     }
1597   }
1598 }
1599 
1600 //
1601 //  Allocate a new NamedCounter.  The JVMState is used to generate the
1602 //  name which consists of method@line for the inlining tree.
1603 //
1604 
1605 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1606   int max_depth = youngest_jvms->depth();
1607 
1608   // Visit scopes from youngest to oldest.
1609   bool first = true;
1610   stringStream st;
1611   for (int depth = max_depth; depth >= 1; depth--) {
1612     JVMState* jvms = youngest_jvms->of_depth(depth);
1613     ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1614     if (!first) {
1615       st.print(" ");
1616     } else {
1617       first = false;
1618     }
1619     int bci = jvms->bci();
1620     if (bci < 0) bci = 0;
1621     st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1622     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1623   }
1624   NamedCounter* c;
1625   if (tag == NamedCounter::BiasedLockingCounter) {
1626     c = new BiasedLockingNamedCounter(st.as_string());
1627   } else if (tag == NamedCounter::RTMLockingCounter) {
1628     c = new RTMLockingNamedCounter(st.as_string());
1629   } else {
1630     c = new NamedCounter(st.as_string(), tag);
1631   }
1632 
1633   // atomically add the new counter to the head of the list.  We only
1634   // add counters so this is safe.
1635   NamedCounter* head;
1636   do {
1637     c->set_next(NULL);
1638     head = _named_counters;
1639     c->set_next(head);
1640   } while (Atomic::cmpxchg(c, &_named_counters, head) != head);
1641   return c;
1642 }
1643 
1644 int trace_exception_counter = 0;
1645 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1646   trace_exception_counter++;
1647   stringStream tempst;
1648 
1649   tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1650   exception_oop->print_value_on(&tempst);
1651   tempst.print(" in ");
1652   CodeBlob* blob = CodeCache::find_blob(exception_pc);
1653   if (blob->is_compiled()) {
1654     CompiledMethod* cm = blob->as_compiled_method_or_null();
1655     cm->method()->print_value_on(&tempst);
1656   } else if (blob->is_runtime_stub()) {
1657     tempst.print("<runtime-stub>");
1658   } else {
1659     tempst.print("<unknown>");
1660   }
1661   tempst.print(" at " INTPTR_FORMAT,  p2i(exception_pc));
1662   tempst.print("]");
1663 
1664   st->print_raw_cr(tempst.as_string());
1665 }
--- EOF ---