< prev index next >

src/share/vm/opto/runtime.cpp

Print this page
rev 12906 : [mq]: gc_interface


  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 "memory/resourceArea.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "opto/ad.hpp"
  52 #include "opto/addnode.hpp"
  53 #include "opto/callnode.hpp"
  54 #include "opto/cfgnode.hpp"
  55 #include "opto/graphKit.hpp"
  56 #include "opto/machnode.hpp"
  57 #include "opto/matcher.hpp"


  77 // For debugging purposes:
  78 //  To force FullGCALot inside a runtime function, add the following two lines
  79 //
  80 //  Universe::release_fullgc_alot_dummy();
  81 //  MarkSweep::invoke(0, "Debugging");
  82 //
  83 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
  84 
  85 
  86 
  87 
  88 // Compiled code entry points
  89 address OptoRuntime::_new_instance_Java                           = NULL;
  90 address OptoRuntime::_new_array_Java                              = NULL;
  91 address OptoRuntime::_new_array_nozero_Java                       = NULL;
  92 address OptoRuntime::_multianewarray2_Java                        = NULL;
  93 address OptoRuntime::_multianewarray3_Java                        = NULL;
  94 address OptoRuntime::_multianewarray4_Java                        = NULL;
  95 address OptoRuntime::_multianewarray5_Java                        = NULL;
  96 address OptoRuntime::_multianewarrayN_Java                        = NULL;
  97 address OptoRuntime::_g1_wb_pre_Java                              = NULL;
  98 address OptoRuntime::_g1_wb_post_Java                             = NULL;
  99 address OptoRuntime::_vtable_must_compile_Java                    = NULL;
 100 address OptoRuntime::_complete_monitor_locking_Java               = NULL;
 101 address OptoRuntime::_monitor_notify_Java                         = NULL;
 102 address OptoRuntime::_monitor_notifyAll_Java                      = NULL;
 103 address OptoRuntime::_rethrow_Java                                = NULL;
 104 
 105 address OptoRuntime::_slow_arraycopy_Java                         = NULL;
 106 address OptoRuntime::_register_finalizer_Java                     = NULL;
 107 
 108 ExceptionBlob* OptoRuntime::_exception_blob;
 109 
 110 // This should be called in an assertion at the start of OptoRuntime routines
 111 // which are entered from compiled code (all of them)
 112 #ifdef ASSERT
 113 static bool check_compiled_frame(JavaThread* thread) {
 114   assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
 115   RegisterMap map(thread, false);
 116   frame caller = thread->last_frame().sender(&map);
 117   assert(caller.is_compiled_frame(), "not being called from compiled like code");
 118   return true;


 123 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
 124   var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc); \
 125   if (var == NULL) { return false; }
 126 
 127 bool OptoRuntime::generate(ciEnv* env) {
 128 
 129   generate_exception_blob();
 130 
 131   // Note: tls: Means fetching the return oop out of the thread-local storage
 132   //
 133   //   variable/name                       type-function-gen              , runtime method                  ,fncy_jp, tls,save_args,retpc
 134   // -------------------------------------------------------------------------------------------------------------------------------
 135   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true , false, false);
 136   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true , false, false);
 137   gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true , false, false);
 138   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true , false, false);
 139   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true , false, false);
 140   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true , false, false);
 141   gen(env, _multianewarray5_Java           , multianewarray5_Type         , multianewarray5_C               ,    0 , true , false, false);
 142   gen(env, _multianewarrayN_Java           , multianewarrayN_Type         , multianewarrayN_C               ,    0 , true , false, false);
 143   gen(env, _g1_wb_pre_Java                 , g1_wb_pre_Type               , SharedRuntime::g1_wb_pre        ,    0 , false, false, false);
 144   gen(env, _g1_wb_post_Java                , g1_wb_post_Type              , SharedRuntime::g1_wb_post       ,    0 , false, false, false);
 145   gen(env, _complete_monitor_locking_Java  , complete_monitor_enter_Type  , SharedRuntime::complete_monitor_locking_C, 0, false, false, false);
 146   gen(env, _monitor_notify_Java            , monitor_notify_Type          , monitor_notify_C                ,    0 , false, false, false);
 147   gen(env, _monitor_notifyAll_Java         , monitor_notify_Type          , monitor_notifyAll_C             ,    0 , false, false, false);
 148   gen(env, _rethrow_Java                   , rethrow_Type                 , rethrow_C                       ,    2 , true , false, true );
 149 
 150   gen(env, _slow_arraycopy_Java            , slow_arraycopy_Type          , SharedRuntime::slow_arraycopy_C ,    0 , false, false, false);
 151   gen(env, _register_finalizer_Java        , register_finalizer_Type      , register_finalizer              ,    0 , false, false, false);
 152 
 153   return true;
 154 }
 155 
 156 #undef gen
 157 
 158 
 159 // Helper method to do generation of RunTimeStub's
 160 address OptoRuntime::generate_stub( ciEnv* env,
 161                                     TypeFunc_generator gen, address C_function,
 162                                     const char *name, int is_fancy_jump,
 163                                     bool pass_tls,
 164                                     bool save_argument_registers,


 177   CodeBlob* cb = CodeCache::find_blob(entry);
 178   RuntimeStub* rs =(RuntimeStub *)cb;
 179   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
 180   return rs->name();
 181 #else
 182   // Fast implementation for product mode (maybe it should be inlined too)
 183   return "runtime stub";
 184 #endif
 185 }
 186 
 187 
 188 //=============================================================================
 189 // Opto compiler runtime routines
 190 //=============================================================================
 191 
 192 
 193 //=============================allocation======================================
 194 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 195 // and try allocation again.
 196 
 197 void OptoRuntime::new_store_pre_barrier(JavaThread* thread) {
 198   // After any safepoint, just before going back to compiled code,
 199   // we inform the GC that we will be doing initializing writes to
 200   // this object in the future without emitting card-marks, so
 201   // GC may take any compensating steps.
 202   // NOTE: Keep this code consistent with GraphKit::store_barrier.
 203 
 204   oop new_obj = thread->vm_result();
 205   if (new_obj == NULL)  return;
 206 
 207   assert(Universe::heap()->can_elide_tlab_store_barriers(),
 208          "compiler must check this first");
 209   // GC may decide to give back a safer copy of new_obj.
 210   new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
 211   thread->set_vm_result(new_obj);
 212 }
 213 
 214 // object allocation
 215 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))
 216   JRT_BLOCK;
 217 #ifndef PRODUCT
 218   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 219 #endif
 220   assert(check_compiled_frame(thread), "incorrect caller");
 221 
 222   // These checks are cheap to make and support reflective allocation.
 223   int lh = klass->layout_helper();
 224   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 225     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 226     klass->check_valid_for_instantiation(false, THREAD);
 227     if (!HAS_PENDING_EXCEPTION) {
 228       InstanceKlass::cast(klass)->initialize(THREAD);
 229     }
 230   }
 231 
 232   if (!HAS_PENDING_EXCEPTION) {
 233     // Scavenge and allocate an instance.
 234     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 235     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 236     thread->set_vm_result(result);
 237 
 238     // Pass oops back through thread local storage.  Our apparent type to Java
 239     // is that we return an oop, but we can block on exit from this routine and
 240     // a GC can trash the oop in C's return register.  The generated stub will
 241     // fetch the oop from TLS after any possible GC.
 242   }
 243 
 244   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 245   JRT_BLOCK_END;
 246 
 247   if (GraphKit::use_ReduceInitialCardMarks()) {
 248     // inform GC that we won't do card marks for initializing writes.
 249     new_store_pre_barrier(thread);
 250   }
 251 JRT_END
 252 
 253 
 254 // array allocation
 255 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))
 256   JRT_BLOCK;
 257 #ifndef PRODUCT
 258   SharedRuntime::_new_array_ctr++;            // new array requires GC
 259 #endif
 260   assert(check_compiled_frame(thread), "incorrect caller");
 261 
 262   // Scavenge and allocate an instance.
 263   oop result;
 264 
 265   if (array_type->is_typeArray_klass()) {
 266     // The oopFactory likes to work with the element type.
 267     // (We could bypass the oopFactory, since it doesn't add much value.)
 268     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 269     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 270   } else {
 271     // Although the oopFactory likes to work with the elem_type,
 272     // the compiler prefers the array_type, since it must already have
 273     // that latter value in hand for the fast path.
 274     Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive
 275     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
 276     result = oopFactory::new_objArray(elem_type, len, THREAD);
 277   }
 278 
 279   // Pass oops back through thread local storage.  Our apparent type to Java
 280   // is that we return an oop, but we can block on exit from this routine and
 281   // a GC can trash the oop in C's return register.  The generated stub will
 282   // fetch the oop from TLS after any possible GC.
 283   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 284   thread->set_vm_result(result);
 285   JRT_BLOCK_END;
 286 
 287   if (GraphKit::use_ReduceInitialCardMarks()) {
 288     // inform GC that we won't do card marks for initializing writes.
 289     new_store_pre_barrier(thread);
 290   }
 291 JRT_END
 292 
 293 // array allocation without zeroing
 294 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))
 295   JRT_BLOCK;
 296 #ifndef PRODUCT
 297   SharedRuntime::_new_array_ctr++;            // new array requires GC
 298 #endif
 299   assert(check_compiled_frame(thread), "incorrect caller");
 300 
 301   // Scavenge and allocate an instance.
 302   oop result;
 303 
 304   assert(array_type->is_typeArray_klass(), "should be called only for type array");
 305   // The oopFactory likes to work with the element type.
 306   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 307   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
 308 
 309   // Pass oops back through thread local storage.  Our apparent type to Java
 310   // is that we return an oop, but we can block on exit from this routine and
 311   // a GC can trash the oop in C's return register.  The generated stub will
 312   // fetch the oop from TLS after any possible GC.
 313   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 314   thread->set_vm_result(result);
 315   JRT_BLOCK_END;
 316 
 317   if (GraphKit::use_ReduceInitialCardMarks()) {
 318     // inform GC that we won't do card marks for initializing writes.
 319     new_store_pre_barrier(thread);
 320   }
 321 
 322   oop result = thread->vm_result();
 323   if ((len > 0) && (result != NULL) &&
 324       is_deoptimized_caller_frame(thread)) {
 325     // Zero array here if the caller is deoptimized.
 326     int size = ((typeArrayOop)result)->object_size();
 327     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 328     const size_t hs = arrayOopDesc::header_size(elem_type);
 329     // Align to next 8 bytes to avoid trashing arrays's length.
 330     const size_t aligned_hs = align_object_offset(hs);
 331     HeapWord* obj = (HeapWord*)result;
 332     if (aligned_hs > hs) {
 333       Copy::zero_to_words(obj+hs, aligned_hs-hs);
 334     }
 335     // Optimized zeroing.
 336     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
 337   }
 338 
 339 JRT_END
 340 


 542 
 543 const TypeFunc *OptoRuntime::multianewarray4_Type() {
 544   return multianewarray_Type(4);
 545 }
 546 
 547 const TypeFunc *OptoRuntime::multianewarray5_Type() {
 548   return multianewarray_Type(5);
 549 }
 550 
 551 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
 552   // create input type (domain)
 553   const Type **fields = TypeTuple::fields(2);
 554   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 555   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;   // array of dim sizes
 556   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 557 
 558   // create result type (range)
 559   fields = TypeTuple::fields(1);
 560   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 561   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 562 
 563   return TypeFunc::make(domain, range);
 564 }
 565 
 566 const TypeFunc *OptoRuntime::g1_wb_pre_Type() {
 567   const Type **fields = TypeTuple::fields(2);
 568   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
 569   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
 570   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 571 
 572   // create result type (range)
 573   fields = TypeTuple::fields(0);
 574   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 575 
 576   return TypeFunc::make(domain, range);
 577 }
 578 
 579 const TypeFunc *OptoRuntime::g1_wb_post_Type() {
 580 
 581   const Type **fields = TypeTuple::fields(2);
 582   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL;  // Card addr
 583   fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL;  // thread
 584   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 585 
 586   // create result type (range)
 587   fields = TypeTuple::fields(0);
 588   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields);
 589 
 590   return TypeFunc::make(domain, range);
 591 }
 592 
 593 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
 594   // create input type (domain)
 595   const Type **fields = TypeTuple::fields(1);
 596   fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
 597   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 598 
 599   // create result type (range)
 600   fields = TypeTuple::fields(0);
 601   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 602 
 603   return TypeFunc::make(domain, range);
 604 }
 605 
 606 //-----------------------------------------------------------------------------
 607 // Monitor Handling
 608 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {




  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/heapRegion.hpp"
  38 #include "gc/shared/barrierSet.hpp"
  39 #include "gc/shared/collectedHeap.hpp"
  40 #include "gc/shared/gcLocker.inline.hpp"
  41 #include "interpreter/bytecode.hpp"
  42 #include "interpreter/interpreter.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "logging/log.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "oops/typeArrayOop.inline.hpp"
  50 #include "opto/ad.hpp"
  51 #include "opto/addnode.hpp"
  52 #include "opto/callnode.hpp"
  53 #include "opto/cfgnode.hpp"
  54 #include "opto/graphKit.hpp"
  55 #include "opto/machnode.hpp"
  56 #include "opto/matcher.hpp"


  76 // For debugging purposes:
  77 //  To force FullGCALot inside a runtime function, add the following two lines
  78 //
  79 //  Universe::release_fullgc_alot_dummy();
  80 //  MarkSweep::invoke(0, "Debugging");
  81 //
  82 // At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
  83 
  84 
  85 
  86 
  87 // Compiled code entry points
  88 address OptoRuntime::_new_instance_Java                           = NULL;
  89 address OptoRuntime::_new_array_Java                              = NULL;
  90 address OptoRuntime::_new_array_nozero_Java                       = NULL;
  91 address OptoRuntime::_multianewarray2_Java                        = NULL;
  92 address OptoRuntime::_multianewarray3_Java                        = NULL;
  93 address OptoRuntime::_multianewarray4_Java                        = NULL;
  94 address OptoRuntime::_multianewarray5_Java                        = NULL;
  95 address OptoRuntime::_multianewarrayN_Java                        = NULL;


  96 address OptoRuntime::_vtable_must_compile_Java                    = NULL;
  97 address OptoRuntime::_complete_monitor_locking_Java               = NULL;
  98 address OptoRuntime::_monitor_notify_Java                         = NULL;
  99 address OptoRuntime::_monitor_notifyAll_Java                      = NULL;
 100 address OptoRuntime::_rethrow_Java                                = NULL;
 101 
 102 address OptoRuntime::_slow_arraycopy_Java                         = NULL;
 103 address OptoRuntime::_register_finalizer_Java                     = NULL;
 104 
 105 ExceptionBlob* OptoRuntime::_exception_blob;
 106 
 107 // This should be called in an assertion at the start of OptoRuntime routines
 108 // which are entered from compiled code (all of them)
 109 #ifdef ASSERT
 110 static bool check_compiled_frame(JavaThread* thread) {
 111   assert(thread->last_frame().is_runtime_frame(), "cannot call runtime directly from compiled code");
 112   RegisterMap map(thread, false);
 113   frame caller = thread->last_frame().sender(&map);
 114   assert(caller.is_compiled_frame(), "not being called from compiled like code");
 115   return true;


 120 #define gen(env, var, type_func_gen, c_func, fancy_jump, pass_tls, save_arg_regs, return_pc) \
 121   var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc); \
 122   if (var == NULL) { return false; }
 123 
 124 bool OptoRuntime::generate(ciEnv* env) {
 125 
 126   generate_exception_blob();
 127 
 128   // Note: tls: Means fetching the return oop out of the thread-local storage
 129   //
 130   //   variable/name                       type-function-gen              , runtime method                  ,fncy_jp, tls,save_args,retpc
 131   // -------------------------------------------------------------------------------------------------------------------------------
 132   gen(env, _new_instance_Java              , new_instance_Type            , new_instance_C                  ,    0 , true , false, false);
 133   gen(env, _new_array_Java                 , new_array_Type               , new_array_C                     ,    0 , true , false, false);
 134   gen(env, _new_array_nozero_Java          , new_array_Type               , new_array_nozero_C              ,    0 , true , false, false);
 135   gen(env, _multianewarray2_Java           , multianewarray2_Type         , multianewarray2_C               ,    0 , true , false, false);
 136   gen(env, _multianewarray3_Java           , multianewarray3_Type         , multianewarray3_C               ,    0 , true , false, false);
 137   gen(env, _multianewarray4_Java           , multianewarray4_Type         , multianewarray4_C               ,    0 , true , false, false);
 138   gen(env, _multianewarray5_Java           , multianewarray5_Type         , multianewarray5_C               ,    0 , true , false, false);
 139   gen(env, _multianewarrayN_Java           , multianewarrayN_Type         , multianewarrayN_C               ,    0 , true , false, false);


 140   gen(env, _complete_monitor_locking_Java  , complete_monitor_enter_Type  , SharedRuntime::complete_monitor_locking_C, 0, false, false, false);
 141   gen(env, _monitor_notify_Java            , monitor_notify_Type          , monitor_notify_C                ,    0 , false, false, false);
 142   gen(env, _monitor_notifyAll_Java         , monitor_notify_Type          , monitor_notifyAll_C             ,    0 , false, false, false);
 143   gen(env, _rethrow_Java                   , rethrow_Type                 , rethrow_C                       ,    2 , true , false, true );
 144 
 145   gen(env, _slow_arraycopy_Java            , slow_arraycopy_Type          , SharedRuntime::slow_arraycopy_C ,    0 , false, false, false);
 146   gen(env, _register_finalizer_Java        , register_finalizer_Type      , register_finalizer              ,    0 , false, false, false);
 147 
 148   return true;
 149 }
 150 
 151 #undef gen
 152 
 153 
 154 // Helper method to do generation of RunTimeStub's
 155 address OptoRuntime::generate_stub( ciEnv* env,
 156                                     TypeFunc_generator gen, address C_function,
 157                                     const char *name, int is_fancy_jump,
 158                                     bool pass_tls,
 159                                     bool save_argument_registers,


 172   CodeBlob* cb = CodeCache::find_blob(entry);
 173   RuntimeStub* rs =(RuntimeStub *)cb;
 174   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
 175   return rs->name();
 176 #else
 177   // Fast implementation for product mode (maybe it should be inlined too)
 178   return "runtime stub";
 179 #endif
 180 }
 181 
 182 
 183 //=============================================================================
 184 // Opto compiler runtime routines
 185 //=============================================================================
 186 
 187 
 188 //=============================allocation======================================
 189 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
 190 // and try allocation again.
 191 

















 192 // object allocation
 193 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))
 194   JRT_BLOCK;
 195 #ifndef PRODUCT
 196   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
 197 #endif
 198   assert(check_compiled_frame(thread), "incorrect caller");
 199 
 200   // These checks are cheap to make and support reflective allocation.
 201   int lh = klass->layout_helper();
 202   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
 203     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 204     klass->check_valid_for_instantiation(false, THREAD);
 205     if (!HAS_PENDING_EXCEPTION) {
 206       InstanceKlass::cast(klass)->initialize(THREAD);
 207     }
 208   }
 209 
 210   if (!HAS_PENDING_EXCEPTION) {
 211     // Scavenge and allocate an instance.
 212     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
 213     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
 214     thread->set_vm_result(result);
 215 
 216     // Pass oops back through thread local storage.  Our apparent type to Java
 217     // is that we return an oop, but we can block on exit from this routine and
 218     // a GC can trash the oop in C's return register.  The generated stub will
 219     // fetch the oop from TLS after any possible GC.
 220   }
 221 
 222   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 223   JRT_BLOCK_END;
 224 

 225   // inform GC that we won't do card marks for initializing writes.
 226   SharedRuntime::on_slowpath_allocation(thread);

 227 JRT_END
 228 
 229 
 230 // array allocation
 231 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))
 232   JRT_BLOCK;
 233 #ifndef PRODUCT
 234   SharedRuntime::_new_array_ctr++;            // new array requires GC
 235 #endif
 236   assert(check_compiled_frame(thread), "incorrect caller");
 237 
 238   // Scavenge and allocate an instance.
 239   oop result;
 240 
 241   if (array_type->is_typeArray_klass()) {
 242     // The oopFactory likes to work with the element type.
 243     // (We could bypass the oopFactory, since it doesn't add much value.)
 244     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 245     result = oopFactory::new_typeArray(elem_type, len, THREAD);
 246   } else {
 247     // Although the oopFactory likes to work with the elem_type,
 248     // the compiler prefers the array_type, since it must already have
 249     // that latter value in hand for the fast path.
 250     Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive
 251     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
 252     result = oopFactory::new_objArray(elem_type, len, THREAD);
 253   }
 254 
 255   // Pass oops back through thread local storage.  Our apparent type to Java
 256   // is that we return an oop, but we can block on exit from this routine and
 257   // a GC can trash the oop in C's return register.  The generated stub will
 258   // fetch the oop from TLS after any possible GC.
 259   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 260   thread->set_vm_result(result);
 261   JRT_BLOCK_END;
 262 

 263   // inform GC that we won't do card marks for initializing writes.
 264   SharedRuntime::on_slowpath_allocation(thread);

 265 JRT_END
 266 
 267 // array allocation without zeroing
 268 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))
 269   JRT_BLOCK;
 270 #ifndef PRODUCT
 271   SharedRuntime::_new_array_ctr++;            // new array requires GC
 272 #endif
 273   assert(check_compiled_frame(thread), "incorrect caller");
 274 
 275   // Scavenge and allocate an instance.
 276   oop result;
 277 
 278   assert(array_type->is_typeArray_klass(), "should be called only for type array");
 279   // The oopFactory likes to work with the element type.
 280   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 281   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
 282 
 283   // Pass oops back through thread local storage.  Our apparent type to Java
 284   // is that we return an oop, but we can block on exit from this routine and
 285   // a GC can trash the oop in C's return register.  The generated stub will
 286   // fetch the oop from TLS after any possible GC.
 287   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
 288   thread->set_vm_result(result);
 289   JRT_BLOCK_END;
 290 
 291 
 292   // inform GC that we won't do card marks for initializing writes.
 293   SharedRuntime::on_slowpath_allocation(thread);

 294 
 295   oop result = thread->vm_result();
 296   if ((len > 0) && (result != NULL) &&
 297       is_deoptimized_caller_frame(thread)) {
 298     // Zero array here if the caller is deoptimized.
 299     int size = ((typeArrayOop)result)->object_size();
 300     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
 301     const size_t hs = arrayOopDesc::header_size(elem_type);
 302     // Align to next 8 bytes to avoid trashing arrays's length.
 303     const size_t aligned_hs = align_object_offset(hs);
 304     HeapWord* obj = (HeapWord*)result;
 305     if (aligned_hs > hs) {
 306       Copy::zero_to_words(obj+hs, aligned_hs-hs);
 307     }
 308     // Optimized zeroing.
 309     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
 310   }
 311 
 312 JRT_END
 313 


 515 
 516 const TypeFunc *OptoRuntime::multianewarray4_Type() {
 517   return multianewarray_Type(4);
 518 }
 519 
 520 const TypeFunc *OptoRuntime::multianewarray5_Type() {
 521   return multianewarray_Type(5);
 522 }
 523 
 524 const TypeFunc *OptoRuntime::multianewarrayN_Type() {
 525   // create input type (domain)
 526   const Type **fields = TypeTuple::fields(2);
 527   fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;   // element klass
 528   fields[TypeFunc::Parms+1] = TypeInstPtr::NOTNULL;   // array of dim sizes
 529   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
 530 
 531   // create result type (range)
 532   fields = TypeTuple::fields(1);
 533   fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop
 534   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);



























 535 
 536   return TypeFunc::make(domain, range);
 537 }
 538 
 539 const TypeFunc *OptoRuntime::uncommon_trap_Type() {
 540   // create input type (domain)
 541   const Type **fields = TypeTuple::fields(1);
 542   fields[TypeFunc::Parms+0] = TypeInt::INT; // trap_reason (deopt reason and action)
 543   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 544 
 545   // create result type (range)
 546   fields = TypeTuple::fields(0);
 547   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 548 
 549   return TypeFunc::make(domain, range);
 550 }
 551 
 552 //-----------------------------------------------------------------------------
 553 // Monitor Handling
 554 const TypeFunc *OptoRuntime::complete_monitor_enter_Type() {


< prev index next >