< prev index next >

src/hotspot/share/c1/c1_Runtime1.cpp

Print this page

  33 #include "classfile/vmSymbols.hpp"
  34 #include "code/aotCodeCache.hpp"
  35 #include "code/codeBlob.hpp"
  36 #include "code/compiledIC.hpp"
  37 #include "code/scopeDesc.hpp"
  38 #include "code/vtableStubs.hpp"
  39 #include "compiler/compilationPolicy.hpp"
  40 #include "compiler/disassembler.hpp"
  41 #include "compiler/oopMap.hpp"
  42 #include "gc/shared/barrierSet.hpp"
  43 #include "gc/shared/c1/barrierSetC1.hpp"
  44 #include "gc/shared/collectedHeap.hpp"
  45 #include "interpreter/bytecode.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "jfr/support/jfrIntrinsics.hpp"
  48 #include "logging/log.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/access.inline.hpp"


  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "prims/jvmtiExport.hpp"
  57 #include "runtime/atomic.hpp"
  58 #include "runtime/fieldDescriptor.inline.hpp"
  59 #include "runtime/frame.inline.hpp"
  60 #include "runtime/handles.inline.hpp"
  61 #include "runtime/interfaceSupport.inline.hpp"
  62 #include "runtime/javaCalls.hpp"
  63 #include "runtime/sharedRuntime.hpp"
  64 #include "runtime/stackWatermarkSet.hpp"
  65 #include "runtime/stubInfo.hpp"
  66 #include "runtime/stubRoutines.hpp"
  67 #include "runtime/vframe.inline.hpp"
  68 #include "runtime/vframeArray.hpp"
  69 #include "runtime/vm_version.hpp"
  70 #include "utilities/copy.hpp"
  71 #include "utilities/events.hpp"
  72 

  97 
  98 
  99 void StubAssembler::set_num_rt_args(int args) {
 100   if (_num_rt_args == 0) {
 101     _num_rt_args = args;
 102   }
 103   assert(_num_rt_args == args, "can't change the number of args");
 104 }
 105 
 106 // Implementation of Runtime1
 107 CodeBlob* Runtime1::_blobs[StubInfo::C1_STUB_COUNT];
 108 
 109 #ifndef PRODUCT
 110 // statistics
 111 uint Runtime1::_generic_arraycopystub_cnt = 0;
 112 uint Runtime1::_arraycopy_slowcase_cnt = 0;
 113 uint Runtime1::_arraycopy_checkcast_cnt = 0;
 114 uint Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
 115 uint Runtime1::_new_type_array_slowcase_cnt = 0;
 116 uint Runtime1::_new_object_array_slowcase_cnt = 0;

 117 uint Runtime1::_new_instance_slowcase_cnt = 0;
 118 uint Runtime1::_new_multi_array_slowcase_cnt = 0;





 119 uint Runtime1::_monitorenter_slowcase_cnt = 0;
 120 uint Runtime1::_monitorexit_slowcase_cnt = 0;
 121 uint Runtime1::_patch_code_slowcase_cnt = 0;
 122 uint Runtime1::_throw_range_check_exception_count = 0;
 123 uint Runtime1::_throw_index_exception_count = 0;
 124 uint Runtime1::_throw_div0_exception_count = 0;
 125 uint Runtime1::_throw_null_pointer_exception_count = 0;
 126 uint Runtime1::_throw_class_cast_exception_count = 0;
 127 uint Runtime1::_throw_incompatible_class_change_error_count = 0;


 128 uint Runtime1::_throw_count = 0;
 129 
 130 static uint _byte_arraycopy_stub_cnt = 0;
 131 static uint _short_arraycopy_stub_cnt = 0;
 132 static uint _int_arraycopy_stub_cnt = 0;
 133 static uint _long_arraycopy_stub_cnt = 0;
 134 static uint _oop_arraycopy_stub_cnt = 0;
 135 
 136 address Runtime1::arraycopy_count_address(BasicType type) {
 137   switch (type) {
 138   case T_BOOLEAN:
 139   case T_BYTE:   return (address)&_byte_arraycopy_stub_cnt;
 140   case T_CHAR:
 141   case T_SHORT:  return (address)&_short_arraycopy_stub_cnt;
 142   case T_FLOAT:
 143   case T_INT:    return (address)&_int_arraycopy_stub_cnt;
 144   case T_DOUBLE:
 145   case T_LONG:   return (address)&_long_arraycopy_stub_cnt;
 146   case T_ARRAY:
 147   case T_OBJECT: return (address)&_oop_arraycopy_stub_cnt;

 355   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
 356   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32C());
 357   FUNCTION_CASE(entry, StubRoutines::vectorizedMismatch());
 358   FUNCTION_CASE(entry, StubRoutines::dexp());
 359   FUNCTION_CASE(entry, StubRoutines::dlog());
 360   FUNCTION_CASE(entry, StubRoutines::dlog10());
 361   FUNCTION_CASE(entry, StubRoutines::dpow());
 362   FUNCTION_CASE(entry, StubRoutines::dsin());
 363   FUNCTION_CASE(entry, StubRoutines::dcos());
 364   FUNCTION_CASE(entry, StubRoutines::dtan());
 365   FUNCTION_CASE(entry, StubRoutines::dsinh());
 366   FUNCTION_CASE(entry, StubRoutines::dtanh());
 367   FUNCTION_CASE(entry, StubRoutines::dcbrt());
 368 
 369 #undef FUNCTION_CASE
 370 
 371   // Soft float adds more runtime names.
 372   return pd_name_for_address(entry);
 373 }
 374 
 375 
 376 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* current, Klass* klass))
 377 #ifndef PRODUCT
 378   if (PrintC1Statistics) {
 379     _new_instance_slowcase_cnt++;
 380   }
 381 #endif
 382   assert(klass->is_klass(), "not a class");
 383   Handle holder(current, klass->klass_holder()); // keep the klass alive
 384   InstanceKlass* h = InstanceKlass::cast(klass);
 385   h->check_valid_for_instantiation(true, CHECK);
 386   // make sure klass is initialized
 387   h->initialize(CHECK);
 388   // allocate instance and return via TLS
 389   oop obj = h->allocate_instance(CHECK);
 390   current->set_vm_result_oop(obj);
 391 JRT_END
 392 



 393 
 394 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* current, Klass* klass, jint length))
 395 #ifndef PRODUCT
 396   if (PrintC1Statistics) {
 397     _new_type_array_slowcase_cnt++;
 398   }
 399 #endif
 400   // Note: no handle for klass needed since they are not used
 401   //       anymore after new_typeArray() and no GC can happen before.
 402   //       (This may have to change if this code changes!)
 403   assert(klass->is_klass(), "not a class");
 404   BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
 405   oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 406   current->set_vm_result_oop(obj);
 407   // This is pretty rare but this runtime patch is stressful to deoptimization
 408   // if we deoptimize here so force a deopt to stress the path.
 409   if (DeoptimizeALot) {
 410     deopt_caller(current);
 411   }
 412 

 418   if (PrintC1Statistics) {
 419     _new_object_array_slowcase_cnt++;
 420   }
 421 #endif
 422   // Note: no handle for klass needed since they are not used
 423   //       anymore after new_objArray() and no GC can happen before.
 424   //       (This may have to change if this code changes!)
 425   assert(array_klass->is_klass(), "not a class");
 426   Handle holder(current, array_klass->klass_holder()); // keep the klass alive
 427   Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 428   objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 429   current->set_vm_result_oop(obj);
 430   // This is pretty rare but this runtime patch is stressful to deoptimization
 431   // if we deoptimize here so force a deopt to stress the path.
 432   if (DeoptimizeALot) {
 433     deopt_caller(current);
 434   }
 435 JRT_END
 436 
 437 
























 438 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims))
 439 #ifndef PRODUCT
 440   if (PrintC1Statistics) {
 441     _new_multi_array_slowcase_cnt++;
 442   }
 443 #endif
 444   assert(klass->is_klass(), "not a class");
 445   assert(rank >= 1, "rank must be nonzero");
 446   Handle holder(current, klass->klass_holder()); // keep the klass alive
 447   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 448   current->set_vm_result_oop(obj);
 449 JRT_END
 450 
 451 
































































































 452 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* current, StubId id))
 453   tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", (int)id);
 454 JRT_END
 455 
 456 
 457 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* current, oopDesc* obj))
 458   ResourceMark rm(current);
 459   const char* klass_name = obj->klass()->external_name();
 460   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ArrayStoreException(), klass_name);
 461 JRT_END
 462 
 463 
 464 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
 465 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
 466 // method) method is passed as an argument. In order to do that it is embedded in the code as
 467 // a constant.
 468 static nmethod* counter_overflow_helper(JavaThread* current, int branch_bci, Method* m) {
 469   nmethod* osr_nm = nullptr;
 470   methodHandle method(current, m);
 471 

 755     _throw_class_cast_exception_count++;
 756   }
 757 #endif
 758   ResourceMark rm(current);
 759   char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
 760   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ClassCastException(), message);
 761 JRT_END
 762 
 763 
 764 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* current))
 765 #ifndef PRODUCT
 766   if (PrintC1Statistics) {
 767     _throw_incompatible_class_change_error_count++;
 768   }
 769 #endif
 770   ResourceMark rm(current);
 771   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IncompatibleClassChangeError());
 772 JRT_END
 773 
 774 













 775 JRT_BLOCK_ENTRY(void, Runtime1::monitorenter(JavaThread* current, oopDesc* obj, BasicObjectLock* lock))
 776 #ifndef PRODUCT
 777   if (PrintC1Statistics) {
 778     _monitorenter_slowcase_cnt++;
 779   }
 780 #endif
 781   if (LockingMode == LM_MONITOR) {
 782     lock->set_obj(obj);
 783   }
 784   assert(obj == lock->obj(), "must match");
 785   SharedRuntime::monitor_enter_helper(obj, lock->lock(), current);
 786 JRT_END
 787 
 788 
 789 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* current, BasicObjectLock* lock))
 790   assert(current == JavaThread::current(), "pre-condition");
 791 #ifndef PRODUCT
 792   if (PrintC1Statistics) {
 793     _monitorexit_slowcase_cnt++;
 794   }

 960                       RegisterMap::WalkContinuation::skip);
 961   frame runtime_frame = current->last_frame();
 962   frame caller_frame = runtime_frame.sender(&reg_map);
 963 
 964   // last java frame on stack
 965   vframeStream vfst(current, true);
 966   assert(!vfst.at_end(), "Java frame must exist");
 967 
 968   methodHandle caller_method(current, vfst.method());
 969   // Note that caller_method->code() may not be same as caller_code because of OSR's
 970   // Note also that in the presence of inlining it is not guaranteed
 971   // that caller_method() == caller_code->method()
 972 
 973   int bci = vfst.bci();
 974   Bytecodes::Code code = caller_method()->java_code_at(bci);
 975 
 976   // this is used by assertions in the access_field_patching_id
 977   BasicType patch_field_type = T_ILLEGAL;
 978   bool deoptimize_for_volatile = false;
 979   bool deoptimize_for_atomic = false;



 980   int patch_field_offset = -1;
 981   Klass* init_klass = nullptr; // klass needed by load_klass_patching code
 982   Klass* load_klass = nullptr; // klass needed by load_klass_patching code
 983   Handle mirror(current, nullptr); // oop needed by load_mirror_patching code
 984   Handle appendix(current, nullptr); // oop needed by appendix_patching code
 985   bool load_klass_or_mirror_patch_id =
 986     (stub_id == StubId::c1_load_klass_patching_id || stub_id == StubId::c1_load_mirror_patching_id);
 987 
 988   if (stub_id == StubId::c1_access_field_patching_id) {
 989 
 990     Bytecode_field field_access(caller_method, bci);
 991     fieldDescriptor result; // initialize class if needed
 992     Bytecodes::Code code = field_access.code();
 993     constantPoolHandle constants(current, caller_method->constants());
 994     LinkResolver::resolve_field_access(result, constants, field_access.index(), caller_method, Bytecodes::java_code(code), CHECK);
 995     patch_field_offset = result.offset();
 996 
 997     // If we're patching a field which is volatile then at compile it
 998     // must not have been know to be volatile, so the generated code
 999     // isn't correct for a volatile reference.  The nmethod has to be

1003     // used for patching references to oops which don't need special
1004     // handling in the volatile case.
1005 
1006     deoptimize_for_volatile = result.access_flags().is_volatile();
1007 
1008     // If we are patching a field which should be atomic, then
1009     // the generated code is not correct either, force deoptimizing.
1010     // We need to only cover T_LONG and T_DOUBLE fields, as we can
1011     // break access atomicity only for them.
1012 
1013     // Strictly speaking, the deoptimization on 64-bit platforms
1014     // is unnecessary, and T_LONG stores on 32-bit platforms need
1015     // to be handled by special patching code when AlwaysAtomicAccesses
1016     // becomes product feature. At this point, we are still going
1017     // for the deoptimization for consistency against volatile
1018     // accesses.
1019 
1020     patch_field_type = result.field_type();
1021     deoptimize_for_atomic = (AlwaysAtomicAccesses && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG));
1022 













