1 /*
   2  * Copyright (c) 1998, 2015, 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/compiledIC.hpp"
  30 #include "code/icBuffer.hpp"
  31 #include "code/nmethod.hpp"
  32 #include "code/pcDesc.hpp"
  33 #include "code/scopeDesc.hpp"
  34 #include "code/vtableStubs.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "compiler/oopMap.hpp"
  37 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  38 #include "gc/g1/heapRegion.hpp"
  39 #include "gc/shared/barrierSet.hpp"
  40 #include "gc/shared/collectedHeap.hpp"
  41 #include "gc/shared/gcLocker.inline.hpp"
  42 #include "interpreter/bytecode.hpp"
  43 #include "interpreter/interpreter.hpp"
  44 #include "interpreter/linkResolver.hpp"
  45 #include "logging/log.hpp"
  46 #include "memory/oopFactory.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "opto/ad.hpp"
  50 #include "opto/addnode.hpp"
  51 #include "opto/callnode.hpp"
  52 #include "opto/cfgnode.hpp"
  53 #include "opto/graphKit.hpp"
  54 #include "opto/machnode.hpp"
  55 #include "opto/matcher.hpp"
  56 #include "opto/memnode.hpp"
  57 #include "opto/mulnode.hpp"
  58 #include "opto/runtime.hpp"
  59 #include "opto/subnode.hpp"
  60 #include "runtime/atomic.inline.hpp"
  61 #include "runtime/fprofiler.hpp"
  62 #include "runtime/handles.inline.hpp"
  63 #include "runtime/interfaceSupport.hpp"
  64 #include "runtime/javaCalls.hpp"
  65 #include "runtime/sharedRuntime.hpp"
  66 #include "runtime/signature.hpp"
  67 #include "runtime/threadCritical.hpp"
  68 #include "runtime/vframe.hpp"
  69 #include "runtime/vframeArray.hpp"
  70 #include "runtime/vframe_hp.hpp"
  71 #include "utilities/copy.hpp"
  72 #include "utilities/preserveException.hpp"
  73 
  74 
  75 // For debugging purposes:
  76 //  To force FullGCALot inside a runtime function, add the following two lines
  77 //
  78 //  Universe::release_fullgc_alot_dummy();
  79 //  MarkSweep::invoke(0, "Debugging");
  80 //
  81 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
  82 
  83 
  84 
  85 
  86 // Compiled code entry points
  87 address OptoRuntime::_new_instance_Java                           = NULL;
  88 address OptoRuntime::_new_array_Java                              = NULL;
  89 address OptoRuntime::_new_array_nozero_Java                       = NULL;
  90 address OptoRuntime::_multianewarray2_Java                        = NULL;
  91 address OptoRuntime::_multianewarray3_Java                        = NULL;
  92 address OptoRuntime::_multianewarray4_Java                        = NULL;
  93 address OptoRuntime::_multianewarray5_Java                        = NULL;
  94 address OptoRuntime::_multianewarrayN_Java                        = NULL;
  95 address OptoRuntime::_g1_wb_pre_Java                              = NULL;
  96 address OptoRuntime::_g1_wb_post_Java                             = NULL;
  97 address OptoRuntime::_vtable_must_compile_Java                    = NULL;
  98 address OptoRuntime::_complete_monitor_locking_Java               = NULL;
  99 address OptoRuntime::_monitor_notify_Java                         = NULL;
 100 address OptoRuntime::_monitor_notifyAll_Java                      = NULL;
 101 address OptoRuntime::_rethrow_Java                                = NULL;
 102 
 103 address OptoRuntime::_slow_arraycopy_Java                         = NULL;
 104 address OptoRuntime::_register_finalizer_Java                     = NULL;
 105 
 106 ExceptionBlob* OptoRuntime::_exception_blob;
 107 
 108 // This should be called in an assertion at the start of OptoRuntime routines
 109 // which are entered from compiled code (all of them)
 110 #ifdef ASSERT
 111 static bool check_compiled_frame(JavaThread* thread) {
 112   assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
 113   RegisterMap map(thread, false);
 114   frame caller = thread->last_frame().sender(&map);
 115   assert(caller.is_compiled_frame(), "not being called from compiled like code");
 116   return true;
 117 }
 118 #endif // ASSERT
 119 
 120 
 121 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
 122   var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc); \
 123   if (var == NULL) { return false; }
 124 
 125 bool OptoRuntime::generate(ciEnv* env) {
 126 
 127   generate_exception_blob();
 128 
 129   // Note: tls: Means fetching the return oop out of the thread-local storage
 130   //
 131   //   variable/name                       type-function-gen              , runtime method                  ,fncy_jp, tls,save_args,retpc
 132   // -------------------------------------------------------------------------------------------------------------------------------
 133   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true , false, false);
 134   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true , false, false);
 135   gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true , false, false);
 136   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true , false, false);
 137   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true , false, false);
 138   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true , false, false);
 139   gen(env, _multianewarray5_Java           , multianewarray5_Type         , multianewarray5_C               ,    0 , true , false, false);
 140   gen(env, _multianewarrayN_Java           , multianewarrayN_Type         , multianewarrayN_C               ,    0 , true , false, false);
 141   gen(env, _g1_wb_pre_Java                 , g1_wb_pre_Type               , SharedRuntime::g1_wb_pre        ,    0 , false, false, false);
 142   gen(env, _g1_wb_post_Java                , g1_wb_post_Type              , SharedRuntime::g1_wb_post       ,    0 , false, false, false);
 143   gen(env, _complete_monitor_locking_Java  , complete_monitor_enter_Type  , SharedRuntime::complete_monitor_locking_C, 0, false, false, false);
 144   gen(env, _monitor_notify_Java            , monitor_notify_Type          , monitor_notify_C                ,    0 , false, false, false);
 145   gen(env, _monitor_notifyAll_Java         , monitor_notify_Type          , monitor_notifyAll_C             ,    0 , false, false, false);
 146   gen(env, _rethrow_Java                   , rethrow_Type                 , rethrow_C                       ,    2 , true , false, true );
 147 
 148   gen(env, _slow_arraycopy_Java            , slow_arraycopy_Type          , SharedRuntime::slow_arraycopy_C ,    0 , false, false, false);
 149   gen(env, _register_finalizer_Java        , register_finalizer_Type      , register_finalizer              ,    0 , false, false, false);
 150 
 151   return true;
 152 }
 153 
 154 #undef gen
 155 
 156 
 157 // Helper method to do generation of RunTimeStub's
 158 address OptoRuntime::generate_stub( ciEnv* env,
 159                                     TypeFunc_generator gen, address C_function,
 160                                     const char *name, int is_fancy_jump,
 161                                     bool pass_tls,
 162                                     bool save_argument_registers,
 163                                     bool return_pc) {
 164 
 165   // Matching the default directive, we currently have no method to match.
 166   DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
 167   ResourceMark rm;
 168   Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc, directive);
 169   DirectivesStack::release(directive);
 170   return  C.stub_entry_point();
 171 }
 172 
 173 const char* OptoRuntime::stub_name(address entry) {
 174 #ifndef PRODUCT
 175   CodeBlob* cb = CodeCache::find_blob(entry);
 176   RuntimeStub* rs =(RuntimeStub *)cb;
 177   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
 178   return rs->name();
 179 #else
 180   // Fast implementation for product mode (maybe it should be inlined too)
 181   return "runtime stub";
 182 #endif
 183 }
 184 
 185 
 186 //=============================================================================
 187 // Opto compiler runtime routines
 188 //=============================================================================
 189 
 190 
 191 //=============================allocation======================================
 192 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 193 // and try allocation again.
 194 
 195 void OptoRuntime::new_store_pre_barrier(JavaThread* thread) {
 196   // After any safepoint, just before going back to compiled code,
 197   // we inform the GC that we will be doing initializing writes to
 198   // this object in the future without emitting card-marks, so
 199   // GC may take any compensating steps.
 200   // NOTE: Keep this code consistent with GraphKit::store_barrier.
 201 
 202   oop new_obj = thread->vm_result();
 203   if (new_obj == NULL)  return;
 204 
 205   assert(Universe::heap()->can_elide_tlab_store_barriers(),
 206          "compiler must check this first");
 207   // GC may decide to give back a safer copy of new_obj.
 208   new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
 209   thread->set_vm_result(new_obj);
 210 }
 211 
 212 // object allocation
 213 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))
 214   JRT_BLOCK;
 215 #ifndef PRODUCT
 216   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 217 #endif
 218   assert(check_compiled_frame(thread), "incorrect caller");
 219 
 220   // These checks are cheap to make and support reflective allocation.
 221   int lh = klass->layout_helper();
 222   if (Klass::layout_helper_needs_slow_path(lh)
 223       || !InstanceKlass::cast(klass)->is_initialized()) {
 224     KlassHandle kh(THREAD, klass);
 225     kh->check_valid_for_instantiation(false, THREAD);
 226     if (!HAS_PENDING_EXCEPTION) {
 227       InstanceKlass::cast(kh())->initialize(THREAD);
 228     }
 229     if (!HAS_PENDING_EXCEPTION) {
 230       klass = kh();
 231     } else {
 232       klass = NULL;
 233     }
 234   }
 235 
 236   if (klass != NULL) {
 237     // Scavenge and allocate an instance.
 238     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 239     thread->set_vm_result(result);
 240 
 241     // Pass oops back through thread local storage.  Our apparent type to Java
 242     // is that we return an oop, but we can block on exit from this routine and
 243     // a GC can trash the oop in C's return register.  The generated stub will
 244     // fetch the oop from TLS after any possible GC.
 245   }
 246 
 247   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 248   JRT_BLOCK_END;
 249 
 250   if (GraphKit::use_ReduceInitialCardMarks()) {
 251     // inform GC that we won't do card marks for initializing writes.
 252     new_store_pre_barrier(thread);
 253   }
 254 JRT_END
 255 
 256 
 257 // array allocation
 258 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))
 259   JRT_BLOCK;
 260 #ifndef PRODUCT
 261   SharedRuntime::_new_array_ctr++;            // new array requires GC
 262 #endif
 263   assert(check_compiled_frame(thread), "incorrect caller");
 264 
 265   // Scavenge and allocate an instance.
 266   oop result;
 267 
 268   if (array_type->is_typeArray_klass()) {
 269     // The oopFactory likes to work with the element type.
 270     // (We could bypass the oopFactory, since it doesn't add much value.)
 271     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 272     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 273   } else {
 274     // Although the oopFactory likes to work with the elem_type,
 275     // the compiler prefers the array_type, since it must already have
 276     // that latter value in hand for the fast path.
 277     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
 278     result = oopFactory::new_objArray(elem_type, len, THREAD);
 279   }
 280 
 281   // Pass oops back through thread local storage.  Our apparent type to Java
 282   // is that we return an oop, but we can block on exit from this routine and
 283   // a GC can trash the oop in C's return register.  The generated stub will
 284   // fetch the oop from TLS after any possible GC.
 285   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 286   thread->set_vm_result(result);
 287   JRT_BLOCK_END;
 288 
 289   if (GraphKit::use_ReduceInitialCardMarks()) {
 290     // inform GC that we won't do card marks for initializing writes.
 291     new_store_pre_barrier(thread);
 292   }
 293 JRT_END
 294 
 295 // array allocation without zeroing
 296 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))
 297   JRT_BLOCK;
 298 #ifndef PRODUCT
 299   SharedRuntime::_new_array_ctr++;            // new array requires GC
 300 #endif
 301   assert(check_compiled_frame(thread), "incorrect caller");
 302 
 303   // Scavenge and allocate an instance.
 304   oop result;
 305 
 306   assert(array_type->is_typeArray_klass(), "should be called only for type array");
 307   // The oopFactory likes to work with the element type.
 308   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 309   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
 310 
 311   // Pass oops back through thread local storage.  Our apparent type to Java
 312   // is that we return an oop, but we can block on exit from this routine and
 313   // a GC can trash the oop in C's return register.  The generated stub will
 314   // fetch the oop from TLS after any possible GC.
 315   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 316   thread->set_vm_result(result);
 317   JRT_BLOCK_END;
 318 
 319   if (GraphKit::use_ReduceInitialCardMarks()) {
 320     // inform GC that we won't do card marks for initializing writes.
 321     new_store_pre_barrier(thread);
 322   }
 323 
 324   oop result = thread->vm_result();
 325   if ((len > 0) && (result != NULL) &&
 326       is_deoptimized_caller_frame(thread)) {
 327     // Zero array here if the caller is deoptimized.
 328     int size = ((typeArrayOop)result)->object_size();
 329     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 330     const size_t hs = arrayOopDesc::header_size(elem_type);
 331     // Align to next 8 bytes to avoid trashing arrays's length.
 332     const size_t aligned_hs = align_object_offset(hs);
 333     HeapWord* obj = (HeapWord*)result;
 334     if (aligned_hs > hs) {
 335       Copy::zero_to_words(obj+hs, aligned_hs-hs);
 336     }
 337     // Optimized zeroing.
 338     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
 339   }
 340 
 341 JRT_END
 342 
 343 // Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
 344 
 345 // multianewarray for 2 dimensions
 346 JRT_ENTRY(void, OptoRuntime::multianewarray2_C(Klass* elem_type, int len1, int len2, JavaThread *thread))
 347 #ifndef PRODUCT
 348   SharedRuntime::_multi2_ctr++;                // multianewarray for 1 dimension
 349 #endif
 350   assert(check_compiled_frame(thread), "incorrect caller");
 351   assert(elem_type->is_klass(), "not a class");
 352   jint dims[2];
 353   dims[0] = len1;
 354   dims[1] = len2;
 355   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(2, dims, THREAD);
 356   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 357   thread->set_vm_result(obj);
 358 JRT_END
 359 
 360 // multianewarray for 3 dimensions
 361 JRT_ENTRY(void, OptoRuntime::multianewarray3_C(Klass* elem_type, int len1, int len2, int len3, JavaThread *thread))
 362 #ifndef PRODUCT
 363   SharedRuntime::_multi3_ctr++;                // multianewarray for 1 dimension
 364 #endif
 365   assert(check_compiled_frame(thread), "incorrect caller");
 366   assert(elem_type->is_klass(), "not a class");
 367   jint dims[3];
 368   dims[0] = len1;
 369   dims[1] = len2;
 370   dims[2] = len3;
 371   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(3, dims, THREAD);
 372   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 373   thread->set_vm_result(obj);
 374 JRT_END
 375 
 376 // multianewarray for 4 dimensions
 377 JRT_ENTRY(void, OptoRuntime::multianewarray4_C(Klass* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
 378 #ifndef PRODUCT
 379   SharedRuntime::_multi4_ctr++;                // multianewarray for 1 dimension
 380 #endif
 381   assert(check_compiled_frame(thread), "incorrect caller");
 382   assert(elem_type->is_klass(), "not a class");
 383   jint dims[4];
 384   dims[0] = len1;
 385   dims[1] = len2;
 386   dims[2] = len3;
 387   dims[3] = len4;
 388   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(4, dims, THREAD);
 389   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 390   thread->set_vm_result(obj);
 391 JRT_END
 392 
 393 // multianewarray for 5 dimensions
 394 JRT_ENTRY(void, OptoRuntime::multianewarray5_C(Klass* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
 395 #ifndef PRODUCT
 396   SharedRuntime::_multi5_ctr++;                // multianewarray for 1 dimension
 397 #endif
 398   assert(check_compiled_frame(thread), "incorrect caller");
 399   assert(elem_type->is_klass(), "not a class");
 400   jint dims[5];
 401   dims[0] = len1;
 402   dims[1] = len2;
 403   dims[2] = len3;
 404   dims[3] = len4;
 405   dims[4] = len5;
 406   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(5, dims, THREAD);
 407   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 408   thread->set_vm_result(obj);
 409 JRT_END
 410 
 411 JRT_ENTRY(void, OptoRuntime::multianewarrayN_C(Klass* elem_type, arrayOopDesc* dims, JavaThread *thread))
 412   assert(check_compiled_frame(thread), "incorrect caller");
 413   assert(elem_type->is_klass(), "not a class");
 414   assert(oop(dims)->is_typeArray(), "not an array");
 415 
 416   ResourceMark rm;
 417   jint len = dims->length();
 418   assert(len > 0, "Dimensions array should contain data");
 419   jint *j_dims = typeArrayOop(dims)->int_at_addr(0);
 420   jint *c_dims = NEW_RESOURCE_ARRAY(jint, len);
 421   Copy::conjoint_jints_atomic(j_dims, c_dims, len);
 422 
 423   oop obj = ArrayKlass::cast(elem_type)->multi_allocate(len, c_dims, THREAD);
 424   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 425   thread->set_vm_result(obj);
 426 JRT_END
 427 
 428 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notify_C(oopDesc* obj, JavaThread *thread))
 429 
 430   // Very few notify/notifyAll operations find any threads on the waitset, so
 431   // the dominant fast-path is to simply return.
 432   // Relatedly, it's critical that notify/notifyAll be fast in order to
 433   // reduce lock hold times.
 434   if (!SafepointSynchronize::is_synchronizing()) {
 435     if (ObjectSynchronizer::quick_notify(obj, thread, false)) {
 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::notify(h_obj, CHECK);
 447   JRT_BLOCK_END;
 448 JRT_END
 449 
 450 JRT_BLOCK_ENTRY(void, OptoRuntime::monitor_notifyAll_C(oopDesc* obj, JavaThread *thread))
 451 
 452   if (!SafepointSynchronize::is_synchronizing() ) {
 453     if (ObjectSynchronizer::quick_notify(obj, thread, true)) {
 454       return;
 455     }
 456   }
 457 
 458   // This is the case the fast-path above isn't provisioned to handle.
 459   // The fast-path is designed to handle frequently arising cases in an efficient manner.
 460   // (The fast-path is just a degenerate variant of the slow-path).
 461   // Perform the dreaded state transition and pass control into the slow-path.
 462   JRT_BLOCK;
 463   Handle h_obj(THREAD, obj);
 464   ObjectSynchronizer::notifyall(h_obj, CHECK);
 465   JRT_BLOCK_END;
 466 JRT_END
 467 
 468 const TypeFunc *OptoRuntime::new_instance_Type() {
 469   // create input type (domain)
 470   const Type **fields = TypeTuple::fields(1);
 471   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 472   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 473 
 474   // create result type (range)
 475   fields = TypeTuple::fields(1);
 476   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 477 
 478   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 479 
 480   return TypeFunc::make(domain, range);
 481 }
 482 
 483 
 484 const TypeFunc *OptoRuntime::athrow_Type() {
 485   // create input type (domain)
 486   const Type **fields = TypeTuple::fields(1);
 487   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Klass to be allocated
 488   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 489 
 490   // create result type (range)
 491   fields = TypeTuple::fields(0);
 492 
 493   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 494 
 495   return TypeFunc::make(domain, range);
 496 }
 497 
 498 
 499 const TypeFunc *OptoRuntime::new_array_Type() {
 500   // create input type (domain)
 501   const Type **fields = TypeTuple::fields(2);
 502   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 503   fields[TypeFunc::Parms+1] = TypeInt::INT;       // array size
 504   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 505 
 506   // create result type (range)
 507   fields = TypeTuple::fields(1);
 508   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 509 
 510   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 511 
 512   return TypeFunc::make(domain, range);
 513 }
 514 
 515 const TypeFunc *OptoRuntime::multianewarray_Type(int ndim) {
 516   // create input type (domain)
 517   const int nargs = ndim + 1;
 518   const Type **fields = TypeTuple::fields(nargs);
 519   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 520   for( int i = 1; i < nargs; i++ )
 521     fields[TypeFunc::Parms + i] = TypeInt::INT;       // array size
 522   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+nargs, fields);
 523 
 524   // create result type (range)
 525   fields = TypeTuple::fields(1);
 526   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 527   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 528 
 529   return TypeFunc::make(domain, range);
 530 }
 531 
 532 const TypeFunc *OptoRuntime::multianewarray2_Type() {
 533   return multianewarray_Type(2);
 534 }
 535 
 536 const TypeFunc *OptoRuntime::multianewarray3_Type() {
 537   return multianewarray_Type(3);
 538 }
 539 
 540 const TypeFunc *OptoRuntime::multianewarray4_Type() {
 541   return multianewarray_Type(4);
 542 }
 543 
 544 const TypeFunc *OptoRuntime::multianewarray5_Type() {
 545   return multianewarray_Type(5);
 546 }
 547 
 548 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
 549   // create input type (domain)
 550   const Type **fields = TypeTuple::fields(2);
 551   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 552   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;   // array of dim sizes
 553   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 554 
 555   // create result type (range)
 556   fields = TypeTuple::fields(1);
 557   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 558   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 559 
 560   return TypeFunc::make(domain, range);
 561 }
 562 
 563 const TypeFunc *OptoRuntime::g1_wb_pre_Type() {
 564   const Type **fields = TypeTuple::fields(2);
 565   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
 566   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
 567   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 568 
 569   // create result type (range)
 570   fields = TypeTuple::fields(0);
 571   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 572 
 573   return TypeFunc::make(domain, range);
 574 }
 575 
 576 const TypeFunc *OptoRuntime::g1_wb_post_Type() {
 577 
 578   const Type **fields = TypeTuple::fields(2);
 579   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL;  // Card addr
 580   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // thread
 581   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 582 
 583   // create result type (range)
 584   fields = TypeTuple::fields(0);
 585   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 586 
 587   return TypeFunc::make(domain, range);
 588 }
 589 
 590 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
 591   // create input type (domain)
 592   const Type **fields = TypeTuple::fields(1);
 593   fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
 594   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 595 
 596   // create result type (range)
 597   fields = TypeTuple::fields(0);
 598   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 599 
 600   return TypeFunc::make(domain, range);
 601 }
 602 
 603 //-----------------------------------------------------------------------------
 604 // Monitor Handling
 605 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {
 606   // create input type (domain)
 607   const Type **fields = TypeTuple::fields(2);
 608   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 609   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;   // Address of stack location for lock
 610   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,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 
 621 //-----------------------------------------------------------------------------
 622 const TypeFunc *OptoRuntime::complete_monitor_exit_Type() {
 623   // create input type (domain)
 624   const Type **fields = TypeTuple::fields(3);
 625   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 626   fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM;    // Address of stack location for lock - BasicLock
 627   fields[TypeFunc::Parms+2] = TypeRawPtr::BOTTOM;    // Thread pointer (Self)
 628   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3, fields);
 629 
 630   // create result type (range)
 631   fields = TypeTuple::fields(0);
 632 
 633   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 634 
 635   return TypeFunc::make(domain, range);
 636 }
 637 
 638 const TypeFunc *OptoRuntime::monitor_notify_Type() {
 639   // create input type (domain)
 640   const Type **fields = TypeTuple::fields(1);
 641   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // Object to be Locked
 642   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 643 
 644   // create result type (range)
 645   fields = TypeTuple::fields(0);
 646   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 647   return TypeFunc::make(domain, range);
 648 }
 649 
 650 const TypeFunc* OptoRuntime::flush_windows_Type() {
 651   // create input type (domain)
 652   const Type** fields = TypeTuple::fields(1);
 653   fields[TypeFunc::Parms+0] = NULL; // void
 654   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
 655 
 656   // create result type
 657   fields = TypeTuple::fields(1);
 658   fields[TypeFunc::Parms+0] = NULL; // void
 659   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 660 
 661   return TypeFunc::make(domain, range);
 662 }
 663 
 664 const TypeFunc* OptoRuntime::l2f_Type() {
 665   // create input type (domain)
 666   const Type **fields = TypeTuple::fields(2);
 667   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 668   fields[TypeFunc::Parms+1] = Type::HALF;
 669   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 670 
 671   // create result type (range)
 672   fields = TypeTuple::fields(1);
 673   fields[TypeFunc::Parms+0] = Type::FLOAT;
 674   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 675 
 676   return TypeFunc::make(domain, range);
 677 }
 678 
 679 const TypeFunc* OptoRuntime::modf_Type() {
 680   const Type **fields = TypeTuple::fields(2);
 681   fields[TypeFunc::Parms+0] = Type::FLOAT;
 682   fields[TypeFunc::Parms+1] = Type::FLOAT;
 683   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 684 
 685   // create result type (range)
 686   fields = TypeTuple::fields(1);
 687   fields[TypeFunc::Parms+0] = Type::FLOAT;
 688 
 689   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 690 
 691   return TypeFunc::make(domain, range);
 692 }
 693 
 694 const TypeFunc *OptoRuntime::Math_D_D_Type() {
 695   // create input type (domain)
 696   const Type **fields = TypeTuple::fields(2);
 697   // Symbol* name of class to be loaded
 698   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 699   fields[TypeFunc::Parms+1] = Type::HALF;
 700   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 701 
 702   // create result type (range)
 703   fields = TypeTuple::fields(2);
 704   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 705   fields[TypeFunc::Parms+1] = Type::HALF;
 706   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 707 
 708   return TypeFunc::make(domain, range);
 709 }
 710 
 711 const TypeFunc* OptoRuntime::Math_DD_D_Type() {
 712   const Type **fields = TypeTuple::fields(4);
 713   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 714   fields[TypeFunc::Parms+1] = Type::HALF;
 715   fields[TypeFunc::Parms+2] = Type::DOUBLE;
 716   fields[TypeFunc::Parms+3] = Type::HALF;
 717   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+4, fields);
 718 
 719   // create result type (range)
 720   fields = TypeTuple::fields(2);
 721   fields[TypeFunc::Parms+0] = Type::DOUBLE;
 722   fields[TypeFunc::Parms+1] = Type::HALF;
 723   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 724 
 725   return TypeFunc::make(domain, range);
 726 }
 727 
 728 //-------------- currentTimeMillis, currentTimeNanos, etc
 729 
 730 const TypeFunc* OptoRuntime::void_long_Type() {
 731   // create input type (domain)
 732   const Type **fields = TypeTuple::fields(0);
 733   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+0, fields);
 734 
 735   // create result type (range)
 736   fields = TypeTuple::fields(2);
 737   fields[TypeFunc::Parms+0] = TypeLong::LONG;
 738   fields[TypeFunc::Parms+1] = Type::HALF;
 739   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+2, fields);
 740 
 741   return TypeFunc::make(domain, range);
 742 }
 743 
 744 // arraycopy stub variations:
 745 enum ArrayCopyType {
 746   ac_fast,                      // void(ptr, ptr, size_t)
 747   ac_checkcast,                 //  int(ptr, ptr, size_t, size_t, ptr)
 748   ac_slow,                      // void(ptr, int, ptr, int, int)
 749   ac_generic                    //  int(ptr, int, ptr, int, int)
 750 };
 751 
 752 static const TypeFunc* make_arraycopy_Type(ArrayCopyType act) {
 753   // create input type (domain)
 754   int num_args      = (act == ac_fast ? 3 : 5);
 755   int num_size_args = (act == ac_fast ? 1 : act == ac_checkcast ? 2 : 0);
 756   int argcnt = num_args;
 757   LP64_ONLY(argcnt += num_size_args); // halfwords for lengths
 758   const Type** fields = TypeTuple::fields(argcnt);
 759   int argp = TypeFunc::Parms;
 760   fields[argp++] = TypePtr::NOTNULL;    // src
 761   if (num_size_args == 0) {
 762     fields[argp++] = TypeInt::INT;      // src_pos
 763   }
 764   fields[argp++] = TypePtr::NOTNULL;    // dest
 765   if (num_size_args == 0) {
 766     fields[argp++] = TypeInt::INT;      // dest_pos
 767     fields[argp++] = TypeInt::INT;      // length
 768   }
 769   while (num_size_args-- > 0) {
 770     fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 771     LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 772   }
 773   if (act == ac_checkcast) {
 774     fields[argp++] = TypePtr::NOTNULL;  // super_klass
 775   }
 776   assert(argp == TypeFunc::Parms+argcnt, "correct decoding of act");
 777   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 778 
 779   // create result type if needed
 780   int retcnt = (act == ac_checkcast || act == ac_generic ? 1 : 0);
 781   fields = TypeTuple::fields(1);
 782   if (retcnt == 0)
 783     fields[TypeFunc::Parms+0] = NULL; // void
 784   else
 785     fields[TypeFunc::Parms+0] = TypeInt::INT; // status result, if needed
 786   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+retcnt, fields);
 787   return TypeFunc::make(domain, range);
 788 }
 789 
 790 const TypeFunc* OptoRuntime::fast_arraycopy_Type() {
 791   // This signature is simple:  Two base pointers and a size_t.
 792   return make_arraycopy_Type(ac_fast);
 793 }
 794 
 795 const TypeFunc* OptoRuntime::checkcast_arraycopy_Type() {
 796   // An extension of fast_arraycopy_Type which adds type checking.
 797   return make_arraycopy_Type(ac_checkcast);
 798 }
 799 
 800 const TypeFunc* OptoRuntime::slow_arraycopy_Type() {
 801   // This signature is exactly the same as System.arraycopy.
 802   // There are no intptr_t (int/long) arguments.
 803   return make_arraycopy_Type(ac_slow);
 804 }
 805 
 806 const TypeFunc* OptoRuntime::generic_arraycopy_Type() {
 807   // This signature is like System.arraycopy, except that it returns status.
 808   return make_arraycopy_Type(ac_generic);
 809 }
 810 
 811 
 812 const TypeFunc* OptoRuntime::array_fill_Type() {
 813   const Type** fields;
 814   int argp = TypeFunc::Parms;
 815   // create input type (domain): pointer, int, size_t
 816   fields = TypeTuple::fields(3 LP64_ONLY( + 1));
 817   fields[argp++] = TypePtr::NOTNULL;
 818   fields[argp++] = TypeInt::INT;
 819   fields[argp++] = TypeX_X;               // size in whatevers (size_t)
 820   LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length
 821   const TypeTuple *domain = TypeTuple::make(argp, fields);
 822 
 823   // create result type
 824   fields = TypeTuple::fields(1);
 825   fields[TypeFunc::Parms+0] = NULL; // void
 826   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 827 
 828   return TypeFunc::make(domain, range);
 829 }
 830 
 831 // for aescrypt encrypt/decrypt operations, just three pointers returning void (length is constant)
 832 const TypeFunc* OptoRuntime::aescrypt_block_Type() {
 833   // create input type (domain)
 834   int num_args      = 3;
 835   if (Matcher::pass_original_key_for_aes()) {
 836     num_args = 4;
 837   }
 838   int argcnt = num_args;
 839   const Type** fields = TypeTuple::fields(argcnt);
 840   int argp = TypeFunc::Parms;
 841   fields[argp++] = TypePtr::NOTNULL;    // src
 842   fields[argp++] = TypePtr::NOTNULL;    // dest
 843   fields[argp++] = TypePtr::NOTNULL;    // k array
 844   if (Matcher::pass_original_key_for_aes()) {
 845     fields[argp++] = TypePtr::NOTNULL;    // original k array
 846   }
 847   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 848   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 849 
 850   // no result type needed
 851   fields = TypeTuple::fields(1);
 852   fields[TypeFunc::Parms+0] = NULL; // void
 853   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 854   return TypeFunc::make(domain, range);
 855 }
 856 
 857 /**
 858  * int updateBytesCRC32(int crc, byte* b, int len)
 859  */
 860 const TypeFunc* OptoRuntime::updateBytesCRC32_Type() {
 861   // create input type (domain)
 862   int num_args      = 3;
 863   int argcnt = num_args;
 864   const Type** fields = TypeTuple::fields(argcnt);
 865   int argp = TypeFunc::Parms;
 866   fields[argp++] = TypeInt::INT;        // crc
 867   fields[argp++] = TypePtr::NOTNULL;    // src
 868   fields[argp++] = TypeInt::INT;        // len
 869   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 870   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 871 
 872   // result type needed
 873   fields = TypeTuple::fields(1);
 874   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 875   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 876   return TypeFunc::make(domain, range);
 877 }
 878 
 879 /**
 880  * int updateBytesCRC32C(int crc, byte* buf, int len, int* table)
 881  */
 882 const TypeFunc* OptoRuntime::updateBytesCRC32C_Type() {
 883   // create input type (domain)
 884   int num_args      = 4;
 885   int argcnt = num_args;
 886   const Type** fields = TypeTuple::fields(argcnt);
 887   int argp = TypeFunc::Parms;
 888   fields[argp++] = TypeInt::INT;        // crc
 889   fields[argp++] = TypePtr::NOTNULL;    // buf
 890   fields[argp++] = TypeInt::INT;        // len
 891   fields[argp++] = TypePtr::NOTNULL;    // table
 892   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 893   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 894 
 895   // result type needed
 896   fields = TypeTuple::fields(1);
 897   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 898   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 899   return TypeFunc::make(domain, range);
 900 }
 901 
 902 /**
 903 *  int updateBytesAdler32(int adler, bytes* b, int off, int len)
 904 */
 905 const TypeFunc* OptoRuntime::updateBytesAdler32_Type() {
 906   // create input type (domain)
 907   int num_args      = 3;
 908   int argcnt = num_args;
 909   const Type** fields = TypeTuple::fields(argcnt);
 910   int argp = TypeFunc::Parms;
 911   fields[argp++] = TypeInt::INT;        // crc
 912   fields[argp++] = TypePtr::NOTNULL;    // src + offset
 913   fields[argp++] = TypeInt::INT;        // len
 914   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 915   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 916 
 917   // result type needed
 918   fields = TypeTuple::fields(1);
 919   fields[TypeFunc::Parms+0] = TypeInt::INT; // crc result
 920   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 921   return TypeFunc::make(domain, range);
 922 }
 923 
 924 // for cipherBlockChaining calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
 925 const TypeFunc* OptoRuntime::cipherBlockChaining_aescrypt_Type() {
 926   // create input type (domain)
 927   int num_args      = 5;
 928   if (Matcher::pass_original_key_for_aes()) {
 929     num_args = 6;
 930   }
 931   int argcnt = num_args;
 932   const Type** fields = TypeTuple::fields(argcnt);
 933   int argp = TypeFunc::Parms;
 934   fields[argp++] = TypePtr::NOTNULL;    // src
 935   fields[argp++] = TypePtr::NOTNULL;    // dest
 936   fields[argp++] = TypePtr::NOTNULL;    // k array
 937   fields[argp++] = TypePtr::NOTNULL;    // r array
 938   fields[argp++] = TypeInt::INT;        // src len
 939   if (Matcher::pass_original_key_for_aes()) {
 940     fields[argp++] = TypePtr::NOTNULL;    // original k array
 941   }
 942   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 943   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 944 
 945   // returning cipher len (int)
 946   fields = TypeTuple::fields(1);
 947   fields[TypeFunc::Parms+0] = TypeInt::INT;
 948   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 949   return TypeFunc::make(domain, range);
 950 }
 951 
 952 /*
 953  * void implCompress(byte[] buf, int ofs)
 954  */
 955 const TypeFunc* OptoRuntime::sha_implCompress_Type() {
 956   // create input type (domain)
 957   int num_args = 2;
 958   int argcnt = num_args;
 959   const Type** fields = TypeTuple::fields(argcnt);
 960   int argp = TypeFunc::Parms;
 961   fields[argp++] = TypePtr::NOTNULL; // buf
 962   fields[argp++] = TypePtr::NOTNULL; // state
 963   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 964   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 965 
 966   // no result type needed
 967   fields = TypeTuple::fields(1);
 968   fields[TypeFunc::Parms+0] = NULL; // void
 969   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
 970   return TypeFunc::make(domain, range);
 971 }
 972 
 973 /*
 974  * int implCompressMultiBlock(byte[] b, int ofs, int limit)
 975  */
 976 const TypeFunc* OptoRuntime::digestBase_implCompressMB_Type() {
 977   // create input type (domain)
 978   int num_args = 4;
 979   int argcnt = num_args;
 980   const Type** fields = TypeTuple::fields(argcnt);
 981   int argp = TypeFunc::Parms;
 982   fields[argp++] = TypePtr::NOTNULL; // buf
 983   fields[argp++] = TypePtr::NOTNULL; // state
 984   fields[argp++] = TypeInt::INT;     // ofs
 985   fields[argp++] = TypeInt::INT;     // limit
 986   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
 987   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
 988 
 989   // returning ofs (int)
 990   fields = TypeTuple::fields(1);
 991   fields[TypeFunc::Parms+0] = TypeInt::INT; // ofs
 992   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
 993   return TypeFunc::make(domain, range);
 994 }
 995 
 996 const TypeFunc* OptoRuntime::multiplyToLen_Type() {
 997   // create input type (domain)
 998   int num_args      = 6;
 999   int argcnt = num_args;
1000   const Type** fields = TypeTuple::fields(argcnt);
1001   int argp = TypeFunc::Parms;
1002   fields[argp++] = TypePtr::NOTNULL;    // x
1003   fields[argp++] = TypeInt::INT;        // xlen
1004   fields[argp++] = TypePtr::NOTNULL;    // y
1005   fields[argp++] = TypeInt::INT;        // ylen
1006   fields[argp++] = TypePtr::NOTNULL;    // z
1007   fields[argp++] = TypeInt::INT;        // zlen
1008   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1009   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1010 
1011   // no result type needed
1012   fields = TypeTuple::fields(1);
1013   fields[TypeFunc::Parms+0] = NULL;
1014   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1015   return TypeFunc::make(domain, range);
1016 }
1017 
1018 const TypeFunc* OptoRuntime::squareToLen_Type() {
1019   // create input type (domain)
1020   int num_args      = 4;
1021   int argcnt = num_args;
1022   const Type** fields = TypeTuple::fields(argcnt);
1023   int argp = TypeFunc::Parms;
1024   fields[argp++] = TypePtr::NOTNULL;    // x
1025   fields[argp++] = TypeInt::INT;        // len
1026   fields[argp++] = TypePtr::NOTNULL;    // z
1027   fields[argp++] = TypeInt::INT;        // zlen
1028   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1029   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1030 
1031   // no result type needed
1032   fields = TypeTuple::fields(1);
1033   fields[TypeFunc::Parms+0] = NULL;
1034   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1035   return TypeFunc::make(domain, range);
1036 }
1037 
1038 // for mulAdd calls, 2 pointers and 3 ints, returning int
1039 const TypeFunc* OptoRuntime::mulAdd_Type() {
1040   // create input type (domain)
1041   int num_args      = 5;
1042   int argcnt = num_args;
1043   const Type** fields = TypeTuple::fields(argcnt);
1044   int argp = TypeFunc::Parms;
1045   fields[argp++] = TypePtr::NOTNULL;    // out
1046   fields[argp++] = TypePtr::NOTNULL;    // in
1047   fields[argp++] = TypeInt::INT;        // offset
1048   fields[argp++] = TypeInt::INT;        // len
1049   fields[argp++] = TypeInt::INT;        // k
1050   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1051   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1052 
1053   // returning carry (int)
1054   fields = TypeTuple::fields(1);
1055   fields[TypeFunc::Parms+0] = TypeInt::INT;
1056   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms+1, fields);
1057   return TypeFunc::make(domain, range);
1058 }
1059 
1060 const TypeFunc* OptoRuntime::montgomeryMultiply_Type() {
1061   // create input type (domain)
1062   int num_args      = 7;
1063   int argcnt = num_args;
1064   const Type** fields = TypeTuple::fields(argcnt);
1065   int argp = TypeFunc::Parms;
1066   fields[argp++] = TypePtr::NOTNULL;    // a
1067   fields[argp++] = TypePtr::NOTNULL;    // b
1068   fields[argp++] = TypePtr::NOTNULL;    // n
1069   fields[argp++] = TypeInt::INT;        // len
1070   fields[argp++] = TypeLong::LONG;      // inv
1071   fields[argp++] = Type::HALF;
1072   fields[argp++] = TypePtr::NOTNULL;    // result
1073   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1074   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1075 
1076   // result type needed
1077   fields = TypeTuple::fields(1);
1078   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1079 
1080   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1081   return TypeFunc::make(domain, range);
1082 }
1083 
1084 const TypeFunc* OptoRuntime::montgomerySquare_Type() {
1085   // create input type (domain)
1086   int num_args      = 6;
1087   int argcnt = num_args;
1088   const Type** fields = TypeTuple::fields(argcnt);
1089   int argp = TypeFunc::Parms;
1090   fields[argp++] = TypePtr::NOTNULL;    // a
1091   fields[argp++] = TypePtr::NOTNULL;    // n
1092   fields[argp++] = TypeInt::INT;        // len
1093   fields[argp++] = TypeLong::LONG;      // inv
1094   fields[argp++] = Type::HALF;
1095   fields[argp++] = TypePtr::NOTNULL;    // result
1096   assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1097   const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1098 
1099   // result type needed
1100   fields = TypeTuple::fields(1);
1101   fields[TypeFunc::Parms+0] = TypePtr::NOTNULL;
1102 
1103   const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1104   return TypeFunc::make(domain, range);
1105 }
1106 
1107 // GHASH block processing
1108 const TypeFunc* OptoRuntime::ghash_processBlocks_Type() {
1109     int argcnt = 4;
1110 
1111     const Type** fields = TypeTuple::fields(argcnt);
1112     int argp = TypeFunc::Parms;
1113     fields[argp++] = TypePtr::NOTNULL;    // state
1114     fields[argp++] = TypePtr::NOTNULL;    // subkeyH
1115     fields[argp++] = TypePtr::NOTNULL;    // data
1116     fields[argp++] = TypeInt::INT;        // blocks
1117     assert(argp == TypeFunc::Parms+argcnt, "correct decoding");
1118     const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms+argcnt, fields);
1119 
1120     // result type needed
1121     fields = TypeTuple::fields(1);
1122     fields[TypeFunc::Parms+0] = NULL; // void
1123     const TypeTuple* range = TypeTuple::make(TypeFunc::Parms, fields);
1124     return TypeFunc::make(domain, range);
1125 }
1126 
1127 //------------- Interpreter state access for on stack replacement
1128 const TypeFunc* OptoRuntime::osr_end_Type() {
1129   // create input type (domain)
1130   const Type **fields = TypeTuple::fields(1);
1131   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // OSR temp buf
1132   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
1133 
1134   // create result type
1135   fields = TypeTuple::fields(1);
1136   // fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
1137   fields[TypeFunc::Parms+0] = NULL; // void
1138   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
1139   return TypeFunc::make(domain, range);
1140 }
1141 
1142 //-------------- methodData update helpers
1143 
1144 const TypeFunc* OptoRuntime::profile_receiver_type_Type() {
1145   // create input type (domain)
1146   const Type **fields = TypeTuple::fields(2);
1147   fields[TypeFunc::Parms+0] = TypeAryPtr::NOTNULL;    // methodData pointer
1148   fields[TypeFunc::Parms+1] = TypeInstPtr::BOTTOM;    // receiver oop
1149   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
1150 
1151   // create result type
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 JRT_LEAF(void, OptoRuntime::profile_receiver_type_C(DataLayout* data, oopDesc* receiver))
1159   if (receiver == NULL) return;
1160   Klass* receiver_klass = receiver->klass();
1161 
1162   intptr_t* mdp = ((intptr_t*)(data)) + DataLayout::header_size_in_cells();
1163   int empty_row = -1;           // free row, if any is encountered
1164 
1165   // ReceiverTypeData* vc = new ReceiverTypeData(mdp);
1166   for (uint row = 0; row < ReceiverTypeData::row_limit(); row++) {
1167     // if (vc->receiver(row) == receiver_klass)
1168     int receiver_off = ReceiverTypeData::receiver_cell_index(row);
1169     intptr_t row_recv = *(mdp + receiver_off);
1170     if (row_recv == (intptr_t) receiver_klass) {
1171       // vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
1172       int count_off = ReceiverTypeData::receiver_count_cell_index(row);
1173       *(mdp + count_off) += DataLayout::counter_increment;
1174       return;
1175     } else if (row_recv == 0) {
1176       // else if (vc->receiver(row) == NULL)
1177       empty_row = (int) row;
1178     }
1179   }
1180 
1181   if (empty_row != -1) {
1182     int receiver_off = ReceiverTypeData::receiver_cell_index(empty_row);
1183     // vc->set_receiver(empty_row, receiver_klass);
1184     *(mdp + receiver_off) = (intptr_t) receiver_klass;
1185     // vc->set_receiver_count(empty_row, DataLayout::counter_increment);
1186     int count_off = ReceiverTypeData::receiver_count_cell_index(empty_row);
1187     *(mdp + count_off) = DataLayout::counter_increment;
1188   } else {
1189     // Receiver did not match any saved receiver and there is no empty row for it.
1190     // Increment total counter to indicate polymorphic case.
1191     intptr_t* count_p = (intptr_t*)(((uint8_t*)(data)) + in_bytes(CounterData::count_offset()));
1192     *count_p += DataLayout::counter_increment;
1193   }
1194 JRT_END
1195 
1196 //-------------------------------------------------------------------------------------
1197 // register policy
1198 
1199 bool OptoRuntime::is_callee_saved_register(MachRegisterNumbers reg) {
1200   assert(reg >= 0 && reg < _last_Mach_Reg, "must be a machine register");
1201   switch (register_save_policy[reg]) {
1202     case 'C': return false; //SOC
1203     case 'E': return true ; //SOE
1204     case 'N': return false; //NS
1205     case 'A': return false; //AS
1206   }
1207   ShouldNotReachHere();
1208   return false;
1209 }
1210 
1211 //-----------------------------------------------------------------------
1212 // Exceptions
1213 //
1214 
1215 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg);
1216 
1217 // The method is an entry that is always called by a C++ method not
1218 // directly from compiled code. Compiled code will call the C++ method following.
1219 // We can't allow async exception to be installed during  exception processing.
1220 JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
1221 
1222   // Do not confuse exception_oop with pending_exception. The exception_oop
1223   // is only used to pass arguments into the method. Not for general
1224   // exception handling.  DO NOT CHANGE IT to use pending_exception, since
1225   // the runtime stubs checks this on exit.
1226   assert(thread->exception_oop() != NULL, "exception oop is found");
1227   address handler_address = NULL;
1228 
1229   Handle exception(thread, thread->exception_oop());
1230   address pc = thread->exception_pc();
1231 
1232   // Clear out the exception oop and pc since looking up an
1233   // exception handler can cause class loading, which might throw an
1234   // exception and those fields are expected to be clear during
1235   // normal bytecode execution.
1236   thread->clear_exception_oop_and_pc();
1237 
1238   if (log_is_enabled(Info, exceptions)) {
1239     ResourceMark rm;
1240     trace_exception(LogHandle(exceptions)::info_stream(), exception(), pc, "");
1241   }
1242 
1243   // for AbortVMOnException flag
1244   Exceptions::debug_check_abort(exception);
1245 
1246 #ifdef ASSERT
1247   if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
1248     // should throw an exception here
1249     ShouldNotReachHere();
1250   }
1251 #endif
1252 
1253   // new exception handling: this method is entered only from adapters
1254   // exceptions from compiled java methods are handled in compiled code
1255   // using rethrow node
1256 
1257   nm = CodeCache::find_nmethod(pc);
1258   assert(nm != NULL, "No NMethod found");
1259   if (nm->is_native_method()) {
1260     fatal("Native method should not have path to exception handling");
1261   } else {
1262     // we are switching to old paradigm: search for exception handler in caller_frame
1263     // instead in exception handler of caller_frame.sender()
1264 
1265     if (JvmtiExport::can_post_on_exceptions()) {
1266       // "Full-speed catching" is not necessary here,
1267       // since we're notifying the VM on every catch.
1268       // Force deoptimization and the rest of the lookup
1269       // will be fine.
1270       deoptimize_caller_frame(thread);
1271     }
1272 
1273     // Check the stack guard pages.  If enabled, look for handler in this frame;
1274     // otherwise, forcibly unwind the frame.
1275     //
1276     // 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
1277     bool force_unwind = !thread->reguard_stack();
1278     bool deopting = false;
1279     if (nm->is_deopt_pc(pc)) {
1280       deopting = true;
1281       RegisterMap map(thread, false);
1282       frame deoptee = thread->last_frame().sender(&map);
1283       assert(deoptee.is_deoptimized_frame(), "must be deopted");
1284       // Adjust the pc back to the original throwing pc
1285       pc = deoptee.pc();
1286     }
1287 
1288     // If we are forcing an unwind because of stack overflow then deopt is
1289     // irrelevant since we are throwing the frame away anyway.
1290 
1291     if (deopting && !force_unwind) {
1292       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1293     } else {
1294 
1295       handler_address =
1296         force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc);
1297 
1298       if (handler_address == NULL) {
1299         Handle original_exception(thread, exception());
1300         handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
1301         assert (handler_address != NULL, "must have compiled handler");
1302         // Update the exception cache only when the unwind was not forced
1303         // and there didn't happen another exception during the computation of the
1304         // compiled exception handler.
1305         if (!force_unwind && original_exception() == exception()) {
1306           nm->add_handler_for_exception_and_pc(exception,pc,handler_address);
1307         }
1308       } else {
1309         assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
1310       }
1311     }
1312 
1313     thread->set_exception_pc(pc);
1314     thread->set_exception_handler_pc(handler_address);
1315 
1316     // Check if the exception PC is a MethodHandle call site.
1317     thread->set_is_method_handle_return(nm->is_method_handle_return(pc));
1318   }
1319 
1320   // Restore correct return pc.  Was saved above.
1321   thread->set_exception_oop(exception());
1322   return handler_address;
1323 
1324 JRT_END
1325 
1326 // We are entering here from exception_blob
1327 // If there is a compiled exception handler in this method, we will continue there;
1328 // otherwise we will unwind the stack and continue at the caller of top frame method
1329 // Note we enter without the usual JRT wrapper. We will call a helper routine that
1330 // will do the normal VM entry. We do it this way so that we can see if the nmethod
1331 // we looked up the handler for has been deoptimized in the meantime. If it has been
1332 // we must not use the handler and instead return the deopt blob.
1333 address OptoRuntime::handle_exception_C(JavaThread* thread) {
1334 //
1335 // We are in Java not VM and in debug mode we have a NoHandleMark
1336 //
1337 #ifndef PRODUCT
1338   SharedRuntime::_find_handler_ctr++;          // find exception handler
1339 #endif
1340   debug_only(NoHandleMark __hm;)
1341   nmethod* nm = NULL;
1342   address handler_address = NULL;
1343   {
1344     // Enter the VM
1345 
1346     ResetNoHandleMark rnhm;
1347     handler_address = handle_exception_C_helper(thread, nm);
1348   }
1349 
1350   // Back in java: Use no oops, DON'T safepoint
1351 
1352   // Now check to see if the handler we are returning is in a now
1353   // deoptimized frame
1354 
1355   if (nm != NULL) {
1356     RegisterMap map(thread, false);
1357     frame caller = thread->last_frame().sender(&map);
1358 #ifdef ASSERT
1359     assert(caller.is_compiled_frame(), "must be");
1360 #endif // ASSERT
1361     if (caller.is_deoptimized_frame()) {
1362       handler_address = SharedRuntime::deopt_blob()->unpack_with_exception();
1363     }
1364   }
1365   return handler_address;
1366 }
1367 
1368 //------------------------------rethrow----------------------------------------
1369 // We get here after compiled code has executed a 'RethrowNode'.  The callee
1370 // is either throwing or rethrowing an exception.  The callee-save registers
1371 // have been restored, synchronized objects have been unlocked and the callee
1372 // stack frame has been removed.  The return address was passed in.
1373 // Exception oop is passed as the 1st argument.  This routine is then called
1374 // from the stub.  On exit, we know where to jump in the caller's code.
1375 // After this C code exits, the stub will pop his frame and end in a jump
1376 // (instead of a return).  We enter the caller's default handler.
1377 //
1378 // This must be JRT_LEAF:
1379 //     - caller will not change its state as we cannot block on exit,
1380 //       therefore raw_exception_handler_for_return_address is all it takes
1381 //       to handle deoptimized blobs
1382 //
1383 // However, there needs to be a safepoint check in the middle!  So compiled
1384 // safepoints are completely watertight.
1385 //
1386 // Thus, it cannot be a leaf since it contains the NoGCVerifier.
1387 //
1388 // *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
1389 //
1390 address OptoRuntime::rethrow_C(oopDesc* exception, JavaThread* thread, address ret_pc) {
1391 #ifndef PRODUCT
1392   SharedRuntime::_rethrow_ctr++;               // count rethrows
1393 #endif
1394   assert (exception != NULL, "should have thrown a NULLPointerException");
1395 #ifdef ASSERT
1396   if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {
1397     // should throw an exception here
1398     ShouldNotReachHere();
1399   }
1400 #endif
1401 
1402   thread->set_vm_result(exception);
1403   // Frame not compiled (handles deoptimization blob)
1404   return SharedRuntime::raw_exception_handler_for_return_address(thread, ret_pc);
1405 }
1406 
1407 
1408 const TypeFunc *OptoRuntime::rethrow_Type() {
1409   // create input type (domain)
1410   const Type **fields = TypeTuple::fields(1);
1411   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1412   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1413 
1414   // create result type (range)
1415   fields = TypeTuple::fields(1);
1416   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Exception oop
1417   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1418 
1419   return TypeFunc::make(domain, range);
1420 }
1421 
1422 
1423 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread, bool doit) {
1424   // Deoptimize the caller before continuing, as the compiled
1425   // exception handler table may not be valid.
1426   if (!StressCompiledExceptionHandlers && doit) {
1427     deoptimize_caller_frame(thread);
1428   }
1429 }
1430 
1431 void OptoRuntime::deoptimize_caller_frame(JavaThread *thread) {
1432   // Called from within the owner thread, so no need for safepoint
1433   RegisterMap reg_map(thread);
1434   frame stub_frame = thread->last_frame();
1435   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1436   frame caller_frame = stub_frame.sender(&reg_map);
1437 
1438   // Deoptimize the caller frame.
1439   Deoptimization::deoptimize_frame(thread, caller_frame.id());
1440 }
1441 
1442 
1443 bool OptoRuntime::is_deoptimized_caller_frame(JavaThread *thread) {
1444   // Called from within the owner thread, so no need for safepoint
1445   RegisterMap reg_map(thread);
1446   frame stub_frame = thread->last_frame();
1447   assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
1448   frame caller_frame = stub_frame.sender(&reg_map);
1449   return caller_frame.is_deoptimized_frame();
1450 }
1451 
1452 
1453 const TypeFunc *OptoRuntime::register_finalizer_Type() {
1454   // create input type (domain)
1455   const Type **fields = TypeTuple::fields(1);
1456   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;  // oop;          Receiver
1457   // // The JavaThread* is passed to each routine as the last argument
1458   // fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // JavaThread *; Executing thread
1459   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1,fields);
1460 
1461   // create result type (range)
1462   fields = TypeTuple::fields(0);
1463 
1464   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1465 
1466   return TypeFunc::make(domain,range);
1467 }
1468 
1469 
1470 //-----------------------------------------------------------------------------
1471 // Dtrace support.  entry and exit probes have the same signature
1472 const TypeFunc *OptoRuntime::dtrace_method_entry_exit_Type() {
1473   // create input type (domain)
1474   const Type **fields = TypeTuple::fields(2);
1475   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1476   fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM;  // Method*;    Method we are entering
1477   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1478 
1479   // create result type (range)
1480   fields = TypeTuple::fields(0);
1481 
1482   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1483 
1484   return TypeFunc::make(domain,range);
1485 }
1486 
1487 const TypeFunc *OptoRuntime::dtrace_object_alloc_Type() {
1488   // create input type (domain)
1489   const Type **fields = TypeTuple::fields(2);
1490   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
1491   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;  // oop;    newly allocated object
1492 
1493   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);
1494 
1495   // create result type (range)
1496   fields = TypeTuple::fields(0);
1497 
1498   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);
1499 
1500   return TypeFunc::make(domain,range);
1501 }
1502 
1503 
1504 JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThread* thread))
1505   assert(obj->is_oop(), "must be a valid oop");
1506   assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
1507   InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
1508 JRT_END
1509 
1510 //-----------------------------------------------------------------------------
1511 
1512 NamedCounter * volatile OptoRuntime::_named_counters = NULL;
1513 
1514 //
1515 // dump the collected NamedCounters.
1516 //
1517 void OptoRuntime::print_named_counters() {
1518   int total_lock_count = 0;
1519   int eliminated_lock_count = 0;
1520 
1521   NamedCounter* c = _named_counters;
1522   while (c) {
1523     if (c->tag() == NamedCounter::LockCounter || c->tag() == NamedCounter::EliminatedLockCounter) {
1524       int count = c->count();
1525       if (count > 0) {
1526         bool eliminated = c->tag() == NamedCounter::EliminatedLockCounter;
1527         if (Verbose) {
1528           tty->print_cr("%d %s%s", count, c->name(), eliminated ? " (eliminated)" : "");
1529         }
1530         total_lock_count += count;
1531         if (eliminated) {
1532           eliminated_lock_count += count;
1533         }
1534       }
1535     } else if (c->tag() == NamedCounter::BiasedLockingCounter) {
1536       BiasedLockingCounters* blc = ((BiasedLockingNamedCounter*)c)->counters();
1537       if (blc->nonzero()) {
1538         tty->print_cr("%s", c->name());
1539         blc->print_on(tty);
1540       }
1541 #if INCLUDE_RTM_OPT
1542     } else if (c->tag() == NamedCounter::RTMLockingCounter) {
1543       RTMLockingCounters* rlc = ((RTMLockingNamedCounter*)c)->counters();
1544       if (rlc->nonzero()) {
1545         tty->print_cr("%s", c->name());
1546         rlc->print_on(tty);
1547       }
1548 #endif
1549     }
1550     c = c->next();
1551   }
1552   if (total_lock_count > 0) {
1553     tty->print_cr("dynamic locks: %d", total_lock_count);
1554     if (eliminated_lock_count) {
1555       tty->print_cr("eliminated locks: %d (%d%%)", eliminated_lock_count,
1556                     (int)(eliminated_lock_count * 100.0 / total_lock_count));
1557     }
1558   }
1559 }
1560 
1561 //
1562 //  Allocate a new NamedCounter.  The JVMState is used to generate the
1563 //  name which consists of method@line for the inlining tree.
1564 //
1565 
1566 NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
1567   int max_depth = youngest_jvms->depth();
1568 
1569   // Visit scopes from youngest to oldest.
1570   bool first = true;
1571   stringStream st;
1572   for (int depth = max_depth; depth >= 1; depth--) {
1573     JVMState* jvms = youngest_jvms->of_depth(depth);
1574     ciMethod* m = jvms->has_method() ? jvms->method() : NULL;
1575     if (!first) {
1576       st.print(" ");
1577     } else {
1578       first = false;
1579     }
1580     int bci = jvms->bci();
1581     if (bci < 0) bci = 0;
1582     st.print("%s.%s@%d", m->holder()->name()->as_utf8(), m->name()->as_utf8(), bci);
1583     // To print linenumbers instead of bci use: m->line_number_from_bci(bci)
1584   }
1585   NamedCounter* c;
1586   if (tag == NamedCounter::BiasedLockingCounter) {
1587     c = new BiasedLockingNamedCounter(st.as_string());
1588   } else if (tag == NamedCounter::RTMLockingCounter) {
1589     c = new RTMLockingNamedCounter(st.as_string());
1590   } else {
1591     c = new NamedCounter(st.as_string(), tag);
1592   }
1593 
1594   // atomically add the new counter to the head of the list.  We only
1595   // add counters so this is safe.
1596   NamedCounter* head;
1597   do {
1598     c->set_next(NULL);
1599     head = _named_counters;
1600     c->set_next(head);
1601   } while (Atomic::cmpxchg_ptr(c, &_named_counters, head) != head);
1602   return c;
1603 }
1604 
1605 int trace_exception_counter = 0;
1606 static void trace_exception(outputStream* st, oop exception_oop, address exception_pc, const char* msg) {
1607   trace_exception_counter++;
1608   stringStream tempst;
1609 
1610   tempst.print("%d [Exception (%s): ", trace_exception_counter, msg);
1611   exception_oop->print_value_on(&tempst);
1612   tempst.print(" in ");
1613   CodeBlob* blob = CodeCache::find_blob(exception_pc);
1614   if (blob->is_nmethod()) {
1615     nmethod* nm = blob->as_nmethod_or_null();
1616     nm->method()->print_value_on(&tempst);
1617   } else if (blob->is_runtime_stub()) {
1618     tempst.print("<runtime-stub>");
1619   } else {
1620     tempst.print("<unknown>");
1621   }
1622   tempst.print(" at " INTPTR_FORMAT,  p2i(exception_pc));
1623   tempst.print("]");
1624 
1625   st->print_raw_cr(tempst.as_string());
1626 }