1023   } else if (load_klass_or_mirror_patch_id) {
1024     Klass* k = nullptr;
1025     switch (code) {
1026       case Bytecodes::_putstatic:
1027       case Bytecodes::_getstatic:
1028         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
1029           init_klass = klass;
1030           mirror = Handle(current, klass->java_mirror());
1031         }
1032         break;
1033       case Bytecodes::_new:
1034         { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
1035           k = caller_method->constants()->klass_at(bnew.index(), CHECK);
1036         }
1037         break;
1038       case Bytecodes::_multianewarray:
1039         { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
1040           k = caller_method->constants()->klass_at(mna.index(), CHECK);
1041         }
1042         break;
1043       case Bytecodes::_instanceof:
1044         { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));
1045           k = caller_method->constants()->klass_at(io.index(), CHECK);
1046         }
1047         break;
1048       case Bytecodes::_checkcast:
1049         { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));
1050           k = caller_method->constants()->klass_at(cc.index(), CHECK);
1051         }
1052         break;
1053       case Bytecodes::_anewarray:
1054         { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));
1055           Klass* ek = caller_method->constants()->klass_at(anew.index(), CHECK);
1056           k = ek->array_klass(CHECK);






1057         }
1058         break;
1059       case Bytecodes::_ldc:
1060       case Bytecodes::_ldc_w:
1061       case Bytecodes::_ldc2_w:
1062         {
1063           Bytecode_loadconstant cc(caller_method, bci);
1064           oop m = cc.resolve_constant(CHECK);
1065           mirror = Handle(current, m);
1066         }
1067         break;
1068       default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");
1069     }
1070     load_klass = k;
1071   } else if (stub_id == StubId::c1_load_appendix_patching_id) {
1072     Bytecode_invoke bytecode(caller_method, bci);
1073     Bytecodes::Code bc = bytecode.invoke_code();
1074 
1075     CallInfo info;
1076     constantPoolHandle pool(current, caller_method->constants());
1077     int index = bytecode.index();
1078     LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);
1079     switch (bc) {
1080       case Bytecodes::_invokehandle: {
1081         ResolvedMethodEntry* entry = pool->cache()->set_method_handle(index, info);
1082         appendix = Handle(current, pool->cache()->appendix_if_resolved(entry));
1083         break;
1084       }
1085       case Bytecodes::_invokedynamic: {
1086         appendix = Handle(current, pool->cache()->set_dynamic_call(info, index));
1087         break;
1088       }
1089       default: fatal("unexpected bytecode for load_appendix_patching_id");
1090     }
1091   } else {
1092     ShouldNotReachHere();
1093   }
1094 
1095   if (deoptimize_for_volatile || deoptimize_for_atomic) {




1096     // At compile time we assumed the field wasn't volatile/atomic but after
1097     // loading it turns out it was volatile/atomic so we have to throw the
1098     // compiled code out and let it be regenerated.
1099     if (TracePatching) {
1100       if (deoptimize_for_volatile) {
1101         tty->print_cr("Deoptimizing for patching volatile field reference");
1102       }
1103       if (deoptimize_for_atomic) {
1104         tty->print_cr("Deoptimizing for patching atomic field reference");
1105       }









1106     }
1107 
1108     // It's possible the nmethod was invalidated in the last
1109     // safepoint, but if it's still alive then make it not_entrant.
1110     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1111     if (nm != nullptr) {
1112       nm->make_not_entrant(nmethod::InvalidationReason::C1_CODEPATCH);
1113     }
1114 
1115     Deoptimization::deoptimize_frame(current, caller_frame.id());
1116 
1117     // Return to the now deoptimized frame.
1118   }
1119 
1120   // Now copy code back
1121 
1122   {
1123     MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
1124     //
1125     // Deoptimization may have happened while we waited for the lock.

1536 #ifndef PRODUCT
1537 void Runtime1::print_statistics() {
1538   tty->print_cr("C1 Runtime statistics:");
1539   tty->print_cr(" _resolve_invoke_virtual_cnt:     %u", SharedRuntime::_resolve_virtual_ctr);
1540   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %u", SharedRuntime::_resolve_opt_virtual_ctr);
1541   tty->print_cr(" _resolve_invoke_static_cnt:      %u", SharedRuntime::_resolve_static_ctr);
1542   tty->print_cr(" _handle_wrong_method_cnt:        %u", SharedRuntime::_wrong_method_ctr);
1543   tty->print_cr(" _ic_miss_cnt:                    %u", SharedRuntime::_ic_miss_ctr);
1544   tty->print_cr(" _generic_arraycopystub_cnt:      %u", _generic_arraycopystub_cnt);
1545   tty->print_cr(" _byte_arraycopy_cnt:             %u", _byte_arraycopy_stub_cnt);
1546   tty->print_cr(" _short_arraycopy_cnt:            %u", _short_arraycopy_stub_cnt);
1547   tty->print_cr(" _int_arraycopy_cnt:              %u", _int_arraycopy_stub_cnt);
1548   tty->print_cr(" _long_arraycopy_cnt:             %u", _long_arraycopy_stub_cnt);
1549   tty->print_cr(" _oop_arraycopy_cnt:              %u", _oop_arraycopy_stub_cnt);
1550   tty->print_cr(" _arraycopy_slowcase_cnt:         %u", _arraycopy_slowcase_cnt);
1551   tty->print_cr(" _arraycopy_checkcast_cnt:        %u", _arraycopy_checkcast_cnt);
1552   tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%u", _arraycopy_checkcast_attempt_cnt);
1553 
1554   tty->print_cr(" _new_type_array_slowcase_cnt:    %u", _new_type_array_slowcase_cnt);
1555   tty->print_cr(" _new_object_array_slowcase_cnt:  %u", _new_object_array_slowcase_cnt);

1556   tty->print_cr(" _new_instance_slowcase_cnt:      %u", _new_instance_slowcase_cnt);
1557   tty->print_cr(" _new_multi_array_slowcase_cnt:   %u", _new_multi_array_slowcase_cnt);






1558   tty->print_cr(" _monitorenter_slowcase_cnt:      %u", _monitorenter_slowcase_cnt);
1559   tty->print_cr(" _monitorexit_slowcase_cnt:       %u", _monitorexit_slowcase_cnt);
1560   tty->print_cr(" _patch_code_slowcase_cnt:        %u", _patch_code_slowcase_cnt);
1561 
1562   tty->print_cr(" _throw_range_check_exception_count:            %u:", _throw_range_check_exception_count);
1563   tty->print_cr(" _throw_index_exception_count:                  %u:", _throw_index_exception_count);
1564   tty->print_cr(" _throw_div0_exception_count:                   %u:", _throw_div0_exception_count);
1565   tty->print_cr(" _throw_null_pointer_exception_count:           %u:", _throw_null_pointer_exception_count);
1566   tty->print_cr(" _throw_class_cast_exception_count:             %u:", _throw_class_cast_exception_count);
1567   tty->print_cr(" _throw_incompatible_class_change_error_count:  %u:", _throw_incompatible_class_change_error_count);


1568   tty->print_cr(" _throw_count:                                  %u:", _throw_count);
1569 
1570   SharedRuntime::print_ic_miss_histogram();
1571   tty->cr();
1572 }
1573 #endif // PRODUCT

  33 #include "classfile/vmSymbols.hpp"
  34 #include "code/aotCodeCache.hpp"
  35 #include "code/codeBlob.hpp"
  36 #include "code/compiledIC.hpp"
  37 #include "code/scopeDesc.hpp"
  38 #include "code/vtableStubs.hpp"
  39 #include "compiler/compilationPolicy.hpp"
  40 #include "compiler/disassembler.hpp"
  41 #include "compiler/oopMap.hpp"
  42 #include "gc/shared/barrierSet.hpp"
  43 #include "gc/shared/c1/barrierSetC1.hpp"
  44 #include "gc/shared/collectedHeap.hpp"
  45 #include "interpreter/bytecode.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "jfr/support/jfrIntrinsics.hpp"
  48 #include "logging/log.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/access.inline.hpp"
  53 #include "oops/flatArrayKlass.hpp"
  54 #include "oops/flatArrayOop.inline.hpp"
  55 #include "oops/objArrayKlass.hpp"
  56 #include "oops/objArrayOop.inline.hpp"
  57 #include "oops/oop.inline.hpp"
  58 #include "prims/jvmtiExport.hpp"
  59 #include "runtime/atomic.hpp"
  60 #include "runtime/fieldDescriptor.inline.hpp"
  61 #include "runtime/frame.inline.hpp"
  62 #include "runtime/handles.inline.hpp"
  63 #include "runtime/interfaceSupport.inline.hpp"
  64 #include "runtime/javaCalls.hpp"
  65 #include "runtime/sharedRuntime.hpp"
  66 #include "runtime/stackWatermarkSet.hpp"
  67 #include "runtime/stubInfo.hpp"
  68 #include "runtime/stubRoutines.hpp"
  69 #include "runtime/vframe.inline.hpp"
  70 #include "runtime/vframeArray.hpp"
  71 #include "runtime/vm_version.hpp"
  72 #include "utilities/copy.hpp"
  73 #include "utilities/events.hpp"
  74 

  99 
 100 
 101 void StubAssembler::set_num_rt_args(int args) {
 102   if (_num_rt_args == 0) {
 103     _num_rt_args = args;
 104   }
 105   assert(_num_rt_args == args, "can't change the number of args");
 106 }
 107 
 108 // Implementation of Runtime1
 109 CodeBlob* Runtime1::_blobs[StubInfo::C1_STUB_COUNT];
 110 
 111 #ifndef PRODUCT
 112 // statistics
 113 uint Runtime1::_generic_arraycopystub_cnt = 0;
 114 uint Runtime1::_arraycopy_slowcase_cnt = 0;
 115 uint Runtime1::_arraycopy_checkcast_cnt = 0;
 116 uint Runtime1::_arraycopy_checkcast_attempt_cnt = 0;
 117 uint Runtime1::_new_type_array_slowcase_cnt = 0;
 118 uint Runtime1::_new_object_array_slowcase_cnt = 0;
 119 uint Runtime1::_new_null_free_array_slowcase_cnt = 0;
 120 uint Runtime1::_new_instance_slowcase_cnt = 0;
 121 uint Runtime1::_new_multi_array_slowcase_cnt = 0;
 122 uint Runtime1::_load_flat_array_slowcase_cnt = 0;
 123 uint Runtime1::_store_flat_array_slowcase_cnt = 0;
 124 uint Runtime1::_substitutability_check_slowcase_cnt = 0;
 125 uint Runtime1::_buffer_inline_args_slowcase_cnt = 0;
 126 uint Runtime1::_buffer_inline_args_no_receiver_slowcase_cnt = 0;
 127 uint Runtime1::_monitorenter_slowcase_cnt = 0;
 128 uint Runtime1::_monitorexit_slowcase_cnt = 0;
 129 uint Runtime1::_patch_code_slowcase_cnt = 0;
 130 uint Runtime1::_throw_range_check_exception_count = 0;
 131 uint Runtime1::_throw_index_exception_count = 0;
 132 uint Runtime1::_throw_div0_exception_count = 0;
 133 uint Runtime1::_throw_null_pointer_exception_count = 0;
 134 uint Runtime1::_throw_class_cast_exception_count = 0;
 135 uint Runtime1::_throw_incompatible_class_change_error_count = 0;
 136 uint Runtime1::_throw_illegal_monitor_state_exception_count = 0;
 137 uint Runtime1::_throw_identity_exception_count = 0;
 138 uint Runtime1::_throw_count = 0;
 139 
 140 static uint _byte_arraycopy_stub_cnt = 0;
 141 static uint _short_arraycopy_stub_cnt = 0;
 142 static uint _int_arraycopy_stub_cnt = 0;
 143 static uint _long_arraycopy_stub_cnt = 0;
 144 static uint _oop_arraycopy_stub_cnt = 0;
 145 
 146 address Runtime1::arraycopy_count_address(BasicType type) {
 147   switch (type) {
 148   case T_BOOLEAN:
 149   case T_BYTE:   return (address)&_byte_arraycopy_stub_cnt;
 150   case T_CHAR:
 151   case T_SHORT:  return (address)&_short_arraycopy_stub_cnt;
 152   case T_FLOAT:
 153   case T_INT:    return (address)&_int_arraycopy_stub_cnt;
 154   case T_DOUBLE:
 155   case T_LONG:   return (address)&_long_arraycopy_stub_cnt;
 156   case T_ARRAY:
 157   case T_OBJECT: return (address)&_oop_arraycopy_stub_cnt;

 365   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());
 366   FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32C());
 367   FUNCTION_CASE(entry, StubRoutines::vectorizedMismatch());
 368   FUNCTION_CASE(entry, StubRoutines::dexp());
 369   FUNCTION_CASE(entry, StubRoutines::dlog());
 370   FUNCTION_CASE(entry, StubRoutines::dlog10());
 371   FUNCTION_CASE(entry, StubRoutines::dpow());
 372   FUNCTION_CASE(entry, StubRoutines::dsin());
 373   FUNCTION_CASE(entry, StubRoutines::dcos());
 374   FUNCTION_CASE(entry, StubRoutines::dtan());
 375   FUNCTION_CASE(entry, StubRoutines::dsinh());
 376   FUNCTION_CASE(entry, StubRoutines::dtanh());
 377   FUNCTION_CASE(entry, StubRoutines::dcbrt());
 378 
 379 #undef FUNCTION_CASE
 380 
 381   // Soft float adds more runtime names.
 382   return pd_name_for_address(entry);
 383 }
 384 
 385 static void allocate_instance(JavaThread* current, Klass* klass, TRAPS) {

 386 #ifndef PRODUCT
 387   if (PrintC1Statistics) {
 388     Runtime1::_new_instance_slowcase_cnt++;
 389   }
 390 #endif
 391   assert(klass->is_klass(), "not a class");
 392   Handle holder(current, klass->klass_holder()); // keep the klass alive
 393   InstanceKlass* h = InstanceKlass::cast(klass);
 394   h->check_valid_for_instantiation(true, CHECK);
 395   // make sure klass is initialized
 396   h->initialize(CHECK);
 397   // allocate instance and return via TLS
 398   oop obj = h->allocate_instance(CHECK);
 399   current->set_vm_result_oop(obj);
 400 JRT_END
 401 
 402 JRT_ENTRY(void, Runtime1::new_instance(JavaThread* current, Klass* klass))
 403   allocate_instance(current, klass, CHECK);
 404 JRT_END
 405 
 406 JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* current, Klass* klass, jint length))
 407 #ifndef PRODUCT
 408   if (PrintC1Statistics) {
 409     _new_type_array_slowcase_cnt++;
 410   }
 411 #endif
 412   // Note: no handle for klass needed since they are not used
 413   //       anymore after new_typeArray() and no GC can happen before.
 414   //       (This may have to change if this code changes!)
 415   assert(klass->is_klass(), "not a class");
 416   BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();
 417   oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);
 418   current->set_vm_result_oop(obj);
 419   // This is pretty rare but this runtime patch is stressful to deoptimization
 420   // if we deoptimize here so force a deopt to stress the path.
 421   if (DeoptimizeALot) {
 422     deopt_caller(current);
 423   }
 424 

 430   if (PrintC1Statistics) {
 431     _new_object_array_slowcase_cnt++;
 432   }
 433 #endif
 434   // Note: no handle for klass needed since they are not used
 435   //       anymore after new_objArray() and no GC can happen before.
 436   //       (This may have to change if this code changes!)
 437   assert(array_klass->is_klass(), "not a class");
 438   Handle holder(current, array_klass->klass_holder()); // keep the klass alive
 439   Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 440   objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);
 441   current->set_vm_result_oop(obj);
 442   // This is pretty rare but this runtime patch is stressful to deoptimization
 443   // if we deoptimize here so force a deopt to stress the path.
 444   if (DeoptimizeALot) {
 445     deopt_caller(current);
 446   }
 447 JRT_END
 448 
 449 
 450 JRT_ENTRY(void, Runtime1::new_null_free_array(JavaThread* current, Klass* array_klass, jint length))
 451   NOT_PRODUCT(_new_null_free_array_slowcase_cnt++;)
 452   // TODO 8350865 This is dead code since 8325660 because null-free arrays can only be created via the factory methods that are not yet implemented in C1. Should probably be fixed by 8265122.
 453 
 454   // Note: no handle for klass needed since they are not used
 455   //       anymore after new_objArray() and no GC can happen before.
 456   //       (This may have to change if this code changes!)
 457   assert(array_klass->is_klass(), "not a class");
 458   Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
 459   Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();
 460   assert(elem_klass->is_inline_klass(), "must be");
 461   InlineKlass* vk = InlineKlass::cast(elem_klass);
 462   // Logically creates elements, ensure klass init
 463   elem_klass->initialize(CHECK);
 464   arrayOop obj= oopFactory::new_objArray(elem_klass, length, ArrayKlass::ArrayProperties::NULL_RESTRICTED, CHECK);
 465   current->set_vm_result_oop(obj);
 466   // This is pretty rare but this runtime patch is stressful to deoptimization
 467   // if we deoptimize here so force a deopt to stress the path.
 468   if (DeoptimizeALot) {
 469     deopt_caller(current);
 470   }
 471 JRT_END
 472 
 473 
 474 JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims))
 475 #ifndef PRODUCT
 476   if (PrintC1Statistics) {
 477     _new_multi_array_slowcase_cnt++;
 478   }
 479 #endif
 480   assert(klass->is_klass(), "not a class");
 481   assert(rank >= 1, "rank must be nonzero");
 482   Handle holder(current, klass->klass_holder()); // keep the klass alive
 483   oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
 484   current->set_vm_result_oop(obj);
 485 JRT_END
 486 
 487 
 488 static void profile_flat_array(JavaThread* current, bool load, bool null_free) {
 489   ResourceMark rm(current);
 490   vframeStream vfst(current, true);
 491   assert(!vfst.at_end(), "Java frame must exist");
 492   // Check if array access profiling is enabled
 493   if (vfst.nm()->comp_level() != CompLevel_full_profile || !C1UpdateMethodData) {
 494     return;
 495   }
 496   int bci = vfst.bci();
 497   Method* method = vfst.method();
 498   MethodData* md = method->method_data();
 499   if (md != nullptr) {
 500     // Lock to access ProfileData, and ensure lock is not broken by a safepoint
 501     MutexLocker ml(md->extra_data_lock(), Mutex::_no_safepoint_check_flag);
 502 
 503     ProfileData* data = md->bci_to_data(bci);
 504     assert(data != nullptr, "incorrect profiling entry");
 505     if (data->is_ArrayLoadData()) {
 506       assert(load, "should be an array load");
 507       ArrayLoadData* load_data = (ArrayLoadData*) data;
 508       load_data->set_flat_array();
 509       if (null_free) {
 510         load_data->set_null_free_array();
 511       }
 512     } else {
 513       assert(data->is_ArrayStoreData(), "");
 514       assert(!load, "should be an array store");
 515       ArrayStoreData* store_data = (ArrayStoreData*) data;
 516       store_data->set_flat_array();
 517       if (null_free) {
 518         store_data->set_null_free_array();
 519       }
 520     }
 521   }
 522 }
 523 
 524 JRT_ENTRY(void, Runtime1::load_flat_array(JavaThread* current, flatArrayOopDesc* array, int index))
 525   assert(array->klass()->is_flatArray_klass(), "should not be called");
 526   profile_flat_array(current, true, array->is_null_free_array());
 527 
 528   NOT_PRODUCT(_load_flat_array_slowcase_cnt++;)
 529   assert(array->length() > 0 && index < array->length(), "already checked");
 530   flatArrayHandle vah(current, array);
 531   oop obj = array->obj_at(index, CHECK);
 532   current->set_vm_result_oop(obj);
 533 JRT_END
 534 
 535 JRT_ENTRY(void, Runtime1::store_flat_array(JavaThread* current, flatArrayOopDesc* array, int index, oopDesc* value))
 536   // TOOD 8350865 We can call here with a non-flat array because of LIR_Assembler::emit_opFlattenedArrayCheck
 537   if (array->klass()->is_flatArray_klass()) {
 538     profile_flat_array(current, false, array->is_null_free_array());
 539   }
 540 
 541   NOT_PRODUCT(_store_flat_array_slowcase_cnt++;)
 542   if (value == nullptr && array->is_null_free_array()) {
 543     SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_NullPointerException());
 544   } else {
 545     assert(array->klass()->is_flatArray_klass(), "should not be called");
 546     array->obj_at_put(index, value, CHECK);
 547   }
 548 JRT_END
 549 
 550 JRT_ENTRY(int, Runtime1::substitutability_check(JavaThread* current, oopDesc* left, oopDesc* right))
 551   NOT_PRODUCT(_substitutability_check_slowcase_cnt++;)
 552   JavaCallArguments args;
 553   args.push_oop(Handle(THREAD, left));
 554   args.push_oop(Handle(THREAD, right));
 555   JavaValue result(T_BOOLEAN);
 556   JavaCalls::call_static(&result,
 557                          vmClasses::ValueObjectMethods_klass(),
 558                          vmSymbols::isSubstitutable_name(),
 559                          vmSymbols::object_object_boolean_signature(),
 560                          &args, CHECK_0);
 561   return result.get_jboolean() ? 1 : 0;
 562 JRT_END
 563 
 564 
 565 extern "C" void ps();
 566 
 567 void Runtime1::buffer_inline_args_impl(JavaThread* current, Method* m, bool allocate_receiver) {
 568   JavaThread* THREAD = current;
 569   methodHandle method(current, m); // We are inside the verified_entry or verified_inline_ro_entry of this method.
 570   oop obj = SharedRuntime::allocate_inline_types_impl(current, method, allocate_receiver, CHECK);
 571   current->set_vm_result_oop(obj);
 572 }
 573 
 574 JRT_ENTRY(void, Runtime1::buffer_inline_args(JavaThread* current, Method* method))
 575   NOT_PRODUCT(_buffer_inline_args_slowcase_cnt++;)
 576   buffer_inline_args_impl(current, method, true);
 577 JRT_END
 578 
 579 JRT_ENTRY(void, Runtime1::buffer_inline_args_no_receiver(JavaThread* current, Method* method))
 580   NOT_PRODUCT(_buffer_inline_args_no_receiver_slowcase_cnt++;)
 581   buffer_inline_args_impl(current, method, false);
 582 JRT_END
 583 
 584 JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* current, StubId id))
 585   tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", (int)id);
 586 JRT_END
 587 
 588 
 589 JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* current, oopDesc* obj))
 590   ResourceMark rm(current);
 591   const char* klass_name = obj->klass()->external_name();
 592   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ArrayStoreException(), klass_name);
 593 JRT_END
 594 
 595 
 596 // counter_overflow() is called from within C1-compiled methods. The enclosing method is the method
 597 // associated with the top activation record. The inlinee (that is possibly included in the enclosing
 598 // method) method is passed as an argument. In order to do that it is embedded in the code as
 599 // a constant.
 600 static nmethod* counter_overflow_helper(JavaThread* current, int branch_bci, Method* m) {
 601   nmethod* osr_nm = nullptr;
 602   methodHandle method(current, m);
 603 

 887     _throw_class_cast_exception_count++;
 888   }
 889 #endif
 890   ResourceMark rm(current);
 891   char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
 892   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ClassCastException(), message);
 893 JRT_END
 894 
 895 
 896 JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* current))
 897 #ifndef PRODUCT
 898   if (PrintC1Statistics) {
 899     _throw_incompatible_class_change_error_count++;
 900   }
 901 #endif
 902   ResourceMark rm(current);
 903   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IncompatibleClassChangeError());
 904 JRT_END
 905 
 906 
 907 JRT_ENTRY(void, Runtime1::throw_illegal_monitor_state_exception(JavaThread* current))
 908   NOT_PRODUCT(_throw_illegal_monitor_state_exception_count++;)
 909   ResourceMark rm(current);
 910   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IllegalMonitorStateException());
 911 JRT_END
 912 
 913 JRT_ENTRY(void, Runtime1::throw_identity_exception(JavaThread* current, oopDesc* object))
 914   NOT_PRODUCT(_throw_identity_exception_count++;)
 915   ResourceMark rm(current);
 916   char* message = SharedRuntime::generate_identity_exception_message(current, object->klass());
 917   SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_IdentityException(), message);
 918 JRT_END
 919 
 920 JRT_BLOCK_ENTRY(void, Runtime1::monitorenter(JavaThread* current, oopDesc* obj, BasicObjectLock* lock))
 921 #ifndef PRODUCT
 922   if (PrintC1Statistics) {
 923     _monitorenter_slowcase_cnt++;
 924   }
 925 #endif
 926   if (LockingMode == LM_MONITOR) {
 927     lock->set_obj(obj);
 928   }
 929   assert(obj == lock->obj(), "must match");
 930   SharedRuntime::monitor_enter_helper(obj, lock->lock(), current);
 931 JRT_END
 932 
 933 
 934 JRT_LEAF(void, Runtime1::monitorexit(JavaThread* current, BasicObjectLock* lock))
 935   assert(current == JavaThread::current(), "pre-condition");
 936 #ifndef PRODUCT
 937   if (PrintC1Statistics) {
 938     _monitorexit_slowcase_cnt++;
 939   }

1105                       RegisterMap::WalkContinuation::skip);
1106   frame runtime_frame = current->last_frame();
1107   frame caller_frame = runtime_frame.sender(&reg_map);
1108 
1109   // last java frame on stack
1110   vframeStream vfst(current, true);
1111   assert(!vfst.at_end(), "Java frame must exist");
1112 
1113   methodHandle caller_method(current, vfst.method());
1114   // Note that caller_method->code() may not be same as caller_code because of OSR's
1115   // Note also that in the presence of inlining it is not guaranteed
1116   // that caller_method() == caller_code->method()
1117 
1118   int bci = vfst.bci();
1119   Bytecodes::Code code = caller_method()->java_code_at(bci);
1120 
1121   // this is used by assertions in the access_field_patching_id
1122   BasicType patch_field_type = T_ILLEGAL;
1123   bool deoptimize_for_volatile = false;
1124   bool deoptimize_for_atomic = false;
1125   bool deoptimize_for_null_free = false;
1126   bool deoptimize_for_flat = false;
1127   bool deoptimize_for_strict_static = false;
1128   int patch_field_offset = -1;
1129   Klass* init_klass = nullptr; // klass needed by load_klass_patching code
1130   Klass* load_klass = nullptr; // klass needed by load_klass_patching code
1131   Handle mirror(current, nullptr); // oop needed by load_mirror_patching code
1132   Handle appendix(current, nullptr); // oop needed by appendix_patching code
1133   bool load_klass_or_mirror_patch_id =
1134     (stub_id == StubId::c1_load_klass_patching_id || stub_id == StubId::c1_load_mirror_patching_id);
1135 
1136   if (stub_id == StubId::c1_access_field_patching_id) {
1137 
1138     Bytecode_field field_access(caller_method, bci);
1139     fieldDescriptor result; // initialize class if needed
1140     Bytecodes::Code code = field_access.code();
1141     constantPoolHandle constants(current, caller_method->constants());
1142     LinkResolver::resolve_field_access(result, constants, field_access.index(), caller_method, Bytecodes::java_code(code), CHECK);
1143     patch_field_offset = result.offset();
1144 
1145     // If we're patching a field which is volatile then at compile it
1146     // must not have been know to be volatile, so the generated code
1147     // isn't correct for a volatile reference.  The nmethod has to be

1151     // used for patching references to oops which don't need special
1152     // handling in the volatile case.
1153 
1154     deoptimize_for_volatile = result.access_flags().is_volatile();
1155 
1156     // If we are patching a field which should be atomic, then
1157     // the generated code is not correct either, force deoptimizing.
1158     // We need to only cover T_LONG and T_DOUBLE fields, as we can
1159     // break access atomicity only for them.
1160 
1161     // Strictly speaking, the deoptimization on 64-bit platforms
1162     // is unnecessary, and T_LONG stores on 32-bit platforms need
1163     // to be handled by special patching code when AlwaysAtomicAccesses
1164     // becomes product feature. At this point, we are still going
1165     // for the deoptimization for consistency against volatile
1166     // accesses.
1167 
1168     patch_field_type = result.field_type();
1169     deoptimize_for_atomic = (AlwaysAtomicAccesses && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG));
1170 
1171     // The field we are patching is null-free. Deoptimize and regenerate
1172     // the compiled code if we patch a putfield/putstatic because it
1173     // does not contain the required null check.
1174     deoptimize_for_null_free = result.is_null_free_inline_type() && (field_access.is_putfield() || field_access.is_putstatic());
1175 
1176     // The field we are patching is flat. Deoptimize and regenerate
1177     // the compiled code which can't handle the layout of the flat
1178     // field because it was unknown at compile time.
1179     deoptimize_for_flat = result.is_flat();
1180 
1181     // Strict statics may require tracking if their class is not fully initialized.
1182     // For now we can bail out of the compiler and let the interpreter handle it.
1183     deoptimize_for_strict_static = result.is_strict_static_unset();
1184   } else if (load_klass_or_mirror_patch_id) {
1185     Klass* k = nullptr;
1186     switch (code) {
1187       case Bytecodes::_putstatic:
1188       case Bytecodes::_getstatic:
1189         { Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);
1190           init_klass = klass;
1191           mirror = Handle(current, klass->java_mirror());
1192         }
1193         break;
1194       case Bytecodes::_new:
1195         { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));
1196           k = caller_method->constants()->klass_at(bnew.index(), CHECK);
1197         }
1198         break;
1199       case Bytecodes::_multianewarray:
1200         { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));
1201           k = caller_method->constants()->klass_at(mna.index(), CHECK);
1202         }
1203         break;
1204       case Bytecodes::_instanceof:
1205         { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));
1206           k = caller_method->constants()->klass_at(io.index(), CHECK);
1207         }
1208         break;
1209       case Bytecodes::_checkcast:
1210         { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));
1211           k = caller_method->constants()->klass_at(cc.index(), CHECK);
1212         }
1213         break;
1214       case Bytecodes::_anewarray:
1215         { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));
1216           Klass* ek = caller_method->constants()->klass_at(anew.index(), CHECK);
1217           k = ek->array_klass(CHECK);
1218           if (!k->is_typeArray_klass() && !k->is_refArray_klass() && !k->is_flatArray_klass()) {
1219             k = ObjArrayKlass::cast(k)->klass_with_properties(ArrayKlass::ArrayProperties::DEFAULT, THREAD);
1220           }
1221           if (k->is_flatArray_klass()) {
1222             deoptimize_for_flat = true;
1223           }
1224         }
1225         break;
1226       case Bytecodes::_ldc:
1227       case Bytecodes::_ldc_w:
1228       case Bytecodes::_ldc2_w:
1229         {
1230           Bytecode_loadconstant cc(caller_method, bci);
1231           oop m = cc.resolve_constant(CHECK);
1232           mirror = Handle(current, m);
1233         }
1234         break;
1235       default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");
1236     }
1237     load_klass = k;
1238   } else if (stub_id == StubId::c1_load_appendix_patching_id) {
1239     Bytecode_invoke bytecode(caller_method, bci);
1240     Bytecodes::Code bc = bytecode.invoke_code();
1241 
1242     CallInfo info;
1243     constantPoolHandle pool(current, caller_method->constants());
1244     int index = bytecode.index();
1245     LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);
1246     switch (bc) {
1247       case Bytecodes::_invokehandle: {
1248         ResolvedMethodEntry* entry = pool->cache()->set_method_handle(index, info);
1249         appendix = Handle(current, pool->cache()->appendix_if_resolved(entry));
1250         break;
1251       }
1252       case Bytecodes::_invokedynamic: {
1253         appendix = Handle(current, pool->cache()->set_dynamic_call(info, index));
1254         break;
1255       }
1256       default: fatal("unexpected bytecode for load_appendix_patching_id");
1257     }
1258   } else {
1259     ShouldNotReachHere();
1260   }
1261 
1262   if (deoptimize_for_volatile  ||
1263       deoptimize_for_atomic    ||
1264       deoptimize_for_null_free ||
1265       deoptimize_for_flat      ||
1266       deoptimize_for_strict_static) {
1267     // At compile time we assumed the field wasn't volatile/atomic but after
1268     // loading it turns out it was volatile/atomic so we have to throw the
1269     // compiled code out and let it be regenerated.
1270     if (TracePatching) {
1271       if (deoptimize_for_volatile) {
1272         tty->print_cr("Deoptimizing for patching volatile field reference");
1273       }
1274       if (deoptimize_for_atomic) {
1275         tty->print_cr("Deoptimizing for patching atomic field reference");
1276       }
1277       if (deoptimize_for_null_free) {
1278         tty->print_cr("Deoptimizing for patching null-free field reference");
1279       }
1280       if (deoptimize_for_flat) {
1281         tty->print_cr("Deoptimizing for patching flat field or array reference");
1282       }
1283       if (deoptimize_for_strict_static) {
1284         tty->print_cr("Deoptimizing for patching strict static field reference");
1285       }
1286     }
1287 
1288     // It's possible the nmethod was invalidated in the last
1289     // safepoint, but if it's still alive then make it not_entrant.
1290     nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
1291     if (nm != nullptr) {
1292       nm->make_not_entrant(nmethod::InvalidationReason::C1_CODEPATCH);
1293     }
1294 
1295     Deoptimization::deoptimize_frame(current, caller_frame.id());
1296 
1297     // Return to the now deoptimized frame.
1298   }
1299 
1300   // Now copy code back
1301 
1302   {
1303     MutexLocker ml_code (current, CodeCache_lock, Mutex::_no_safepoint_check_flag);
1304     //
1305     // Deoptimization may have happened while we waited for the lock.

1716 #ifndef PRODUCT
1717 void Runtime1::print_statistics() {
1718   tty->print_cr("C1 Runtime statistics:");
1719   tty->print_cr(" _resolve_invoke_virtual_cnt:     %u", SharedRuntime::_resolve_virtual_ctr);
1720   tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %u", SharedRuntime::_resolve_opt_virtual_ctr);
1721   tty->print_cr(" _resolve_invoke_static_cnt:      %u", SharedRuntime::_resolve_static_ctr);
1722   tty->print_cr(" _handle_wrong_method_cnt:        %u", SharedRuntime::_wrong_method_ctr);
1723   tty->print_cr(" _ic_miss_cnt:                    %u", SharedRuntime::_ic_miss_ctr);
1724   tty->print_cr(" _generic_arraycopystub_cnt:      %u", _generic_arraycopystub_cnt);
1725   tty->print_cr(" _byte_arraycopy_cnt:             %u", _byte_arraycopy_stub_cnt);
1726   tty->print_cr(" _short_arraycopy_cnt:            %u", _short_arraycopy_stub_cnt);
1727   tty->print_cr(" _int_arraycopy_cnt:              %u", _int_arraycopy_stub_cnt);
1728   tty->print_cr(" _long_arraycopy_cnt:             %u", _long_arraycopy_stub_cnt);
1729   tty->print_cr(" _oop_arraycopy_cnt:              %u", _oop_arraycopy_stub_cnt);
1730   tty->print_cr(" _arraycopy_slowcase_cnt:         %u", _arraycopy_slowcase_cnt);
1731   tty->print_cr(" _arraycopy_checkcast_cnt:        %u", _arraycopy_checkcast_cnt);
1732   tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%u", _arraycopy_checkcast_attempt_cnt);
1733 
1734   tty->print_cr(" _new_type_array_slowcase_cnt:    %u", _new_type_array_slowcase_cnt);
1735   tty->print_cr(" _new_object_array_slowcase_cnt:  %u", _new_object_array_slowcase_cnt);
1736   tty->print_cr(" _new_null_free_array_slowcase_cnt: %u", _new_null_free_array_slowcase_cnt);
1737   tty->print_cr(" _new_instance_slowcase_cnt:      %u", _new_instance_slowcase_cnt);
1738   tty->print_cr(" _new_multi_array_slowcase_cnt:   %u", _new_multi_array_slowcase_cnt);
1739   tty->print_cr(" _load_flat_array_slowcase_cnt:   %u", _load_flat_array_slowcase_cnt);
1740   tty->print_cr(" _store_flat_array_slowcase_cnt:  %u", _store_flat_array_slowcase_cnt);
1741   tty->print_cr(" _substitutability_check_slowcase_cnt: %u", _substitutability_check_slowcase_cnt);
1742   tty->print_cr(" _buffer_inline_args_slowcase_cnt:%u", _buffer_inline_args_slowcase_cnt);
1743   tty->print_cr(" _buffer_inline_args_no_receiver_slowcase_cnt:%u", _buffer_inline_args_no_receiver_slowcase_cnt);
1744 
1745   tty->print_cr(" _monitorenter_slowcase_cnt:      %u", _monitorenter_slowcase_cnt);
1746   tty->print_cr(" _monitorexit_slowcase_cnt:       %u", _monitorexit_slowcase_cnt);
1747   tty->print_cr(" _patch_code_slowcase_cnt:        %u", _patch_code_slowcase_cnt);
1748 
1749   tty->print_cr(" _throw_range_check_exception_count:            %u:", _throw_range_check_exception_count);
1750   tty->print_cr(" _throw_index_exception_count:                  %u:", _throw_index_exception_count);
1751   tty->print_cr(" _throw_div0_exception_count:                   %u:", _throw_div0_exception_count);
1752   tty->print_cr(" _throw_null_pointer_exception_count:           %u:", _throw_null_pointer_exception_count);
1753   tty->print_cr(" _throw_class_cast_exception_count:             %u:", _throw_class_cast_exception_count);
1754   tty->print_cr(" _throw_incompatible_class_change_error_count:  %u:", _throw_incompatible_class_change_error_count);
1755   tty->print_cr(" _throw_illegal_monitor_state_exception_count:  %u:", _throw_illegal_monitor_state_exception_count);
1756   tty->print_cr(" _throw_identity_exception_count:               %u:", _throw_identity_exception_count);
1757   tty->print_cr(" _throw_count:                                  %u:", _throw_count);
1758 
1759   SharedRuntime::print_ic_miss_histogram();
1760   tty->cr();
1761 }
1762 #endif // PRODUCT
< prev index next >